使用GetProcAddress()C ++ VBexpress未找到函数13 [英] Not finding function using GetProcAddress() C++ VBexpress 13

查看:100
本文介绍了使用GetProcAddress()C ++ VBexpress未找到函数13的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我很危险地接近此处的转发,但我的情况与有关此功能的许多其他发布者有所不同。我正在与一个DLL进行交互,该DLL可以追溯到以前,当时我所拥有的只是文件。我没有.lib文件,所以我正在使用LoadLibrary和GetProcessAddress函数。我遵循了MSDN网站上的教程以获取基本结构。 DLL位于项目文件夹中。它编译。在运行时,我获得了 hinstLib的数值,因此我假设找到了DLL。我正在为 ProcAdd变量获取空值。其他发布者通过将extern C放在DLL函数中解决了问题,但我实际上没有这个选择。更不用说,据我所知,这个DLL是用纯C语言编写的。我确实有一个接口文档,并且非常确定我具有正确的函数名(为此目的用一个通用示例替换了)。老实说,我没有执行任何超出ProcAdd分配的操作,因为它的输出为NULL。对于为什么这给我一个0的函数赋值的任何想法,将不胜感激。注意:由于各种原因,我无法上传DLL。

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;

}

推荐答案

编译器通常会破坏函数名称,然后名为 funcName 的函数可能会出现在DLL内且名称为 funcName @ 16 ,例如...它取决于调用约定,对于正确调用函数很重要。对于 __ cdecl 调用约定,您可能需要 _funcName :-)。

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 :-) .

这篇关于使用GetProcAddress()C ++ VBexpress未找到函数13的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆