template & lt; typename T> 使用__declspec (dllexport), void MySwap (T&,其中obj1,, T&, methoda) { T tmp =,其中obj1; 时间=obj1 methoda; obj2 =, tml; }
# pragma ,评论(自由,,“12 _18_dll01”) 使用__declspec (dllimport), int 添加(int ,, int b); int main () { int ret =,添加(1,2); std:: cout & lt; & lt;, ret & lt; & lt;, std:: endl; return 0; }
使用__declspec (dllimport), int 添加(int ,, int b);
class 使用__declspec (dllimport) MyClass {};
# pragma 评论(自由,,“MyLib.lib”) int MyAdd (int ,, int b),,,,,//通常发布会把把声明放到头文件中,一并发布
# include & lt; winsock2.h> # include & lt; windows.h>
extern “C”,使用__declspec (dllexprot), int MyAdd (int ,, int b);
# include & lt; iostream> # include & lt; winsock2.h> # include & lt; windows.h> int main () { 时间=wchar_t *, Path L“12 _18_dll01.dll”; HINSTANCE , handle =, LoadLibrary(路径);//,字符集兼容问题 if (处理) {//,定义要找的函数原型 int (* DLL_FUNCTION_ADD) typedef (int, int);//,找到目标函数的地址注意实现必须用,extern “C”,的方式编译 DLL_FUNCTION_ADD dll_func =, (DLL_FUNCTION_ADD) GetProcAddress(,句柄,“添加”); if (dll_func) {//,调用该函数 int result =, dll_func (1, 2); std:: cout & lt; & lt;, result & lt; & lt;, std:: endl; } } FreeLibrary(处理); return 0; }