| 
			 
					阅读:3756回复:3
				 
				急!!!VC编程安装驱动的一个问题!
					下面的代码在win2003下运行正常,但在win2k下运行报错,是怎么回事?(调用时报SetupDiSetDeviceRegistryProperty参数出错)
 
							请问sHardwareId参数有什么限制,怎样定义? m_sHardwareId.Format(\"root\\\\%s\",DriverFileName); if(InstallRootEnumeratedDriver((LPTSTR)(LPCTSTR)m_sHardwareId,(LPTSTR)(LPCTSTR)m_sPath,&bRebootRequred)) { AfxMessageBox(\"安装成功!\"); } BOOL CDrvSetupDlgDlg::InstallRootEnumeratedDriver(IN LPTSTR HardwareId, IN LPTSTR INFFile, OUT PBOOL RebootRequired OPTIONAL ) { HDEVINFO DeviceInfoSet = 0; SP_DEVINFO_DATA DeviceInfoData; GUID ClassGUID; TCHAR ClassName[MAX_CLASS_NAME_LEN]; DWORD err; if (!SetupDiGetINFClass(INFFile,&ClassGUID,ClassName,sizeof(ClassName),0)) { return DisplayError(TEXT(\"GetINFClass\")); } DeviceInfoSet = SetupDiCreateDeviceInfoList(&ClassGUID,0); if(DeviceInfoSet == INVALID_HANDLE_VALUE) { return DisplayError(TEXT(\"CreateDeviceInfoList\")); } DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); if (!SetupDiCreateDeviceInfo(DeviceInfoSet, ClassName, &ClassGUID, NULL, 0, DICD_GENERATE_ID, &DeviceInfoData)) { DisplayError(TEXT(\"CreateDeviceInfo\")); goto cleanup_DeviceInfo; } unsigned long lCount; lCount = (lstrlen(HardwareId)+1)*sizeof(TCHAR); if(!SetupDiSetDeviceRegistryProperty(DeviceInfoSet,&DeviceInfoData,SPDRP_HARDWAREID,(LPBYTE)HardwareId,lCount)) { DisplayError(TEXT(\"SetDeviceRegistryProperty\")); goto cleanup_DeviceInfo; } // // Transform the registry element into an actual devnode // in the PnP HW tree. // if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, DeviceInfoSet, &DeviceInfoData)) { DisplayError(TEXT(\"CallClassInstaller(REGISTERDEVICE)\")); goto cleanup_DeviceInfo; } if (!UpdateDriverForPlugAndPlayDevices(0, HardwareId, INFFile, INSTALLFLAG_FORCE, RebootRequired)) { DWORD err = GetLastError(); DisplayError(TEXT(\"UpdateDriverForPlugAndPlayDevices\")); if (!SetupDiCallClassInstaller( DIF_REMOVE, DeviceInfoSet, &DeviceInfoData)) { DisplayError(TEXT(\"CallClassInstaller(REMOVE)\")); } SetLastError(err); } // // Cleanup. // cleanup_DeviceInfo: err = GetLastError(); SetupDiDestroyDeviceInfoList(DeviceInfoSet); SetLastError(err); return err == NO_ERROR; }  | 
	|
| 
			 沙发# 
								发布于:2003-10-20 14:55				
			
					可能你调用了WINXP以后才支持API,仔细看看DDK说明吧.				 
							 | 
	|
					
						
  | 
	
| 
			 板凳# 
								发布于:2003-10-21 12:05				
			
					能说具体点吗?最好举个例子
 
							而且我这代码在VC中,用对话框程序编译运行就报错;用控制台程序DEBUG编译的程序运行时也报错,RELEASE编译的程序运行时就很正常!  | 
	|
| 
			 地板# 
								发布于:2003-11-03 10:27				
			unsigned long lCount; 问题通常出在参数lCount上,你换个方法。想办法让HardwareId中没有数据的部分都为0(例如,Memset(HardwareId, 0, sizeof(HardwareId)),然后再设定HardwardId。可以用strcat实现。参数lCount就设定为sizeof(HardwareId);  | 
	|
					
						
  |