當(dāng)前位置:首頁文章首頁 IT學(xué)院 IT技術(shù)

全自動(dòng)安裝卸載驅(qū)動(dòng)程序的源程序

作者:  來源:  發(fā)布時(shí)間:2011-12-15 0:53:30  點(diǎn)擊:
   {

   DWORD DataT;

   LPTSTR p,buffer = NULL;

   DWORD buffersize = 0;

   //

   // We won't know the size of the HardwareID buffer until we call

   // this function. So call it with a null to begin with, and then

   // use the required buffer size to Alloc the nessicary space.

   // Keep calling we have success or an unknown failure.

   //

   while (!SetupDiGetDeviceRegistryProperty(

   DeviceInfoSet,

   &DeviceInfoData,

   SPDRP_HARDWAREID,

   &DataT,

   (PBYTE)buffer,

   buffersize,

   &buffersize))

   {

   if (GetLastError() == ERROR_INVALID_DATA)

   {

   //

   // May be a Legacy Device with no HardwareID. Continue.

   //

   break;

   }

   else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)

   {

   //

   // We need to change the buffer size.

   //

   if (buffer)

   LocalFree(buffer);

   buffer = (char *)LocalAlloc(LPTR,buffersize);

   }

   else

   {

   //

   // Unknown Failure.

   //

   DisplayError(TEXT(GetDeviceRegistryProperty));

   goto cleanup_DeviceInfo;

   }

   }

   if (GetLastError() == ERROR_INVALID_DATA)

   continue;

   //

   // Compare each entry in the buffer multi-sz list with our HardwareID.

   //

   for (p=buffer;*p&&(p<&buffer[buffersize]);p+=lstrlen(p)+sizeof(TCHAR))

   {

   //_tprintf(TEXT(Compare device ID: [%s]\\n),p);

   if (!_tcscmp(HardwareID,p))

   {

   //_tprintf(TEXT(Found! [%s]\\n),p);

   //

   // Worker function to remove device.

   //

   if (!SetupDiCallClassInstaller(DIF_REMOVE,

   DeviceInfoSet,

   &DeviceInfoData))

   {

   DisplayError(TEXT(CallClassInstaller(REMOVE)));

   }

   break;

   }

   }

   if (buffer) LocalFree(buffer);

   }

   if ((GetLastError()!=NO_ERROR)&&(GetLastError()!=ERROR_NO_MORE_ITEMS))

   {

   DisplayError(TEXT(EnumDeviceInfo));

   }

   //

   // Cleanup.

   //

  cleanup_DeviceInfo:

   err = GetLastError();

   SetupDiDestroyDeviceInfoList(DeviceInfoSet);

   return err;

  }

  [/scode]

首頁 上一頁 [1] [2] [3]  下一頁 尾頁

文章評論

軟件按字母排列: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z