jrfonseca / drmingw

Postmortem debugging tools for MinGW.
GNU Lesser General Public License v2.1
279 stars 56 forks source link

better sample code in the home page #87

Closed asmwarrior closed 9 months ago

asmwarrior commented 10 months ago
LoadLibrary("exchndl.dll");
pfnExcHndlInit = GetProcAddress("ExcHndlInit");
pfnExcHndlInit()

Hi, this code in the project home page is simple, but I think it can't be compiled. This is what I used for my project:

    // Load the DLL
    HMODULE hModule = LoadLibrary(L"exchndl.dll");

    if(hModule != NULL)
    {
        // Get the function pointer
        FARPROC pfnExcHndlInit = GetProcAddress(hModule, "ExcHndlInit");

        if(pfnExcHndlInit != NULL)
        {
            // Declare the function pointer type
            typedef void (*ExcHndlInitFunc)();

            // Cast the function pointer
            ExcHndlInitFunc pfnInit = reinterpret_cast<ExcHndlInitFunc>(pfnExcHndlInit);

            // Call the function
            pfnInit();
        }
        else
        {
            // Handle the error if GetProcAddress fails
            // Add your error handling code here
        }

        // Free the DLL module, actually we do not free the dll, so we can got the call stack RPT(report file)
        // FreeLibrary(hModule);
    }
    else
    {
        // Handle the error if LoadLibrary fails
        // Add your error handling code here
    }

Hope that helps.

jrfonseca commented 9 months ago

I've slightly compacted your sample code and committed. Thanks.