【发布时间】:2025-12-01 07:05:01
【问题描述】:
我正在尝试使用 WinAPI 函数GUIDFromString(),但它需要一些技巧才能将其包含在我的项目中。
根据msdn 文档:
此函数未在标头中声明或按名称从 .dll 文件。它必须从 Shell32.dll 作为序号 703 加载 GUIDFromStringA 和 GUIDFromStringW 的序号 704。
它也可以从 Shlwapi.dll 作为序数 269 访问 GUIDFromStringA 和 GUIDFromStringW 的序号 270。
我以前从未加载过 DLL,所以我不确定我应该做什么,我不确定加载 DLL 是否足够,我是否还必须包含一个编号为 703 的“序数”?任何人都可以就我需要做什么来使用这个功能甚至是一个例子提供任何建议吗?
我在下面的尝试不起作用(我使用的是 VC++ 2010 Express):
#pragma comment(lib, "shell32.lib") // if I am including the dll do I need to include the lib aswell?
// I've heard that the dll location differs across versions of windows
// Does anyone know of a Cross-Windows-Version way to include Shell32.dll no matter where it is? Maybe use a keyword like "%SYSTEM%/Shell32.dll"
HINSTANCE shell32DLL = LoadLibary("C:/System/Shell32.dll");
// Now do I include 'Ordinal 703' as described in msdn? And how do I do that?
【问题讨论】:
-
我没有用序数代替名字做任何类似的事情,但我猜你在
GetProcAddress中指定"703"作为名字。 -
你也可以使用
UuidFromString按名称导出的函数(msdn.microsoft.com/en-us/library/windows/desktop/…) -
@chris:使用
MAKEINTRESOURCE()将序数传递给GetProcAddress()。 -
@RemyLebeau,哦,我明白了。有一天知道这一点会很高兴,谢谢。
-
很好奇,您是否事先知道 GUID(这是您在运行时发现的字符串?) - 如果是这样,您可以跳过字符串解析并在编译时将其声明为
GUID myGuid = { 0x00000000, 0x0000, 0x0000, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }或类似。