|
本人在开发wince下的usb流驱动,已经实现usbinstalldriver函数,在usbdeviceattach函数中用activatedevice激活设备是,用getlasterror()返回1,不知道是什么原因。。。
以下是我的代码:
EG_VALUE_DESCR usbOBDValues[] = {
{(TEXT("Dll")), REG_SZ, 0, (PBYTE)(DRIVER_NAME)},
{(TEXT("Prefix")), REG_SZ, 0, (PBYTE)(DEVICE_PREFIX)},
{NULL,0,0,NULL}
};
BOOL USBInstallDriver(LPCWSTR szDriverLibFile)
{
WCHAR wsUsbDeviceID[] = CLASS_NAME_SZ; //OBD_Class
WCHAR wsSubClassRegKey[] = CLIENT_REGKEY_SZ;//Drivers\\USB\\ClientDrivers\\OBD_Class
USB_DRIVER_SETTINGS usbDriverSettings = { DRIVER_SETTINGS };
BOOL bSuccess;
LPREGISTER_CLIENT_DRIVER_ID lpfnRegisterClientDriverID;
LPREGISTER_CLIENT_SETTINGS lpfnRegisterClientSettings;
HINSTANCE hUSB=LoadLibrary(TEXT("USBd.dll"));
if (hUSB==0)
{
MessageBox(NULL,TEXT("usbd.dll"),TEXT("installdriver"),MB_OK);
return FALSE;
}
lpfnRegisterClientDriverID = (LPREGISTER_CLIENT_DRIVER_ID) GetProcAddress (hUSB, TEXT("RegisterClientDriverID"));
lpfnRegisterClientSettings = (LPREGISTER_CLIENT_SETTINGS) GetProcAddress (hUSB, TEXT("RegisterClientSettings"));
if ((lpfnRegisterClientDriverID == 0) || (lpfnRegisterClientSettings == 0))
{
FreeLibrary (hUSB);
return FALSE;
}
bSuccess = (lpfnRegisterClientDriverID) (wsUsbDeviceID);
if (!bSuccess)
{
FreeLibrary(hUSB);
return FALSE;
}
bSuccess = (lpfnRegisterClientSettings) (szDriverLibFile, wsUsbDeviceID,
NULL, &usbDriverSettings);
if (!bSuccess)
{
FreeLibrary (hUSB);
return FALSE;
}
usbDriverSettings.dwVendorId = csOBD.wVendorID;
usbDriverSettings.dwProductId = csOBD.wProductID;
usbDriverSettings.dwInterfaceClass=0x00;
usbDriverSettings.dwDeviceClass=0x00;
usbDriverSettings.dwDeviceProtocol=0x00;
usbDriverSettings.dwInterfaceProtocol=0x00;
usbDriverSettings.dwDeviceProtocol=0x00;
usbDriverSettings.dwDeviceSubClass=0x00;
usbDriverSettings.dwCount=sizeof(USB_DRIVER_SETTINGS);
bSuccess = (lpfnRegisterClientSettings) (szDriverLibFile, wsUsbDeviceID,
NULL, &usbDriverSettings);
if (!bSuccess)
{
FreeLibrary (hUSB);
return FALSE;
}
bSuccess = GetSetKeyValues (wsSubClassRegKey, usbOBDValues, SET, TRUE );
if (!bSuccess)
{
MessageBox(NULL,TEXT("getsek"),TEXT("kk"),MB_OK);
FreeLibrary (hUSB);
return FALSE;
}
bSuccess=FreeLibrary (hUSB);
return TRUE;
}
BOOL USBDeviceAttach(USB_HANDLE hDevice, LPCUSB_FUNCS lpUsbFuncs, LPCUSB_INTERFACE lpInterface,
LPCWSTR szUniqueDriverId, LPBOOL fAcceptControl, LPCUSB_DRIVER_SETTINGS lpDriverSettings, DWORD dwUnused)
{
MessageBox(NULL,TEXT("usbdeviceattach"),TEXT("1"),MB_OK);
WCHAR wsSubClassRegkey[]=CLIENT_REGKEY_SZ;
LPCUSB_DEVICE lpus=(lpUsbFuncs->lpGetDeviceInfo)(hDevice);
if (!lpus)
{
return FALSE;
}
Pdrv kk;
kk=(Pdrv)LocalAlloc(LPTR,sizeof(DRv));
kk->hde=hDevice;
kk->lp=lpUsbFuncs;
kk->dwsize=sizeof(DRv);
InitializeCriticalSection(&kk->csDCall);
kk->hStream=ActivateDevice(wsSubClassRegkey,(DOWD)kk);
if (!kk->hStream)
{
WCHAR tt[7];
_itow(GetLastError(),tt,16);
MessageBox(NULL,tt,TEXT("6788900"),MB_OK);
return FALSE;
}
}
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
查看注册表发现在HKEY_LOCAL_MACHINE\\Drivers\\USB\\ClientDrivers 和LoadClients
下已经有相应的注册信息,但是执行ActivateDevice(wsSubClassRegkey,(DOWD)kk); MessageBox(NULL,tt,TEXT("6788900"),MB_OK);显示的是1.
不知为何。。。。。。。。。。。。。。。。??? 恳请 大侠相救。。。
|
|