예전에 어느분이 질문하셨던 내용인데,
아무도 답변이 없었던 내용입니다.
저도 관련 프로그램을 하려고 찾아보다가 DDK sample에서 해답을 얻었습니다.
관련함수 :
hDevInfo = SetupDiGetClassDevs(...);
SetupDiEnumDeviceInfo(...);
CM_Get_DevNode_Status(...);
SetupDiGetDeviceRegistryProperty(...);
등등
HELP : DDK HELP
해더파일 : 아래의 순서로 선언하세요..
#include <windows.h> // Most Windows functions
#include <cfgmgr32.h> // Used for CM_Xxxx functions
#include <vcl.h>
참조 : WINXP DDK 의 setup\enable 소스참조..
아래는 빌더로 약간 수정한 일부 소스입니다..참조하세요.
BOOL IsClassHidden( GUID * ClassGuid )
{
BOOL bHidden = FALSE;
HKEY hKeyClass;
//
// If the devices class has the NoDisplayClass value then
// don't display this device.
//
if (hKeyClass = SetupDiOpenClassRegKey(ClassGuid,KEY_READ))
{
bHidden = (RegQueryValueEx(hKeyClass,
REGSTR_VAL_NODISPLAYCLASS,
NULL, NULL, NULL, NULL) == ERROR_SUCCESS);
RegCloseKey(hKeyClass);
}
return bHidden;
}
BOOL GetRegistryProperty(HDEVINFO DeviceInfoSet,
PSP_DEVINFO_DATA DeviceInfoData,
ULONG Property,
PVOID Buffer,
PULONG Length)
{
BOOL state;
DWORD errdata;
while (1)
{
state=SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
DeviceInfoData,
Property,
NULL,
(PBYTE)Buffer,
*Length,
Length);
if(state) break;
errdata=GetLastError();
if (errdata == ERROR_INSUFFICIENT_BUFFER)
{
//
// We need to change the buffer size.
//
// if ((char *)Buffer)
// LocalFree((char *)Buffer);
// (char *)Buffer = (char *)LocalAlloc(LPTR,*Length);
}
else
{
//
// Unknown Failure.
//
// if (errdata != ERROR_INVALID_DATA)
// DisplayError(TEXT("GetDeviceRegistryProperty"));
return FALSE;
}
}
return ((char *)Buffer)[0];
}
#define UnknownDevice TEXT("<Unknown Device>")
BOOL ConstructDeviceName( HDEVINFO DeviceInfoSet,
PSP_DEVINFO_DATA DeviceInfoData,
PVOID Buffer,
PULONG Length)
{
if (!GetRegistryProperty(DeviceInfoSet,
DeviceInfoData,
SPDRP_FRIENDLYNAME ,
Buffer,
Length))
{
if (!GetRegistryProperty(DeviceInfoSet,
DeviceInfoData,
SPDRP_DEVICEDESC ,
Buffer,
Length))
{
if (!GetRegistryProperty(DeviceInfoSet,
DeviceInfoData,
SPDRP_CLASS ,
Buffer,
Length))
{
if (!GetRegistryProperty(DeviceInfoSet,
DeviceInfoData,
SPDRP_CLASSGUID ,
Buffer,
Length))
{
// *Length = (_tcslen(UnknownDevice)+1)*sizeof(TCHAR);
// *(LPTSTR *)Buffer = *(LPTSTR *)LocalAlloc(LPTR,*Length);
_tcscpy((char *)Buffer,UnknownDevice);
}
}
}
}
return TRUE;
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
char DevStr[10000];
ULONG DevStrMax;
char S[100];
DWORD i, Status, Problem;
TV_INSERTSTRUCT tvInsertStruc;
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};
if (INVALID_HANDLE_VALUE == (hDevInfo =
SetupDiGetClassDevs(NULL,NULL,Form1->Handle,
DIGCF_PRESENT|DIGCF_ALLCLASSES)))
{
MessageBox(NULL,"ERR","MSG",MB_OK);
}
for(i=65;i<110;i++)
{
SetupDiEnumDeviceInfo(hDevInfo,i,&DeviceInfoData);
if (CR_SUCCESS != CM_Get_DevNode_Status(&Status, &Problem,
DeviceInfoData.DevInst,0))
{
MessageBox(NULL,"ERR","MSG",MB_OK);
return;
}
if (!(ShowHidden || !((Status & DN_NO_SHOW_IN_DM) ||
IsClassHidden(&DeviceInfoData.ClassGuid))))
{
continue;
}
wsprintf(S,"%08lX %04X %04X %02X %02X %02X %02X %02X %02X %02X %02X"
,DeviceInfoData.ClassGuid.Data1
,DeviceInfoData.ClassGuid.Data2
,DeviceInfoData.ClassGuid.Data3
,DeviceInfoData.ClassGuid.Data4[0]
,DeviceInfoData.ClassGuid.Data4[0]
,DeviceInfoData.ClassGuid.Data4[0]
,DeviceInfoData.ClassGuid.Data4[0]
,DeviceInfoData.ClassGuid.Data4[0]
,DeviceInfoData.ClassGuid.Data4[0]
,DeviceInfoData.ClassGuid.Data4[0]
,DeviceInfoData.ClassGuid.Data4[0]
);
Memo1->Lines->Add(S);
ConstructDeviceName( hDevInfo,&DeviceInfoData,
// &tvInsertStruc.item.pszText,
// &tvInsertStruc.item.cchTextMax);
DevStr,
&DevStrMax);
wsprintf(S,"%lu : %s %lu",i,DevStr,DevStrMax);
Memo1->Lines->Add(S);
Label1->Caption=S;
}
}
|