SetupAPI - SetupDiGetDeviceRegistryProperty替代?

时间:2016-05-24 14:28:05

标签: winapi setupapi

我需要在firefox扩展中使用一些SetupAPI函数。我需要检索设备的友好名称。我认为可以通过SetupDiGetClassDevsSetupDiEnumDeviceInfoSetupDiGetDeviceRegistryPropertySetupDiDestroyDeviceInfoList来完成。

BUT!我导入了setupapi.dll并声明了三个函数 - 没问题。然后我发现SetupDiGetDeviceRegistryProperty根本就不在DLL中,只能与setupapi.lib静态链接。有什么方法可以替代这个功能吗?

我无法使用WMI。

2 个答案:

答案 0 :(得分:1)

你是对的,没有具有该确切名称的导出。该名称实际上是在SetupApi标头中定义的,就像Windows API中具有Unicode&的大多数功能一样。 ANSI变体。

来自SetupApi.h:

#ifdef UNICODE
#define SetupDiGetDeviceRegistryProperty SetupDiGetDeviceRegistryPropertyW
#else
#define SetupDiGetDeviceRegistryProperty SetupDiGetDeviceRegistryPropertyA
#endif

该函数在导出表中作为SetupDiGetDeviceRegistryPropertyW(ordinal:373)或SetupDiGetDeviceRegistryPropertyA(ordinal:372)

我找到了使用dumpbin /exports setupapi.dll的人。

答案 1 :(得分:1)

这个功能确实在SetupAPI.DLL中,因为我已经使用Dependency Walker进行了确认。它就是这样,它需要一个字符指针(字符串),它必须有两个变体 - 一个用于ANSI(A),一个用于Unicode(W)。

  • SetupDiGetDeviceRegistryPropertyA
  • SetupDiGetDeviceRegistryPropertyW

使用任何Windows API函数 - 如果函数将一个或多个字符串作为参数,它将有两个变体。

我发现你可能正在使用GetProcAddress找到它。因此,您需要将真实姓名(而不是宏)传递给它。以下是此功能的广泛变体。

GetProcAddress(handleOfDLL, "SetupDiGetDeviceRegistryPropertyW"); // Wide