Jedi:需要GUID_DEVINTERFACE_IMAGE的值:TGUID

时间:2015-01-04 13:58:14

标签: delphi

早上好,

我想抓住计算机中的网络摄像头总数,并将C ++中的源代码(code is here))转换为Delphi,如下所示:

 const
      MAX_PATH = 260;
      CR_SUCCESS =$00000000;
    type
      HDevInfo  = Pointer; { a pointer to a HID device info structure }
      THDEVINFO = Pointer;
      PSP_DevInfo_Data = ^TSP_DevInfo_Data;
      SP_DEVINFO_DATA = packed record
        cbSize: DWORD;
        ClassGuid: TGUID;
        DevInst: DWORD;
        Reserved: LongWord;
      end;
      TSP_DevInfo_Data = SP_DEVINFO_DATA;
      PDEVPROPKEY = ^TDEVPROPKEY;
      DEVPROPKEY = packed record
        fmtid : TGUID ;
        pid : Pointer;
      end;
      TDEVPROPKEY = DEVPROPKEY;
      DEVPROPTYPE = Pointer;
      PCWSTR = PWCHAR;
      TDEVINST = DWord;
      TPOSVERSIONINFOW = ^TOSVERSIONINFOW;
      TOSVERSIONINFOW = packed record
        dwOSVersionInfoSize : DWORD ;
        dwMajorVersion : DWORD ;
        dwMinorVersion : DWORD ;
        dwBuildNumber : DWORD ;
        dwPlatformId : DWORD ;
        szCSDVersion : array[0..127] of wchar;
      end;
    function SetupDiGetDeviceProperty(DeviceInfoSet: THDEVINFO; DeviceInfoData: PSP_DEVINFO_DATA; const PropertyKey: PDEVPROPKEY; var PropertyType:DEVPROPTYPE; PropertyBuffer:PBYTE;PropertyBufferSize:DWORD; RequiredSize:PDWORD; Flags:DWORD): BOOL; stdcall; external 'Setupapi.DLL' name 'SetupDiGetDevicePropertyW';
    function SetupDiGetClassDevsW(const ClassGuid: PGUID; Enumerator: PCWSTR; hwndParent: HWND; Flags: DWORD): THDEVINFO; stdcall; external 'Setupapi.DLL' name 'SetupDiGetClassDevsW';
    function SetupDiGetClassDevsA(ClassGuid: PGUID; const Enumerator: PAnsiChar;
hwndParent: HWND; Flags: DWORD): THandle; stdcall; external 'SetupApi.dll';
    function SetupDiEnumDeviceInfo(DeviceInfoSet: THDEVINFO; MemberIndex: DWORD; DeviceInfoData: PSP_DEVINFO_DATA): BOOL; stdcall; external 'Setupapi.DLL' name 'SetupDiEnumDeviceInfo';
    function CM_Get_Device_IDW(DeviceInstanceHandle: TDEVINst; Buffer:PCWSTR; Bufferlen : ULONG; ulFlags:ULONG): DWORD; stdcall; external 'Setupapi.DLL' name 'CM_Get_Device_IDW';
    function SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet: THDEVINFO; const DeviceInfoData: SP_DevInfo_Data; Property_: DWORD; var PropertyRegDataType: DWORD; PropertyBuffer: PBYTE; PropertyBufferSize: DWORD; var RequiredSize: DWORD): BOOL; stdcall; external 'Setupapi.DLL' name 'SetupDiGetDeviceRegistryPropertyW';
    function GetVersionExW(OsVersion:TPOSVERSIONINFOW): BOOL; stdcall; external 'Kernel32.dll' name 'GetVersionExW';

    const
            DIGCF_PRESENT = $00000002;
            DIGCF_ALLCLASSES = $00000004;
            DIGCF_PROFILE = $00000008;
            DIGCF_DEVICEINTERFACE = $00000010;
            INVALID_HANDLE_VALUE = DWORD($FFFFFFFF);
            MAX_DEVICE_ID_LEN = 200;
            SPDRP_DEVICEDESC = ($00000000) ;
            DEVPKEY_Device_BusReportedDeviceDesc : TDEVPROPKEY = (fmtid : '{540b947e-8b40-45bc-a8a2-6a0b894cbda2}' ; pid : pointer(4) );

implementation

        function GetNumCam: integer;
        var
        MemberIndex: integer;
        dev: HDEVINFO;
        DeviceInfoData: SP_DEVINFO_DATA;
        begin
        DeviceInfoData.cbSize := sizeof(DeviceInfoData);
        dev := SetupDiGetClassDevsA(@GUID_DEVINTERFACE_IMAGE, nil, nil, DIGCF_PRESENT);
         if dev = nil then  begin
         //raise exception.Create('Nenhum dispositivo encontrado');
         exit;
         end
         else
           while SetupDiEnumDeviceInfo(dev,MemberIndex, @DeviceInfoData) do
           begin
            MemberIndex:= MemberIndex + 1;
           end;
        Result:= MemberIndex;
        end;

但是我很难在Delphi中找到GUID_DEVINTERFACE_IMAGE的值,并在为此常量赋值之后。我在(this unit)中看到了,但是没有这个常数,因为我抓住了价值。

有人知道这个常数的确切值吗?

提前感谢。

1 个答案:

答案 0 :(得分:3)

可以在documentation

中找到该值
  

{0x6bdd1fc6L,0x810f,0x11d0,0xbe,0xc7,0x08,   0x00,0x2b,0xe2,0x09,0x2f}

在Delphi中你声明它是这样的:

const
  GUID_DEVINTERFACE_IMAGE: TGUID = (
    D1:$6bdd1fc6; D2:$810f; D3:$11d0; D4:($be, $c7, $08, $00, $2b, $e2, $09, $2f)
  );

或者像这样:

const
  GUID_DEVINTERFACE_IMAGE: TGUID = '{6bdd1fc6-810f-11d0-bec7-08002be2092f}';
相关问题