Пример #1
0
long ndiSerialOpen(const char *device)
{
  short serial_out, serial_in; /* macintosh device handles */
  long serial_port; /* hold them both, packed into 32 bits */
  char namein[64], nameout[64];
  int i;

  sprintf(namein,"%sIn",device);
  sprintf(nameout,"%sOut",device);

  if (OpenDriver(namein, &serial_in) != noErr) {
    return -1;
  }
  if (OpenDriver(nameout,&serial_out) != noErr) {
    CloseDriver(serial_in);
    return -1;
  }

  /* combine the two shorts into one long */
  serial_port = ((serial_in << 0) | (serial_out << 16));
  
  /* save the serial port state so that it can be restored when
     the serial port is closed in ndiSerialClose() */
  for (i = 0; i < NDI_MAX_SAVE_STATE; i++) {
    if (ndi_open_handles[i] == serial_port || ndi_open_handles[i] == -1) {
      ndi_open_handles[i] = serial_port;
      break;
    }
  }

  return serial_port;
}
Пример #2
0
//-----------------------------------------------------------------------------
//
// Initialize/Deinitialize Functions
//
//-----------------------------------------------------------------------------
DWORD Initialize()
{
	TCHAR dir[MAX_PATH];
	TCHAR *ptr;

	GetModuleFileName(gModule, dir, MAX_PATH);
	if((ptr = _tcsrchr(dir, '\\')) != NULL)
	{
		*ptr = '\0';
	}
	wsprintf(gDriverPath, _T("%s\\%s"), dir, gDriverFileName);

	if(IsFileExist(gDriverPath) == FALSE)
	{
		return OLS_DLL_DRIVER_NOT_FOUND;
	}

	if(IsOnNetworkDrive(gDriverPath) == TRUE)
	{
		return OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK;
	}

	if(gIsNT)
	{
		if(OpenDriver())
		{
			return OLS_DLL_NO_ERROR;
		}

		ManageDriver(OLS_DRIVER_ID, gDriverPath, OLS_DRIVER_REMOVE);
		if(!ManageDriver(OLS_DRIVER_ID, gDriverPath, OLS_DRIVER_INSTALL))
		{
			ManageDriver(OLS_DRIVER_ID, gDriverPath, OLS_DRIVER_REMOVE);
			return OLS_DLL_DRIVER_NOT_LOADED;
		}
		
		if(OpenDriver())
		{
			return OLS_DLL_NO_ERROR;
		}
		return OLS_DLL_DRIVER_NOT_LOADED;
	}
	else
	{
		gHandle = CreateFile(
			_T("\\\\.\\") OLS_DRIVER_FILE_NAME_WIN_9X,
			0, 0, NULL,	0, 
			FILE_FLAG_DELETE_ON_CLOSE,
			NULL);

		if(gHandle == INVALID_HANDLE_VALUE)
		{
			return OLS_DLL_DRIVER_NOT_LOADED;
		}
		return OLS_DLL_NO_ERROR;
	}
}
Пример #3
0
BOOL AddClusterSender(
	struct MidiCluster *cluster,
	struct Node *node,
	ULONG *ErrorCode,
	struct CamdBase *CamdBase
){
	struct MidiLink *midilink;
	struct DriverData *driverdata;

	if(node->ln_Type!=NT_USER-MLTYPE_NTypes){
		driverdata=FindReceiverDriverInCluster(cluster);
		if(driverdata!=NULL){
			if(driverdata->isInOpen==FALSE && driverdata->isOutOpen==FALSE){
				if(OpenDriver(driverdata,ErrorCode,CamdBase)==FALSE){
					return FALSE;
				}
				driverdata->isOutOpen=TRUE;
			}
		}
		midilink=(struct MidiLink *)node;
		midilink->ml_Location=cluster;
	}

	Enqueue(&cluster->mcl_Senders,node);
	return TRUE;
}
Пример #4
0
//-----------------------------------------------------------------------------
bool HoneDumpcap::Initialize(QStringList args, QString appPath)
{
	m_args = args;
	if (!ParseArgs()) {
		return false;
	}

#ifdef WIN32
	m_dumpcapFileName = QString("%1/dumpcap_orig.exe").arg(appPath);
#else
	m_dumpcapFileName = QString("%1/dumpcap_orig").arg(appPath);
#endif

	if (m_operation == OperationCapture) {
		if (m_haveHoneInterface) {
			m_captureStart = QDateTime::currentMSecsSinceEpoch();
			if (m_parentPid.isEmpty()) {
				Log("Capturing on 'Hone'");
			}
			if (!OpenDriver() || !OpenCaptureFile()) {
				return false;
			}
		} else {
			connect(&m_dumpcapProcess, SIGNAL(error(QProcess::ProcessError)),      this, SLOT(OnError(QProcess::ProcessError)));
			connect(&m_dumpcapProcess, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(OnFinished(int,QProcess::ExitStatus)));
			connect(&m_dumpcapProcess, SIGNAL(readyReadStandardError()),           this, SLOT(OnReadyReadStandardError()));
			connect(&m_dumpcapProcess, SIGNAL(readyReadStandardOutput()),          this, SLOT(OnReadyReadStandardOutput()));
			m_dumpcapProcess.start(m_dumpcapFileName, m_args);
			m_needEventLoop = true;
		}
	}
	return true;
}
Пример #5
0
/*
 * Exported function for obtaining a driver's option list (UTF-8 encoded XML).
 *
 * The returned char pointer points directly into the driver. Therefore
 * it should be treated as a constant.
 *
 * If the driver was not found or does not support configuration NULL is
 * returned.
 *
 * Note: The driver remains opened after this function returns.
 */
const char *glXGetDriverConfig (const char *driverName) {
   __DRIdriver *driver = OpenDriver (driverName);
   if (driver)
      return dlsym (driver->handle, "__driConfigOptions");
   else
      return NULL;
}
Пример #6
0
/**************************************************************************
 *				OpenDriverA		        [WINMM.@]
 *				DrvOpenA			[WINMM.@]
 * (0,1,DRV_LOAD  ,0       ,0)
 * (0,1,DRV_ENABLE,0       ,0)
 * (0,1,DRV_OPEN  ,buf[256],0)
 */
HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam)
{
    INT                 len;
    LPWSTR 		dn = NULL;
    LPWSTR 		sn = NULL;
    HDRVR		ret = 0;

    if (lpDriverName)
    {
        len = MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, NULL, 0 );
        dn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
        if (!dn) goto done;
        MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, dn, len );
    }

    if (lpSectionName)
    {
        len = MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, NULL, 0 );
        sn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
        if (!sn) goto done;
        MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, sn, len );
    }

    ret = OpenDriver(dn, sn, lParam);

done:
    HeapFree(GetProcessHeap(), 0, dn);
    HeapFree(GetProcessHeap(), 0, sn);
    return ret;
}
Пример #7
0
BOOL AddClusterReceiver(
	struct MidiCluster *cluster,
	struct Node *node,
	ULONG *ErrorCode,
	struct CamdBase *CamdBase
){
	struct MidiLink *midilink;
	struct DriverData *driverdata;
	struct MyMidiCluster *mycluster=(struct MyMidiCluster *)cluster;

	if(node->ln_Type!=NT_USER-MLTYPE_NTypes){
	  driverdata=FindSenderDriverInCluster(cluster);
	  if(driverdata!=NULL){
			if(driverdata->isInOpen==FALSE && driverdata->isOutOpen==FALSE){
				if(OpenDriver(driverdata,ErrorCode,CamdBase)==FALSE){
					return FALSE;
				}
	  
				driverdata->isInOpen=TRUE;
			}
		}
		midilink=(struct MidiLink *)node;
		ObtainSemaphore(&mycluster->semaphore);
		midilink->ml_Location=cluster;
	}else{
		/* The receiver is a hardware-receiver, not a midilink. */
		ObtainSemaphore(&mycluster->semaphore);
	}

	Enqueue(&cluster->mcl_Receivers,node);
	ReleaseSemaphore(&mycluster->semaphore);

	return TRUE;
}
Пример #8
0
CGPIODriver::CGPIODriver()
{
	// 打开驱动...	
	m_hGPIODriver = INVALID_HANDLE_VALUE;

	// 打开 GPIO 驱动
	OpenDriver();

}
Пример #9
0
A1(PUBLIC, OSErr, RAMSDOpen, SPortSel, port)	/* IMII-249 */
{
    OSErr err;
    INTEGER rn;

    switch (port) {
    case sPortA:
	if ((err = OpenDriver((StringPtr) AINNAME, &rn)) == noErr)
	    err = OpenDriver((StringPtr) AOUTNAME, &rn);
	break;
    case sPortB:
	if ((err = OpenDriver((StringPtr) BINNAME, &rn)) == noErr)
	    err = OpenDriver((StringPtr) BOUTNAME, &rn);
	break;
    default:
	err = openErr;
	break;
    }
    return err;
}
Пример #10
0
/*
 * Given a display pointer and screen number, return a __DRIdriver handle.
 * Return NULL if anything goes wrong.
 */
__DRIdriver *driGetDriver(Display *dpy, int scrNum)
{
   char *driverName;
   if (GetDriverName(dpy, scrNum, &driverName)) {
      __DRIdriver *ret;
      ret = OpenDriver(driverName);
      if (driverName)
     	 Xfree(driverName);
      return ret;
   }
   return NULL;
}
   /**
     * Create MidiShare input device for LinuxSampler. 
	 *
     * @param AutoConnectPortID - (optional) Alsa client and port ID of a
     *                            MIDI source we should auto connect to
     *                            (e.g. "64:0")
     * @throws MidiInputException  if initialization failed
     */
    MidiInputDeviceMidiShare::MidiInputDeviceMidiShare(char* AutoConnectPortID) : MidiInputDevice(MidiInputDevice::type_midishare) 
	{
		if (!MidiShare())
			throw MidiInputException("MidiShare not installed");
			
		#if defined(MIDISHARE_DRIVER)
			OpenDriver();
		#else
			OpenAppl();
		#endif
		
		hMidiFilter = MidiNewFilter();
		
		if (hMidiFilter == 0) {
			MidiClose(hRefnum);
			throw MidiInputException("MidiShare filter can not be allocated");	
		}
		  
		for (int i = 0 ; i < 256; i++) {
			MidiAcceptPort(hMidiFilter, i, 1); /* accept all ports */
			MidiAcceptType(hMidiFilter, i, 0); /* reject all types */ 
		} 
		  
		for (int i = 0 ; i < 16; i++) {
			MidiAcceptChan(hMidiFilter, i, 1); /* accept all chan */ 
		} 
		/* accept only the following types */
		MidiAcceptType(hMidiFilter, typeNote, 1);
		MidiAcceptType(hMidiFilter, typeKeyOn, 1);
		MidiAcceptType(hMidiFilter, typeKeyOff, 1);
		MidiAcceptType(hMidiFilter, typeCtrlChange, 1);
		//MidiAcceptType(hMidiFilter, typeProgChange, 1);
		MidiAcceptType(hMidiFilter, typePitchWheel, 1);
		  
		/* set the filter */
		MidiSetFilter(hRefnum, hMidiFilter);
	
		MidiSetRcvAlarm(hRefnum,ReceiveEvents);
		MidiSetApplAlarm(hRefnum,ApplAlarm);
		MidiSetInfo(hRefnum,this);
		MidiConnect(0,hRefnum,true);
	}
Пример #12
0
void EncryptionControl(BOOL Action)
{
	DWORD dwSize = 0;

	if( hDriver == INVALID_HANDLE_VALUE )
	{
		OpenDriver();
		if( hDriver == INVALID_HANDLE_VALUE )
		{
			wprintf(L"Open driver failed with the error: %d\n", GetLastError());
			return;
		}
	}

	if( !DeviceIoControl( hDriver, Action ? GINGKO_SET_ENCRYPT_START : GINGKO_SET_ENCRYPT_END, NULL, 0, NULL, 0, &dwSize, NULL ) )
	{
		wprintf(L"Control to hDriver was failed. with the error code: %d.\n", GetLastError());
		return;
	}
}
Пример #13
0
/***********************************************************************
 *		ICOpen				[MSVFW32.@]
 * Opens an installable compressor. Return special handle.
 */
HIC VFWAPI ICOpen(DWORD fccType, DWORD fccHandler, UINT wMode) 
{
    WCHAR		codecname[10];
    ICOPEN		icopen;
    HDRVR		hdrv;
    WINE_HIC*           whic;
    static const WCHAR  drv32W[] = {'d','r','i','v','e','r','s','3','2','\0'};
    reg_driver*         driver;

    TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wMode);

    /* Check if there is a registered driver that matches */
    driver = reg_driver_list;
    while(driver)
        if (!compare_fourcc(fccType, driver->fccType) &&
            !compare_fourcc(fccHandler, driver->fccHandler))
	    break;
        else
            driver = driver->next;

    if (driver && driver->proc)
	/* The driver has been registered at runtime with its driverproc */
        return ICOpenFunction(fccType, fccHandler, wMode, driver->proc);
  
    /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
     * same layout as ICOPEN
     */
    icopen.dwSize		= sizeof(ICOPEN);
    icopen.fccType		= fccType;
    icopen.fccHandler	        = fccHandler;
    icopen.dwVersion            = 0x00001000; /* FIXME */
    icopen.dwFlags		= wMode;
    icopen.dwError              = 0;
    icopen.pV1Reserved          = NULL;
    icopen.pV2Reserved          = NULL;
    icopen.dnDevNode            = 0; /* FIXME */
	
    if (!driver) {
        /* The driver is registered in the registry */
	fourcc_to_string(codecname, fccType);
        codecname[4] = '.';
	fourcc_to_string(codecname + 5, fccHandler);
        codecname[9] = '\0';

        hdrv = OpenDriver(codecname, drv32W, (LPARAM)&icopen);
        if (!hdrv) 
            return 0;
    } else {
        /* The driver has been registered at runtime with its name */
        hdrv = OpenDriver(driver->name, NULL, (LPARAM)&icopen);
        if (!hdrv) 
            return 0; 
    }

    whic = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC));
    if (!whic)
    {
        CloseDriver(hdrv, 0, 0);
        return FALSE;
    }
    whic->hdrv          = hdrv;
    whic->driverproc    = NULL;
    whic->type          = fccType;
    whic->handler       = fccHandler;
    while (MSVIDEO_GetHicPtr((HIC)(ULONG_PTR)IC_HandleRef) != NULL) IC_HandleRef++;
    whic->hic           = (HIC)(ULONG_PTR)IC_HandleRef++;
    whic->next          = MSVIDEO_FirstHic;
    MSVIDEO_FirstHic = whic;

    TRACE("=> %p\n", whic->hic);
    return whic->hic;
}
Пример #14
0
/***********************************************************************
 *		ICOpen				[MSVFW32.@]
 * Opens an installable compressor. Return special handle.
 */
HIC VFWAPI ICOpen(DWORD fccType, DWORD fccHandler, UINT wMode) 
{
    WCHAR		codecname[10];
    ICOPEN		icopen;
    HDRVR		hdrv;
    WINE_HIC*           whic;
    static const WCHAR  drv32W[] = {'d','r','i','v','e','r','s','3','2','\0'};
    reg_driver*         driver;

    TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wMode);

    if (!fccHandler) /* No specific handler, return the first valid for wMode */
    {
        HIC local;
        ICINFO info;
        DWORD loop = 0;
        info.dwSize = sizeof(info);
        while(ICInfo(fccType, loop++, &info))
        {
            /* Ensure fccHandler is not 0x0 because we will recurse on ICOpen */
            if(!info.fccHandler)
                continue;
            local = ICOpen(fccType, info.fccHandler, wMode);
            if (local != 0)
            {
                TRACE("Returning %s as default handler for %s\n",
                      wine_dbgstr_fcc(info.fccHandler), wine_dbgstr_fcc(fccType));
                return local;
            }
        }
    }

    /* Check if there is a registered driver that matches */
    driver = reg_driver_list;
    while(driver)
        if (!compare_fourcc(fccType, driver->fccType) &&
            !compare_fourcc(fccHandler, driver->fccHandler)) {
	    fccType = driver->fccType;
	    fccHandler = driver->fccHandler;
	    break;
        } else
            driver = driver->next;

    if (driver && driver->proc)
        /* The driver has been registered at runtime with its driverproc */
        return ICOpenFunction(fccType, fccHandler, wMode, driver->proc);
  
    /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
     * same layout as ICOPEN
     */
    icopen.dwSize      = sizeof(ICOPEN);
    icopen.fccType     = fccType;
    icopen.fccHandler  = fccHandler;
    icopen.dwVersion   = 0x00001000; /* FIXME */
    icopen.dwFlags     = wMode;
    icopen.dwError     = 0;
    icopen.pV1Reserved = NULL;
    icopen.pV2Reserved = NULL;
    icopen.dnDevNode   = 0; /* FIXME */

    if (!driver) {
        /* normalize to lower case as in 'vidc' */
        ((char*)&fccType)[0] = tolower(((char*)&fccType)[0]);
        ((char*)&fccType)[1] = tolower(((char*)&fccType)[1]);
        ((char*)&fccType)[2] = tolower(((char*)&fccType)[2]);
        ((char*)&fccType)[3] = tolower(((char*)&fccType)[3]);
        icopen.fccType = fccType;
        /* Seek the driver in the registry */
        fourcc_to_string(codecname, fccType);
        codecname[4] = '.';
        fourcc_to_string(codecname + 5, fccHandler);
        codecname[9] = '\0';

        hdrv = OpenDriver(codecname, drv32W, (LPARAM)&icopen);
        if (!hdrv)
            return 0;
    } else {
        /* The driver has been registered at runtime with its name */
        hdrv = OpenDriver(driver->name, NULL, (LPARAM)&icopen);
        if (!hdrv) 
            return 0; 
    }

    whic = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC));
    if (!whic)
    {
        CloseDriver(hdrv, 0, 0);
        return FALSE;
    }
    whic->hdrv          = hdrv;
    whic->driverproc    = NULL;
    whic->type          = fccType;
    whic->handler       = fccHandler;
    while (MSVIDEO_GetHicPtr((HIC)(ULONG_PTR)IC_HandleRef) != NULL) IC_HandleRef++;
    whic->hic           = (HIC)(ULONG_PTR)IC_HandleRef++;
    whic->next          = MSVIDEO_FirstHic;
    MSVIDEO_FirstHic = whic;

    TRACE("=> %p\n", whic->hic);
    return whic->hic;
}
Пример #15
0
//--------------------------------------------------------------------------
bool ReadDriver(const bool verbose, const char *logDir, UINT32 snapLen)
{
	enum State {
		STATE_NORMAL,       // Normal operation
		STATE_ROTATING,     // Rotating the log
		STATE_CLEANING_UP,  // Ensuring last record is fully read before exiting
		STATE_DONE,         // Done running
	};

	char                *buffer     = NULL;
	static const UINT32  bufferSize = 75000;
	DWORD                bytesRead;
	DWORD                bytesReturned;
	DWORD                bytesWritten;
	HANDLE               driver     = INVALID_HANDLE_VALUE;
	HANDLE               log        = INVALID_HANDLE_VALUE;
	char                 logFile[MAX_PATH];
	bool                 rc         = false;
	enum State           state      = STATE_NORMAL;
	UINT32               snapLenSet;

	gVerbose = verbose;

	if (!SetConsoleCtrlHandler(ConsoleHandler, TRUE)) {
		LogError("Cannot set console control handler");
		goto Cleanup;
	}
	if (verbose) {
		fputs("Press CTRL-C to exit and CTRL-BREAK to rotate log\n", stdout);
	}

	gDataEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
	if (gDataEvent == NULL) {
		LogError("Cannot create data event");
		goto Cleanup;
	}
	if (verbose) {
		printf("Data event handle is %u\n", gDataEvent);
	}

	driver = OpenDriver(verbose);
	if (driver == INVALID_HANDLE_VALUE) {
		goto Cleanup;
	}

	if (!DeviceIoControl(driver, IOCTL_HONE_SET_DATA_EVENT, &gDataEvent,
			sizeof(HANDLE), NULL, 0, &bytesReturned, NULL)) {
		LogError("Cannot send IOCTL to set data event");
		goto Cleanup;
	}

	if (!DeviceIoControl(driver, IOCTL_HONE_SET_SNAP_LENGTH, &snapLen,
			sizeof(UINT32), NULL, 0, &bytesReturned, NULL)) {
		LogError("Cannot send IOCTL to set snap length");
		goto Cleanup;
	}

	if (!DeviceIoControl(driver, IOCTL_HONE_GET_SNAP_LENGTH, NULL, 0,
			&snapLenSet, sizeof(UINT32), &bytesReturned, NULL)) {
		LogError("Cannot send IOCTL to get snap length");
		goto Cleanup;
	}
	if (verbose) {
		if (snapLenSet) {
			printf("Snap length set to %u\n", snapLenSet);
		} else {
			printf("Snap length set to 0 (unlimited)\n");
		}
	}

	log = OpenPcapNgFile(logDir, logFile, sizeof(logFile));
	if (log == INVALID_HANDLE_VALUE) {
		goto Cleanup;
	}

	buffer = reinterpret_cast<char*>(malloc(bufferSize));
	if (!buffer) {
		printf("Cannot allocate %d bytes for read buffer\n", bufferSize);
		goto Cleanup;
	}

	while (state != STATE_DONE) {
		const LONG restart = InterlockedCompareExchange(&gRestart, 0, 1);
		const LONG cleanup = InterlockedCompareExchange(&gCleanup, 0, 1);
		if (restart || cleanup) {
			if (!DeviceIoControl(driver, IOCTL_HONE_MARK_RESTART, NULL, 0, NULL, 0,
					&bytesReturned, NULL)) {
				LogError("Cannot send IOCTL to restart log");
				goto Cleanup;
			}

			if (cleanup) {
				state = STATE_CLEANING_UP;
			} else if (state == STATE_NORMAL) {
				state = STATE_ROTATING;
			}
		}

		if (!ReadFile(driver, buffer, bufferSize, &bytesRead, NULL)) {
			LogError("Cannot read %d bytes from driver", bufferSize);
			goto Cleanup;
		}
		if (bytesRead) {
			if (verbose) {
				printf("Read %d bytes\n", bytesRead);
			}

			if (!WriteFile(log, buffer, bytesRead, &bytesWritten, NULL)) {
				LogError("Cannot write %d bytes to %s", bytesRead, logFile);
				goto Cleanup;
			}
			if (bytesRead != bytesWritten) {
				printf("Only wrote %d of %d bytes to %s\n", bytesWritten, bytesRead,
						logFile);
				goto Cleanup;
			}
		} else {
			// No data to read
			switch (state) {
			case STATE_NORMAL:
				if (WaitForSingleObject(gDataEvent, INFINITE) == WAIT_FAILED) {
					LogError("Cannot wait for data event");
					goto Cleanup;
				}
				ResetEvent(gDataEvent);
				break;
			case STATE_ROTATING:
				CloseHandle(log);
				log = OpenPcapNgFile(logDir, logFile, sizeof(logFile));
				if (!log) {
					goto Cleanup;
				}
				state = STATE_NORMAL;
				break;
			default:
				state = STATE_DONE;
				break;
			}
		}
	}

	rc = true;

Cleanup:
	if (gDataEvent != NULL) {
		CloseHandle(gDataEvent);
	}
	if (driver != INVALID_HANDLE_VALUE) {
		CloseHandle(driver);
	}
	if (log != INVALID_HANDLE_VALUE) {
		CloseHandle(log);
	}
	if (buffer != NULL) {
		free(buffer);
	}
	return rc;
}
Пример #16
0
CPWMDriver::CPWMDriver()
{
	m_hPWMDriver = INVALID_HANDLE_VALUE;

	OpenDriver();
}
Пример #17
0
/***********************************************************************
 *           acmDriverOpen (MSACM32.@)
 */
MMRESULT WINAPI acmDriverOpen(PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpen)
{
    PWINE_ACMDRIVERID	padid;
    PWINE_ACMDRIVER	pad = NULL;
    MMRESULT		ret;

    TRACE("(%p, %p, %08u)\n", phad, hadid, fdwOpen);

    if (!phad) {
        WARN("invalid parameter\n");
	return MMSYSERR_INVALPARAM;
    }

    if (fdwOpen) {
        WARN("invalid flag\n");
	return MMSYSERR_INVALFLAG;
    }

    padid = MSACM_GetDriverID(hadid);
    if (!padid) {
        WARN("invalid handle\n");
	return MMSYSERR_INVALHANDLE;
    }

    pad = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVER));
    if (!pad) {
        WARN("no memory\n");
        return MMSYSERR_NOMEM;
    }

    pad->obj.dwType = WINE_ACMOBJ_DRIVER;
    pad->obj.pACMDriverID = padid;
    pad->hDrvr = 0;
    pad->pLocalDrvrInst = NULL;

    if (padid->pLocalDriver == NULL)
    {
        ACMDRVOPENDESCW	adod;
        int		len;
        LPWSTR		section_name;

	/* this is not an externally added driver... need to actually load it */
	if (!padid->pszDriverAlias)
        {
            ret = MMSYSERR_ERROR;
            goto gotError;
        }

        adod.cbStruct = sizeof(adod);
        adod.fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
        adod.fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
        adod.dwVersion = acmGetVersion();
        adod.dwFlags = fdwOpen;
        adod.dwError = 0;
        len = strlen("Drivers32") + 1;
        section_name = HeapAlloc(MSACM_hHeap, 0, len * sizeof(WCHAR));
        MultiByteToWideChar(CP_ACP, 0, "Drivers32", -1, section_name, len);
        adod.pszSectionName = section_name;
        adod.pszAliasName = padid->pszDriverAlias;
        adod.dnDevNode = 0;

        pad->hDrvr = OpenDriver(padid->pszDriverAlias, NULL, (DWORD_PTR)&adod);

        HeapFree(MSACM_hHeap, 0, section_name);
        if (!pad->hDrvr)
        {
            ret = adod.dwError;
            if (ret == MMSYSERR_NOERROR)
                ret = MMSYSERR_NODRIVER;
            goto gotError;
        }
    }
    else
    {
        ACMDRVOPENDESCW	adod;

        pad->hDrvr = NULL;

        adod.cbStruct = sizeof(adod);
        adod.fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
        adod.fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
        adod.dwVersion = acmGetVersion();
        adod.dwFlags = fdwOpen;
        adod.dwError = 0;
        adod.pszSectionName = NULL;
        adod.pszAliasName = NULL;
        adod.dnDevNode = 0;

        pad->pLocalDrvrInst = MSACM_OpenLocalDriver(padid->pLocalDriver, (DWORD_PTR)&adod);
        if (!pad->pLocalDrvrInst)
        {
            ret = adod.dwError;
            if (ret == MMSYSERR_NOERROR)
                ret = MMSYSERR_NODRIVER;
            goto gotError;
        }
    }

    /* insert new pad at beg of list */
    pad->pNextACMDriver = padid->pACMDriverList;
    padid->pACMDriverList = pad;

    /* FIXME: Create a WINE_ACMDRIVER32 */
    *phad = (HACMDRIVER)pad;
    TRACE("%s => %p\n", debugstr_w(padid->pszDriverAlias), pad);

    return MMSYSERR_NOERROR;
 gotError:
    WARN("failed: ret = %08x\n", ret);
    if (pad && !pad->hDrvr)
	HeapFree(MSACM_hHeap, 0, pad);
    return ret;
}
Пример #18
0
//--------------------------------------------------------------------------
bool GetStatistics(const bool verbose, UINT32 snapLen)
{
	bool        rc = false;
	DWORD       bytesReturned;
	HANDLE      driver;
	STATISTICS  statistics;
	TIME        loadedTime;
	TIME        loggingTime;

	driver = OpenDriver(verbose);
	if (driver == INVALID_HANDLE_VALUE) {
		goto Cleanup;
	}

	if (snapLen) {
		if (!DeviceIoControl(driver, IOCTL_HONE_SET_SNAP_LENGTH, &snapLen,
				sizeof(UINT32), NULL, 0, &bytesReturned, NULL)) {
			LogError("Cannot send IOCTL to set snap length");
			goto Cleanup;
		}
	}

	if (!DeviceIoControl(driver, IOCTL_HONE_GET_STATISTICS, NULL, 0,
			&statistics, sizeof(statistics), &bytesReturned, NULL)) {
		LogError("Cannot send IOCTL to get snap length", stdout);
		goto Cleanup;
	}

	SecondsToTime(statistics.LoadedTime,  loadedTime);
	SecondsToTime(statistics.LoggingTime, loggingTime);

	printf(
		"Driver version . . . . . . . . . . . . . . . . . . %u.%u.%u\n"
		"Time elapsed since driver was loaded . . . . . . . %u days %u hours %u minutes %u seconds\n"
		"Time driver has had readers attached . . . . . . . %u days %u hours %u minutes %u seconds\n"
		"Total number of readers since driver was loaded  . %u\n"
		"Number of readers  . . . . . . . . . . . . . . . . %u\n"
		"Number of processes tracked by the driver  . . . . %u\n"
		"Number of connections tracked by the driver  . . . %u\n"
		"Ring buffer size . . . . . . . . . . . . . . . . . %u\n"
		"Maximum snap length  . . . . . . . . . . . . . . . %u\n"
		"This reader's ID . . . . . . . . . . . . . . . . . %u\n"
		"This reader's ring buffer size . . . . . . . . . . %u\n"
		"This reader's snap length  . . . . . . . . . . . . %u\n"
		"Total number of packets captured . . . . . . . . . %I64u\n"
		"Total number of packet bytes captured  . . . . . . %I64u\n"
		"Total number of process start events . . . . . . . %u\n"
		"Total number of process end events . . . . . . . . %u\n"
		"Total number of connection open events . . . . . . %u\n"
		"Total number of connection close events  . . . . . %u\n",
		statistics.VersionMajor, statistics.VersionMinor, statistics.VersionMicro,
		loadedTime.Days,  loadedTime.Hours,  loadedTime.Minutes,  loadedTime.Seconds,
		loggingTime.Days, loggingTime.Hours, loggingTime.Minutes, loggingTime.Seconds,
		statistics.TotalReaders,
		statistics.NumReaders,
		statistics.NumProcesses,
		statistics.NumConnections,
		statistics.RingBufferSize,
		statistics.MaxSnapLength,
		statistics.ReaderId,
		statistics.ReaderBufferSize,
		statistics.ReaderSnapLength,
		statistics.CapturedPackets,
		statistics.CapturedPacketBytes,
		statistics.ProcessStartEvents,
		statistics.ProcessEndEvents,
		statistics.ConnectionOpenEvents,
		statistics.ConnectionCloseEvents);
	rc = true;

Cleanup:
	if (driver != INVALID_HANDLE_VALUE) {
		CloseHandle(driver);
	}
	return rc;
}
Пример #19
0
/* Before main(), get an FD for the driver program, so that it is still
   accessible even if the application enters a sandbox. */
void __attribute__((constructor)) _stub_construct(void) {
  g_exe_fd = OpenDriver(g_exe_file);
}
Пример #20
0
int PASCAL WinMain(HANDLE hInstance,
                   HANDLE hPrevInstance, LPSTR lpszCmdLine, int iCmd)

{
    int i;
    MSG msg;
    LPSTR pch,pch1;
    WORD    ret;
    WOWINFO wowinfo;
    char aszWOWDEB[CCHMAX];
    LPSTR pchWOWDEB;
    HANDLE hMMDriver;


    char        szBuffer[150];
    BOOL        bFinished;
    int         iStart;
    int         iEnd;


    hAppInstance = hInstance ;

    // Only Want One WOWExec
    if (hPrevInstance != NULL) {
        return(FALSE);
    }

    if (!InitializeApp(lpszCmdLine)) {
        OutputDebugString("WOWEXEC: InitializeApp failure!\n");
        return 0;
    }

/*
 * Look for a drivers= line in the [boot] section of SYSTEM.INI
 * If present it is the 16 bit MultiMedia interface, so load it
 */

#ifdef OLD_MMSYSTEM_LOAD
    if (GetPrivateProfileString((LPSTR)"boot", (LPSTR)"drivers",(LPSTR)"", aszMMDriver, sizeof(aszMMDriver), (LPSTR)"SYSTEM.INI")) {
/*
 * We have now discovered an app that rewrites the "drivers" entry with
 * multiple drivers - so the existing load method fails. As a temporary fix
 * while we decide what the "proper" fix is I will always load MMSYSTEM and
 * ONLY MMSYSTEM.
 *
 *       aszMMDriver[sizeof(aszMMDriver)-1] = '\0';
 *       hMMDriver = LoadLibrary((LPSTR)aszMMDriver);
 * #ifdef DEBUG
 *       if (hMMDriver < 32) {
 *           OutputDebugString("WOWEXEC: Load of MultiMedia driver failed\n");
 *       }
 * #endif
 */
        LoadLibrary("MMSYSTEM.DLL");
    }
#else
    /* Load DDL's from DRIVERS section in system.ini
     */
    GetPrivateProfileString( (LPSTR)"boot",      /* [Boot] section */
                            (LPSTR)"drivers",   /* Drivers= */
                            (LPSTR)"",          /* Default if no match */
                            szBuffer,    /* Return buffer */
                            sizeof(szBuffer),
                            (LPSTR)"system.ini" );

    if (!*szBuffer) {
        goto Done;
    }

    bFinished = FALSE;
    iStart    = 0;

    while (!bFinished) {
        iEnd = iStart;

        while (szBuffer[iEnd] && (szBuffer[iEnd] != ' ') &&
               (szBuffer[iEnd] != ',')) {
            iEnd++;
        }

        if (szBuffer[iEnd] == NULL) {
            bFinished = TRUE;
        }
        else {
            szBuffer[iEnd] = NULL;
        }

        /* Load and enable the driver.
         */
        OpenDriver( &(szBuffer[iStart]), NULL, NULL );
        iStart = iEnd + 1;
    }

Done:

#endif

/*
 * Look for a debug= line in the [boot] section of SYSTEM.INI
 * If present it is the 16 bit MultiMedia interface, so load it
 */

    if ( WOWQueryDebug() & 0x0001 ) {
        pchWOWDEB = "WOWDEB.EXE";
    } else {
        pchWOWDEB = "";
    }

    GetPrivateProfileString((LPSTR)"boot", (LPSTR)"debug",pchWOWDEB, aszWOWDEB, sizeof(aszWOWDEB), (LPSTR)"SYSTEM.INI");
    aszWOWDEB[sizeof(aszWOWDEB)-1] = '\0';

    if ( lstrlen(pchWOWDEB) != 0 ) {
        WinExec((LPSTR)aszWOWDEB,SW_SHOW);
    }

#if 0
/*  Preload winspool.exe.   Apps will keep loading and freeing it
 *  which is slow.   We might as well load it now so the reference
 *  count is 1 so it will never be loaded or freed
 */
    //
    // Disabled load of winspool.exe to save 8k.  Size vs. speed,
    // which one do we care about?  Right now, size!
    //
    LoadLibrary("WINSPOOL.EXE");
#endif

    // Always load SHELL.DLL, FileMaker Pro and Lotus Install require it.

    LoadLibrary("SHELL.DLL");

    //
    // Start any apps pending in basesrv queue
    //

    while (StartRequestedApp() && gfSharedWOW) {
        /* null stmt */ ;
    }


    while (1)  {
        if (!WowWaitForMsgAndEvent(ghwndMain) &&
            PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) &&
            msg.message != WM_WOWEXECHEARTBEAT )
           {
            if (msg.message != WM_QUIT) {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
    }

    return 1;
}
Пример #21
0
int main(int argc, char *argv[])
{
    char *driver = NULL;
    char *fourcc = NULL;
    char *filename = NULL;
    unsigned char mode = 0;
    DWORD dwFCC = 0;
    ICOPEN icopen;
    HRESULT coinit = S_FALSE;
    /* ICINFO icinfo; */

    wchar_t drvfile[MAX_PATH];
    HDRVR hDriver = NULL;
    int ret = 0;
    int c = -1, long_options_index = -1;

    if (argc < 2)
    {
        help(argv[0]);
        ret = -1;
        goto cleanup;
    }

    while ((c = getopt_long(argc, argv, "hd:f:s:c:v", long_options, &long_options_index)) != -1)
    {
        switch (c)
        {
            case 'h':
                help(argv[0]);
                ret = 0;
                goto cleanup;
            case 'd':
                driver = strdup(optarg);
                break;
            case 'f':
                fourcc = strdup(optarg);
                if (strlen(optarg) != 4) BAIL("Fourcc must be exactly 4 chars");
                break;
            case 's':
                if (mode != MODE_NONE) BAIL("Incompatible arguments");
                filename = strdup(optarg);
                mode = MODE_SAVE;
                break;
            case 'c':
                if (mode != MODE_NONE) BAIL("Incompatible arguments");
                filename = strdup(optarg);
                mode = MODE_CHECK;
                break;
            case 'v':
                if (mode != MODE_NONE) BAIL("Incompatible arguments");
                mode = MODE_VIEW;
                break;
            default:
                printf("Wrong arguments!\n");
                help(argv[0]);
                goto cleanup;
        }
    }

    if (!(argc == optind) && (mode != MODE_NONE) &&
        driver && (filename || (mode == MODE_VIEW)))
    {
        help(argv[0]);
        goto cleanup;
    }

    if (!MultiByteToWideChar(CP_ACP, 0, driver, -1, drvfile, MAX_PATH))
        BAIL("MultiByteToWideChar() failed\n");

    if (fourcc) memcpy(&dwFCC, fourcc, 4);
    memset(&icopen, 0, sizeof(icopen));

    icopen.dwSize = sizeof(icopen);
    icopen.fccType = ICTYPE_VIDEO; /* VIDC */
    icopen.fccHandler = dwFCC;
    icopen.dwVersion  = 0x00001000; /* FIXME */
    icopen.dwFlags = ICMODE_COMPRESS;
    icopen.dwError = 0;
    icopen.pV1Reserved = NULL;
    icopen.pV2Reserved = NULL;
    icopen.dnDevNode = -1; /* FIXME */

    coinit = CoInitialize(NULL);

    if (!(hDriver = OpenDriver(drvfile, NULL, (LPARAM) &icopen)))
        BAIL("OpenDriver() failed\n");

   /*
        memset(&icinfo, 0, sizeof(ICINFO));
        icinfo.dwSize = sizeof(ICINFO);
        SendDriverMessage(hDriver, ICM_GETINFO, (LPARAM) &icinfo, sizeof(ICINFO));
    */

    if (SendDriverMessage(hDriver, ICM_CONFIGURE, -1, 0) != ICERR_OK)
        BAIL("The driver doesn't provide a configure dialog");


    switch(mode)
    {
        case MODE_CHECK:
            if (load_settings(hDriver, filename))
                BAIL("Cannot load settings from file");
            if (SendDriverMessage(hDriver, ICM_CONFIGURE, 0, 0) != ICERR_OK)
                BAIL("ICM_CONFIGURE failed");
            break;
        case MODE_SAVE:
            if (SendDriverMessage(hDriver, ICM_CONFIGURE, 0, 0) != ICERR_OK)
                BAIL("ICM_CONFIGURE failed");
            if (save_settings(hDriver, filename))
                BAIL("Cannot save settings to file");
            break;
        case MODE_VIEW:
            {
                HWND hwnd = GetDesktopWindow();
                if (SendDriverMessage(hDriver, ICM_CONFIGURE, (LPARAM) hwnd, 0) != ICERR_OK)
                    BAIL("ICM_CONFIGURE failed");
            }
            break;
        default:
            BAIL("This should not happen :)");
    }

cleanup:
    if (driver) free(driver);
    if (fourcc) free(fourcc);
    if (filename) free(filename);
    if (hDriver) CloseDriver(hDriver, 0, 0);
    if (coinit == S_OK) CoUninitialize();
    return ret;
}
Пример #22
0
/***********************************************************************
 *           acmFormatEnumW (MSACM32.@)
 */
static BOOL MSACM_FormatEnumHelper(PWINE_ACMDRIVERID padid, HACMDRIVER had,
				   PACMFORMATDETAILSW pafd, PWAVEFORMATEX pwfxRef,
                                   ACMFORMATENUMCBW fnCallback,
                                   DWORD_PTR dwInstance, DWORD fdwEnum)
{
    ACMFORMATTAGDETAILSW	aftd;
    unsigned int			i, j;

    if (fdwEnum & ACM_FORMATENUMF_SUGGEST) {
        HDRVR hdrvr;
        ACMDRVFORMATSUGGEST adfs;
        pafd->dwFormatIndex = 0;
        memset(&aftd, 0, sizeof(aftd));
        aftd.cbStruct = sizeof(aftd);
        memset(&adfs, 0, sizeof(adfs));
        adfs.cbStruct = sizeof(adfs);

        for (i = 0; i < padid->cFormatTags; i++) {
            aftd.dwFormatTag = i;
            pafd->dwFormatTag = aftd.dwFormatTag;
            pafd->pwfx->wFormatTag = pafd->dwFormatTag;

            if (acmFormatTagDetailsW(had, &aftd, ACM_FORMATTAGDETAILSF_INDEX) != MMSYSERR_NOERROR)
                continue;

            adfs.cbwfxSrc = aftd.cbFormatSize;
            adfs.cbwfxDst = aftd.cbFormatSize;
            adfs.pwfxSrc = pwfxRef;
            adfs.pwfxDst = pafd->pwfx;
            pafd->fdwSupport = padid->fdwSupport;

            if ((fdwEnum & ACM_FORMATENUMF_WFORMATTAG) &&
                aftd.dwFormatTag != pwfxRef->wFormatTag)
                continue;

            if ((fdwEnum & ACM_FORMATENUMF_HARDWARE) &&
                !(pafd->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_HARDWARE))
                continue;

            hdrvr = OpenDriver(padid->pszFileName,0,0);
            SendDriverMessage(hdrvr,ACMDM_FORMAT_SUGGEST,(LPARAM)&adfs,(fdwEnum & 0x000000FFL));

            if (acmFormatDetailsW(had, pafd, ACM_FORMATDETAILSF_FORMAT) != MMSYSERR_NOERROR)
                continue;

            pafd->cbwfx = sizeof(*(pafd->pwfx));

            if (!(fnCallback)((HACMDRIVERID)padid, pafd, dwInstance, padid->fdwSupport))
                return FALSE;
        }
    } else {
        for (i = 0; i < padid->cFormatTags; i++) {
            memset(&aftd, 0, sizeof(aftd));
            aftd.cbStruct = sizeof(aftd);
            aftd.dwFormatTagIndex = i;
            if (acmFormatTagDetailsW(had, &aftd, ACM_FORMATTAGDETAILSF_INDEX) != MMSYSERR_NOERROR)
                continue;

            if ((fdwEnum & ACM_FORMATENUMF_WFORMATTAG) && aftd.dwFormatTag != pwfxRef->wFormatTag)
                continue;

            for (j = 0; j < aftd.cStandardFormats; j++) {
                pafd->dwFormatIndex = j;
                pafd->dwFormatTag = aftd.dwFormatTag;
                if (acmFormatDetailsW(had, pafd, ACM_FORMATDETAILSF_INDEX) != MMSYSERR_NOERROR)
                    continue;

                if ((fdwEnum & ACM_FORMATENUMF_NCHANNELS) &&
                    pafd->pwfx->nChannels != pwfxRef->nChannels)
                    continue;
                if ((fdwEnum & ACM_FORMATENUMF_NSAMPLESPERSEC) &&
                    pafd->pwfx->nSamplesPerSec != pwfxRef->nSamplesPerSec)
                    continue;
                if ((fdwEnum & ACM_FORMATENUMF_WBITSPERSAMPLE) &&
                    pafd->pwfx->wBitsPerSample != pwfxRef->wBitsPerSample)
                    continue;
                if ((fdwEnum & ACM_FORMATENUMF_HARDWARE) &&
                    !(pafd->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_HARDWARE))
                    continue;

            /* more checks to be done on fdwEnum */

                if (!(fnCallback)((HACMDRIVERID)padid, pafd, dwInstance, padid->fdwSupport))
                    return FALSE;
            }
        /* the "formats" used by the filters are also reported */
        }
    }
    return TRUE;
}
Пример #23
-1
P1(PUBLIC pascal trap, INTEGER, OpenDeskAcc, Str255, acc)	/* IMI-440 */
{
    INTEGER retval;
    DCtlHandle dctlh;
    WindowPtr wp;

    if (EqualString (acc, about_box_menu_name_pstr, TRUE, TRUE))
      {
	do_about_box ();
	retval = 0;
	goto done;
      }

    if (OpenDriver(acc, &retval) == noErr) {
	retval = CW(retval);
	dctlh = GetDCtlEntry(retval);
	if (dctlh)
	  {
	    wp = HxP(dctlh, dCtlWindow);
	    if (wp)
	      {
		ShowWindow(wp);
		SelectWindow(wp);
	      }
	  }
    }

  done:

    SEvtEnb = TRUE;
    return retval;
}