- 关键在于声明函数时 .h 文件中,需要将要导出的函数名进行以下操作(process_image 函数名)
#ifdef __cplusplusextern "C" {#endif__declspec(dllexport) double process_image(char* img_path);#ifdef __cplusplus}#endif
- 在定义声明函数的实现(cpp文件实现代码)
- 生成式选择生成dll

- 调用时需要特定代码调用函数名(以下代码是process_image函数的例子)
#include <windows.h>
#include <iostream>
typedef double (*ProcessImageFunc)(char*);
int main() {HMODULE hDll = LoadLibraryA("sperm.dll");if (!hDll) {std::cerr << "Failed to load DLL" << std::endl;return -1;}ProcessImageFunc process_image = (ProcessImageFunc)GetProcAddress(hDll, "process_image");if (!process_image) {std::cerr << "Failed to get process_image address" << std::endl;FreeLibrary(hDll);return -1;}char img_path[] = "frame_01_5000.jpg";double score = process_image(img_path);std::cout << "Tenengrad Score: " << score << std::endl;FreeLibrary(hDll);return 0;
}