且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用C ++编程的USB编程

更新时间:1970-01-01 07:58:18

1。只要你直接加载它就应该完全指定函数 GetProcAddress(hSetUpApi,SetupDiGetClassDevsW); for unicode as function SetupDiGetClassDevs 在setup api dll中不存在。除此之外,你应该将unicode结构声明传递给函数(最后用W)。



2.你的函数类型声明不正确:

1. you should specify function fully as long you are loading them directly GetProcAddress(hSetUpApi, "SetupDiGetClassDevsW"); for unicode as function "SetupDiGetClassDevs" does not exists in setup api dll. Along with it you should passing unicode structure declaration into functions (with "W" at the end).

2. Your function type declarations are not correct:
// Example
typedef HDEVINFO (WINAPI * FNSetupDiGetClassDevsW)(CONST GUID *ClassGuid,PCWSTR Enumerator,HWND hwndParent,DWORD Flags);
// Initializing
FNSetupDiGetClassDevsW pfn = (FNSetupDiGetClassDevsW)GetProcAddress(hSetUpApi, "SetupDiGetClassDevsW");



问候,

Maxim。


Regards,
Maxim.


这里有一大堆问题,主要的一点是你不需要做大部分工作。例如,使用 SetupDiGetClassDevs 只需 #include< setupapi.h> < /setupapi.h> 并链接到 Setupapi.lib 。你会发现 SetupDiGetClassDevs 然后是全局命名空间中的普通函数,你可以使用它。

这将解决你的大多数问题,但可能不是全部。您需要检查返回的句柄,以确保实际找到并加载DLL。您还可以使用 Dependency walker [ ^ ]检查dll本身,看看他们确实输出了什么名称。

如果你还有问题,请回来更新问题或发布另一个问题,因为它用更少的东西来查看错误会更容易。
There are a raft of problem here, the main one is that you don''t need to do most of this. For example to use SetupDiGetClassDevs just #include <setupapi.h> </setupapi.h> and link to Setupapi.lib. You will find SetupDiGetClassDevs is then an ordinary function in the global namespace and you can just use it.
This will solve most of your issues but probably not all. You need to check the returned handles to ensure that the DLLs are actually being found and loaded. You can also use Dependency walker[^] to examine the dlls themselves to see exactly what names they do export.
If you still have issues come back and update the questions or post another as it will be much easier to spot whats wrong with less to look at.


当使用 GetProcAddress()时,你必须指定的函数名称是存在于DLL中。当DLL支持Unicode和多字节时,存在字符或字符串参数时有两个函数。然后将字母A或W附加到函数名称中。因此,当使用多字节构建时,使用''A''(ANSI)终止名称:

When using GetProcAddress() you must specify function names that are present in the DLL. When a DLL supports Unicode and multi byte, there are two functions when character or string parameters are present. Then the letters ''A'' or ''W'' are appended to the function names. So when using multi byte builds, use the ''A'' (ANSI) terminated names:
_SetupDiGetClassDevsUMPTR = (SetupDiGetClassDevsUMPTR)GetProcAddress(hSetUpApi, "SetupDiGetClassDevsA"); 



当有ANSI和宽版本时,以相同的方式更改所有其他功能的代码。对于不使用 SetupDiEnumDeviceInfo 等字符串的函数,只有一个版本。


Change your code for all other functions in the same way when there are ANSI and wide versions. With functions that did not use strings like SetupDiEnumDeviceInfo, there is only one version.