c++ LoadLibrary and GetProcAddress from extern DLL


I´ve got an extern DLL to work with. I try to load the DLL with LoadLibrary and get the function by calling GetProcAddress but everytime I debug the programm I got an exception, which I can ignore by windows but in the end my main method throws the exception also and never ends in calling exceptions:

typedef int(__cdecl* GETRANDOMNUM)(unsigned char*);

int main(int argc, char *argv[])
    HMODULE hinstLib = LoadLibrary(TEXT("some.dll"));
    GETRANDOMNUM getrandomnum = (GETRANDOMNUM)GetProcAddress(hinstLib, "getrandomnum");
    int state = 0;
    if (ic_getrandomnum != NULL)
        unsigned char password[8] = { 0 };
        state = (getrandomnum)(password);
        return -1;

    return state;

The definition of "getrandomnum" is:

#ifdef EXPORT
#define IM_OR_EXPORT    extern "C" __declspec(dllexport)
#define IM_OR_EXPORT    extern "C" __declspec(dllimport)
#define CALLTYPE  __stdcall
IM_OR_EXPORT int CALLTYPE getrandomnum(unsigned char* randomnum);

The exceptions are:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.


Ausnahme ausgelöst bei 0x0044C828 in Cpp.exe: 0xC0000005: Zugriffsverletzung beim Ausführen an Position 0x0044C828.


Ausnahmefehler bei 0x00442F59 in Cpp.exe: Vom Stapelcookie-Instrumentationscode wurde ein stapelbasierter Pufferüberlauf erkannt.

This exception repeats for ever.

May someone help me?

asked on Stack Overflow Sep 24, 2020 by Max Mustermann

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0