0

我被分配了以 DLL 的形式围绕现有 C++ 代码库编写包装器的工作。我遇到的问题是 DLL 导出名称被破坏了。当我将它们传递给 GetProcAddress 时,我可以/应该简单地使用损坏的名称吗?还是有更好的方法来做事?

编辑:我没有提到。我无权访问代码,以允许我以任何方式修改 dll。

EDIT2:事实证明我确实可以访问此 DLL 的代码(.h 和 .cpp),但我无法修改所述代码。

4

2 回答 2

0

对于我提出的具体问题,我最终确定的解决方案是以下功能。它在我的情况下有效,因为出口名称只是略微受到破坏。

static FARPROC getFunctionPointer(HINSTANCE dll, const char *baseName)
{
    char buf[256];
    FARPROC fp;
    sprintf(buf,"%s",baseName);
    fp = GetProcAddress(dll,buf);
    if (fp == 0)
    {
      sprintf(buf,"_%s",baseName);
      fp = GetProcAddress(dll,buf);
    }
    if (fp == 0)
    {
      sprintf(buf,"_%s@4",baseName);
      fp = GetProcAddress(dll,buf);
    }
    if (fp == 0)
    {
      sprintf(buf,"_%s@8",baseName);
      fp = GetProcAddress(dll,buf);
    }
    if (fp == 0)
    {
      sprintf(buf,"_%s@0",baseName);
      fp = GetProcAddress(dll,buf);
    }

    if (fp == 0)
    {
        printf("ERROR: Could not locate function: %s \n", baseName);
    }
    return fp;
}
于 2013-09-05T15:39:05.643 回答
0

因为你有源代码(不可修改)。

使用 DLL 源代码文件创建项目。创建 wrapper.cpp/wrapper.h 与

// 包装器.h

#ifndef WRAPPER_H
#define WRAPPER_H

extern "C" {

    void wrapper_function1();
    // and so on
}
#endif

// 包装器.cpp

#include "wrapper.h"
#include "dll.h"

extern "C" {
    void wrapper_function1() { /* code which may call functions from dll.h */ }
    // And so on
}

因此,您的新 DLL 没有名称修饰。

于 2013-09-04T09:59:02.940 回答