【发布时间】:2019-07-10 00:33:20
【问题描述】:
我有一个函数名称为“Test123::MyFunction”的外部 DLL 文件,这里的问题是如果名称不包含“::”字符,我可以成功调用 DLL 名称,我如何传递完整的函数在 DLL 调用中命名“Test123::MyFunction”?
完整的源代码:
#include "pch.h"
#include <stdio.h>
#include <Windows.h>
#include <iostream>
int MyFunction(char* buf);
int main(int argc, char** argv)
{
/* get handle to dll */
HINSTANCE hGetProcIDDLL = LoadLibrary(L"CallMe.dll");
/* get pointer to the function in the dll*/
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hGetProcIDDLL), "MyFunction"); // Here the name MyFunction should be Test123::MyFunction
typedef int(__stdcall * pICFUNC)(char *);
pICFUNC MyFunction;
MyFunction = pICFUNC(lpfnGetProcessID);
/* The actual call to the function contained in the dll */
int intMyReturnVal = MyFunction(argv[1]);
/* Release the Dll */
FreeLibrary(hGetProcIDDLL);
return intMyReturnVal;
/* The return val from the dll */
}
谢谢
【问题讨论】:
-
GetProcAddress-- 就其预期而言,这是一个非常简单的函数。您使用的名称必须与导出的名称完全匹配。这包括大小写和特殊字符。显然,您误认为正确的导出名称。使用 Dependency Walker 或 dumpbin 等工具获取确切名称。
标签: c++ string windows visual-studio dll