没有找到函数使用GetProcAddress() c++ VBexpress

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

本文关键字:GetProcAddress c++ VBexpress 函数      更新时间:2023-10-16

好吧,所以我在这里危险地接近于转发,但我的情况与许多其他关于这个函数的海报有点不同。我与一个DLL的接口是写在一天的方式,我所拥有的是文件。我没有。lib文件,所以我使用LoadLibrary和GetProcessAddress函数。我按照MSDN网站上的教程获得了基本结构。DLL位于项目文件夹中。它编译。在运行时,我得到了"hinstLib"的数值,所以我假设找到了DLL。我得到一个空值"ProcAdd"变量。其他海报通过在DLL函数中放入外部C来解决问题,但我真的没有那个选项。更不用说,据我所知,这个DLL是用纯c编写的。我确实有一个接口文档,我很确定我的函数名是正确的(为了这些目的,用一个通用的例子代替)。老实说,我没有运行任何超过ProcAdd赋值,因为它出来NULL。任何关于为什么这给我一个0值的函数分配的想法将是非常感激的。注:不幸的是,由于各种原因,我不能上传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 functionn"); 
    }
    // Free the DLL module.
    fFreeResult = FreeLibrary(hinstLib); 
} 
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess) 
    printf("Message printed from executablen"); 
return 0;

}

编译器通常会混淆函数名,那么一个名为funcName的函数可能会以funcName@16的名称出现在DLL中,例如…它取决于调用约定,对于正确调用函数非常重要。对于__cdecl调用约定,您可能需要_funcName:-)。