fork download
  1. /*
  2.  * 這是 DLL 裡面的 Function
  3.  */
  4.  
  5. __declspec(dllexport) int __cdecl add(int a, int b)
  6. {
  7. return a + b;
  8. }
  9.  
  10.  
  11. /*
  12.  * DLL的客戶端程式
  13.  */
  14.  
  15. #include <Windows.h>
  16.  
  17. typedef int (__cdecl *BinaryOp)(int op1, int op2);
  18.  
  19. int _tmain(int argc, _TCHAR* argv[])
  20. {
  21. BinaryOp bop;
  22.  
  23. HMODULE lib = LoadLibrary(_T("D:\\VC_Projects\\DllTest\\Debug\\DllTest.dll"));
  24. if (lib != NULL)
  25. {
  26. // 下面這個詭異的名稱是用 Dependency Walker 看到的
  27. bop = (BinaryOp)GetProcAddress(lib, "?add@@YAHHH@Z");
  28. if (bop != 0)
  29. {
  30. printf("add(5, 9) = %d\n", bop(5, 9));
  31. }
  32. }
  33.  
  34. return 0;
  35. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty