MircoProgram MircoProgram - 9 months ago 68
C++ Question

c++ WINAPI call exported function via GetProcAddress

Im trying to call an exported function from a DLL by grabbing its function pointer through

but upon calling the function the application crashes.

I used dependencywalker to see if the exported functions have the correct name. The address returned from
is not null. I'm almost certain that it has something to do with the calling convention, i used both
but no success. However i do would like to use
instead of

DLL #1 (Caller)

  • Linked DLL#2.lib to this DLL

    typedef void(__stdcall *ptr_init)(DWORD size);

    ctx.hModule = LoadLibraryA("someDLL.dll");
    ptr_init init = (ptr_init)GetProcAddress(ctx.hModule, "init");

    if (init == NULL) {
    out = out + " | init function is null";
    } else {
    out = out + " | init function found!";//It is found

    DWORD test = 10;
    (*init)(test);//<-- makes application crash

DLL #2 (DLL containing exported function)

extern "C" __declspec(dllexport) void init(DWORD size);

extern "C" __declspec(dllexport) void init(DWORD size) {


You should be consistent. If you retrieve pointer as a pointer to stdcall function - it must be declared as stdcall in implementation:

extern "C" __declspec(dllexport) void __stdcall init(DWORD size);