Not finding function using GetProcAddress() C++ VBexpress 13

邮差的信 提交于 2020-01-16 00:36:08

问题


Okay so I'm coming dangerously close to a repost here but my situation is a little bit different than the numerous other posters about this function. I am interfacing with a DLL that was written way back in the day and all I have is the file. I don't have a .lib file so I'm using the LoadLibrary and GetProcessAddress functions. I followed the tutorial on the MSDN website to get the basic structure. the DLL is located in the project folder. it compiles. at run time, I am getting a numerical value for "hinstLib" so I'm assuming the DLL was found. I am getting a null value for "ProcAdd" variable. Other posters had there issues resolved by putting extern C in the DLL functions but I don't really have that option. not to mention, to my knowledge this DLL was written in plain C. I do have an interface document and am quite sure I have the function name correct (replaced with a generic example for these purposes). I honestly didn't run anything past the ProcAdd assignment because it came out NULL. Any thoughts as to why this is giving me a 0 value for the function assignment would be great appreciated. Note: unfortunately due to various reasons I can't upload the DLL.

    #include <iostream>
    #include "stdafx.h"
    #include "Windows.h"
    #include <stdio.h> 

    typedef int(__cdecl *MYPROC)(LPWSTR);

    using namespace std;

    int main()
    {
      HINSTANCE hinstLib;
      MYPROC ProcAdd;
      BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;

      hinstLib = LoadLibrary(TEXT("dllName.dll"));
      if (hinstLib != NULL) 
    { 
    ProcAdd = (MYPROC) GetProcAddress(hinstLib, "funcName"); 

    // If the function address is valid, call the function.

    if (NULL != ProcAdd) 
    {
        fRunTimeLinkSuccess = TRUE;
        //(ProcAdd) (L"Message sent to the DLL function\n"); 
    }
    // Free the DLL module.

    fFreeResult = FreeLibrary(hinstLib); 
} 

// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess) 
    printf("Message printed from executable\n"); 

return 0;

}


回答1:


Compilers usually mangle function names, then a function named funcName may appear inside the DLL with a name funcName@16 , for example... It depends on calling convention and are important for a function to be called properly. For __cdecl calling convention you probably need _funcName :-) .



来源:https://stackoverflow.com/questions/23791995/not-finding-function-using-getprocaddress-c-vbexpress-13

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!