Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I Wrote a driver for WIN7 64bits computer ,now the driver can be installed on the computer successfully ,but there is a bug. After installed the driver, the driver should run immediately on the compter.but it wasn;t. after i replug the device the driver started working ,anyone know how to soolve this ?is that i need a restart after installation?please give me direction on how to solve this ,thanks .
here are the code for installedselectedsriver( i think this part of code have some problem,but i can find it):
typedef BOOL (*PINSTALLSELECTEDDRIVER)(
  HWND hwndParent,
  HDEVINFO DeviceInfoSet,
  LPCWSTR Reserved,
  BOOL Backup,
  PDWORD pReboot    
  );

	DeviceInfoSet = SetupDiGetClassDevs(&guidHID1,
		NULL,
		0,   
		DIGCF_PRESENT|DIGCF_INTERFACEDEVICE);
	if(DeviceInfoSet == INVALID_HANDLE_VALUE) 
	{
	
		MessageBox(_T("the device is not connected "));
		return;
	}
	SP_DEVICE_INTERFACE_DATA strtInterfaceData;
	strtInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
	TCHAR InstanceId[MAX_PATH];
	DWORD index = 0;
	CString temp;
	BOOL findFlag = false;
	int i = 0;
		while(1)
	{
		
		if(!SetupDiEnumDeviceInterfaces(DeviceInfoSet, 
			NULL, 
			&guidHID, 
			i,
			&strtInterfaceData))   
		
		{
			break;
		}
		i++;
		if(strtInterfaceData.Flags == SPINT_ACTIVE )
		{
			
			DWORD strSize = 0, requiesize = 0;
			DWORD nSize= 0;
			
			SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, 
				&strtInterfaceData, 
				NULL, 
				0, 
				&strSize, 
				NULL);
			requiesize = strSize;  
			PSP_DEVICE_INTERFACE_DETAIL_DATA strtDetailData;
			strtDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(requiesize);
			strtDetailData -> cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
			
			DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
			if(!SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, 
				&strtInterfaceData,
				strtDetailData, 
				strSize, 
				&requiesize, 
				&DeviceInfoData))
			{
				MessageBox(_T("can not get the interface information"));
				free(strtDetailData);
				break;
			}
	if(!SetupDiGetDeviceInstanceId(DeviceInfoSet,&DeviceInfoData,InstanceId,sizeof(InstanceId),&nSize)) 
	{
		MessageBox(_T("can not get the instanceid"));
	}
  }
}
		 DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL);
    if (DeviceInfoSet == INVALID_HANDLE_VALUE)
	{
        Err = GetLastError();
       // goto clean0;
	}
	  DeviceInfoData.cbSize = sizeof(DeviceInfoData);
    if (!SetupDiOpenDeviceInfo(DeviceInfoSet,
                               (PCTSTR)InstanceId,
                               NULL,
                               0,
                               &DeviceInfoData)) {
        Err = GetLastError();
        //goto clean0;
    }
	 if (!SetupDiSetSelectedDevice(DeviceInfoSet,
                                  &DeviceInfoData)) {
        Err = GetLastError();
        //goto clean0;
    }
	    DeviceInstallParams.cbSize = sizeof(DeviceInstallParams);
    if (!SetupDiGetDeviceInstallParams(DeviceInfoSet,
                                       &DeviceInfoData,
                                       &DeviceInstallParams)) {
        Err = GetLastError();
        //goto clean0;
    }
	 DeviceInstallParams.Flags |= DI_ENUMSINGLEINF;
	 CString path2;
    if (FAILED(StringCchCopy(DeviceInstallParams.DriverPath,
                             SIZECHARS(DeviceInstallParams.DriverPath),
                             path2)))
	{
        // The file path that was passed in was too big.
        Err = ERROR_INVALID_PARAMETER;
        //goto clean0;
    }
	 DeviceInstallParams.FlagsEx |= DI_FLAGSEX_ALLOWEXCLUDEDDRVS;
    if (!SetupDiSetDeviceInstallParams(DeviceInfoSet,
                                       &DeviceInfoData,
                                       &DeviceInstallParams))
	{
        Err = GetLastError();
        //goto clean0;
    }
	 if (!SetupDiBuildDriverInfoList(DeviceInfoSet,
                                    &DeviceInfoData,
                                    SPDIT_COMPATDRIVER)) 
	 {
        Err = GetLastError();
        //goto clean0;
    }
     if (!SetupDiCallClassInstaller(DIF_SELECTBESTCOMPATDRV,
                                   DeviceInfoSet,
                                   &DeviceInfoData))
	 {
        Err = GetLastError();
        //goto clean0;
    }
	   DriverInfoData.cbSize = sizeof(DriverInfoData);
    if (!SetupDiGetSelectedDriver(DeviceInfoSet,
                                  &DeviceInfoData,
                                  &DriverInfoData)) 
	{
        Err = GetLastError();
        //goto clean0;
    }
	  if (GetSystemDirectory(NewDevPath, SIZECHARS(NewDevPath)) == 0) {
        Err = GetLastError();
        //goto clean0;
    }
	  if (FAILED(StringCchCat(NewDevPath, SIZECHARS(NewDevPath), TEXT("\\NEWDEV.DLL")))) {
        Err = ERROR_INSUFFICIENT_BUFFER;
       // goto clean0;
    }
    hNewDev = LoadLibrary(NewDevPath);
    if (!hNewDev) {
        Err = GetLastError();
       //goto clean0;
    }
    pInstallSelectedDriver = (PINSTALLSELECTEDDRIVER)GetProcAddress(hNewDev, "InstallSelectedDriver");
    if (!pInstallSelectedDriver) {
        Err = GetLastError();
       // goto clean0;
    }
    //
    // Call pInstallSelectedDriver to install the selected driver on
    // the selected device.
    //
 if(!pInstallSelectedDriver(NULL,DeviceInfoSet,NULL,TRUE,&Reboot))
 {
	 DWORD myErr;
	 myErr = GetLastError();
	 AfxMessageBox(LPCTSTR(myErr));
 }
Posted
Updated 8-Jul-11 0:10am
v3

1 solution

If it works in the end, then it sounds like an issue with Windows 7 in general. Try installing some other drivers, if they work right away, then you have an issue in your code. But, if that's the case, no-one can resolve the issue in your code without seeing some of it.
 
Share this answer
 
Comments
markfilan 8-Jul-11 5:25am    
my driver is designed like this :when it startto installl. the device must be pluged first ,is that the problem ?BTW, I did not use updatedriverforplugandplaydevices()function.is that right? i used the installedselecteddriver() fuction.i tried on other computer ,it have the same problem.so it's my code.i will ad somepart of the code later .thanks for helping ~
markfilan 10-Jul-11 20:39pm    
no body knows how to solve this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900