函数名称与序数值 - 从DLL模块获取函数地址

时间:2021-11-19 23:17:56

I have a DLL (WinDll.dll) that exports a function called 'SampleFunction'. The DLL is in the same folder as that of the executing application. Now when I try getting the address of the exported function by name, it gives error 127, however, when I do the same using the ordinal value of the function, it works all fine. Any ideas how and why this might be happening?? Following is the code which loads and tries to make use of the exported function. Also I have attached a clip from IDA Proo that shows the exported functions from WindDll.dll.

我有一个DLL(WinDll.dll)导出一个名为'SampleFunction'的函数。 DLL与正在执行的应用程序位于同一文件夹中。现在,当我尝试按名称获取导出函数的地址时,它会给出错误127,但是,当我使用函数的序数值执行相同操作时,它可以正常工作。任何想法如何以及为什么会发生这种情况?以下是加载并尝试使用导出函数的代码。我还附上了IDA Proo的一个剪辑,它显示了WindDll.dll的导出函数。

#include <windows.h>
#include <stdio.h>

typedef int (WINAPI *ProcP)(HINSTANCE, HINSTANCE, LPSTR, int);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    HINSTANCE hinstlib;
    LPSTR lpBuffer = (LPSTR)malloc(256*2);
    GetCurrentDirectory(256,lpBuffer);
    ProcP procAddress = NULL;

    strcat(lpBuffer,"\\WinDll.dll");
    hinstlib = LoadLibrary(TEXT(lpBuffer));

    if(hinstlib == NULL){
        MessageBox(NULL,lpBuffer, "Bull", MB_OK);
        exit(0);
    }
    else{
        procAddress = (ProcP)GetProcAddress(hinstlib,"SampleFunction");    // <-- Problem
        if(procAddress != NULL){
            PostMessage(NULL, WM_RBUTTONDOWN, MK_RBUTTON, 0);   
        }
        else{
            MessageBox(NULL, "Invalid ProcAddress", "Bull", MB_OK); 
        }
    }

    return 0;
}

函数名称与序数值 - 从DLL模块获取函数地址函数名称与序数值 - 从DLL模块获取函数地址

1 个解决方案

#1


3  

The SampleFunction seems to be declared with the _stdcall calling convention. So the name of the function you must pass to GetProcAddress is "_SampleFunction@16" as showed by the dumpbin command.

SampleFunction似乎是使用_stdcall调用约定声明的。因此,必须传递给GetProcAddress的函数的名称是“_SampleFunction @ 16”,如dumpbin命令所示。

For more details about calling convention search for _stdcall, _cdecl and Calling convetion.

有关调用常规搜索_stdcall,_cdecl和Calling convetion的更多详细信息。

#1


3  

The SampleFunction seems to be declared with the _stdcall calling convention. So the name of the function you must pass to GetProcAddress is "_SampleFunction@16" as showed by the dumpbin command.

SampleFunction似乎是使用_stdcall调用约定声明的。因此,必须传递给GetProcAddress的函数的名称是“_SampleFunction @ 16”,如dumpbin命令所示。

For more details about calling convention search for _stdcall, _cdecl and Calling convetion.

有关调用常规搜索_stdcall,_cdecl和Calling convetion的更多详细信息。