gpt4 book ai didi

dll - GetProcAddress 返回 NULL

转载 作者:行者123 更新时间:2023-12-01 05:11:45 28 4
gpt4 key购买 nike

我正在尝试使用 LoadLibrary 和 GetProcAddress 加载 dll。 LoadLibrary 返回一个有效的句柄,但我对 GetProcAddress 的调用返回 NULL。调用 GetLastError 返回 87,即 ERROR_INVALID_PARAMETER。我验证了我传递给 GetProcAddress 的函数名称与运行时返回的相同 dumpbin /exports在 dll 上。不幸的是,这是为了工作,所以我不能包含实际的代码。但这里有一个经过编辑的版本,可以让您了解我在做什么。

HINSTANCE hDLL = NULL;

hDLL = LoadLibrary(L"<PATH TO DLL>");

if (hDLL == NULL)
{
// error handling code
}

g_var1 = (VAR1_TYPE) GetProcAddress(hDLL, L"Function1Name");
g_var2 = (VAR2_TYPE) GetProcAddress(hDLL, L"Function2Name");

if (!g_var1 ||
!g_var2 )
{
// error handling code
}

我在 SO 和其他论坛上查看了许多相关问题,但通常问题是由于 C++ 名称修改造成的。由于我使用的名称与 dumpbin 相同显示我不认为这是我的问题。有任何想法吗?

更新

我想我可能已经缩小了问题的范围。目标上存在此 dll 的旧版本(这是一个嵌入式 WinCE 解决方案)。但是我需要使用具有一些我需要的额外功能的较新版本的 dll;不幸的是,我无法更新旧的 dll。这个新的 dll 和使用该 dll 的应用程序被打包到一个加载到目标上的 cab 文件中。我用旧 dll 中的几个函数尝试了 GetProcAddress 并且这些函数有效。因此,即使我使用新 dll 的路径调用 LoadLibrary,它似乎也只是加载目标上已经存在的 dll。任何人都可以确认这是会发生的事情吗?

回答上一个问题

When Windows CE loads a DLL, all path information is ignored when determining if the DLL is already loaded. This means that a DLL with the same name but a different path can only be loaded once. In addition, a module ending with the extension .cpl is treated as if the extension is .dll.



来源: http://msdn.microsoft.com/en-us/library/ms886736.aspx

最佳答案

是的,这是一个常见的陷阱。如果您没有提供 DLL 的完整路径,LoadLibrary 将返回一个已加载的同名 DLL 的句柄。

来自 MSDN :

If lpFileName does not include a path and there is more than one loaded module with the same base name and extension, the function returns a handle to the module that was loaded first.



我相信您可以通过提供 LoadLibrary 的绝对路径来获得您想要的确切 DLL。

关于dll - GetProcAddress 返回 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24289101/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com