我正在尝试动态加载dll。找到了dll,但是当我试图找到该功能时,它就无法工作了。
Main.cpp的
#include <iostream>
#include "windows.h"
typedef void (__stdcall *f_funci)();
int main(){
HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\users\\MyWin.dll");
if (!hGetProcIDDLL) {
std::cout << "could not load the dynamic library" << std::endl;
return 0;
}else{
std::cout << "Found the dll" << std::endl;
}
f_funci funci = (f_funci)GetProcAddress(hGetProcIDDLL, "printSomething");
if (!funci) {
std::cout << "could not locate the function" << std::endl;
}
return 0;
}
和dll的文件:
MyWin.h
#define TEST
#ifndef TEST
#define MAKRO __declspec(dllexport) __stdcall
MAKRO void printSomething();
#endif
MyWin.cpp
#include "MyWin.h"
#include <iostream>
void printSomething(){
std::cout<<"Call the function dynamically"<<std::endl;
}
以下列方式编译dll:
g++ MyWin.h MyWin.cpp -shared -o MyWin.dll
非常感谢任何帮助