Open
Description
加载动态库 (loadlibrary)
[toc]
加载
> using的用法参考 使用using起别名
#include <iostream>
#include <windows.h>
#include "PipeIPC/PipeIPC.h"
int main()
{
std::cout << "--- DLL Test ---\n";
HINSTANCE hDLL; // Handle to DLL
using Face = int * (*)(int,int);
hDLL = LoadLibrary(L"mydll.dll");
if (hDLL != NULL)
{
Face faceSum = (Face)GetProcAddress(hDLL,
"mySum");
if (!faceSum)
{
// handle the error
FreeLibrary(hDLL);
return 0;
}
else
{
// call the function
faceSum(1,1);
}
}
return 0;
}
生成动态库
dllmain.cpp
#ifdef __cplusplus
extern "C"
{
#endif
#define MYIMAPI extern "C" __declspec(dllimport)
#define MYEXAPI extern "C" __declspec(dllexport)
#ifdef __cplusplus
}
#endif
MYEXAPI int Add(int numa, int numb)
{
return numa + numb;
}
MYEXAPI int Sub(int numa, int numb)
{
return (numa - numb);
}
blog link 加载动态库 (loadlibrary)