동적으로 C++ dll을로드하려고했는데, 먼저 "LoadLibrary"함수를 사용하여 dll을로드 했으므로 올바르게 처리됩니다. 그런 다음 "GetProcAddress"를 사용하여 DLL 함수의 함수 포인터를 얻으려고 시도했지만 NULL을 반환합니다. 내 DLL 코드와 응용 프로그램 코드를 찾고 코드에서 어디서 잘못되었는지 알려주십시오.NULL을 반환하는 GetProcAddress 함수
dummy2.h
namespace newer
{
class dllclass
{
public:
static __declspec(dllexport) int run(int a,int b);
};
}
dummy2.cpp
#include <iostream>
using namespace std;
#include "dummy2.h"
namespace newer
{
int dllclass::run(int a,int b)
{
return a+b;
}
}
dummy1.cpp
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
typedef int (*Addition)(int,int);
int _tmain(int argc, _TCHAR* argv[])
{
Addition add;
HINSTANCE hDLL;
hDLL = LoadLibrary(TEXT("Dummy2.dll"));
add = (Addition)GetProcAddress(hDLL, "run");
getchar();
return 0;
}
위의 코드를 참조하여 나를 인도 해주십시오.
당신은 아마'GetProcAddress를 (hDLL, "dllclass :: 실행")가 필요합니다; '또는'GetProcAddress (hDLL, "newer :: dllclass :: run");'? –
GetProcAddress는 대/소문자와 특수 문자, 하이픈, 물음표, @ 기호 등 내 보낸 ** 정확한 ** 이름을 알아야합니다. 따라서 "실행"은 다음과 같은 "실행"과 다릅니다. "@ 4"를 실행하십시오. Dependency Walker 또는 * exact * 이름이 무엇인지보기위한 다른 도구와 같은 DLL에 DLL을로드해야하며, GetProcAddress에서 사용해야하는 이름입니다. – PaulMcKenzie
실제로는 "__imp_? run @ dllclass @ [email protected]@ SAHHH @ Z"와 같은 것입니다. – axalis