dll – GetProcAddress返回NULL

前端之家收集整理的这篇文章主要介绍了dll – GetProcAddress返回NULL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用LoadLibrary和GetProcAddress加载一个DLL. LoadLibrary返回一个有效的句柄,但我对GetProcAddress的调用返回NULL.对GetLastError的调用返回87,即ERROR_INVALID_PARAMETER.我验证了我传递给GetProcAddress的函数名与在dll上运行dumpbin / exports时返回的函数名相同.不幸的是,这是为了工作,所以我不能包括实际的代码.但这是一个编辑版本,让您了解我在做什么.

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显示名称相同的名称,所以我不认为这是我的问题.有任何想法吗?

UPDATE

我想我可能已经缩小了这个问题.目标上存在此dll的旧版本(这是一个嵌入式WinCE解决方案).但我需要使用更新版本的dll,它具有我需要的一些额外功能; unfortuanatley我无法更新旧的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.

猜你在找的Windows相关文章