= = 依然是demo
声明文件:
- //////////////////////////////////////////////////////////////////////////
- // CopyRight(c) 2009, YOYO, All Rights Reserved.
- // Author: LIN YiQian
- // Created: 2009/09/15
- // Describe: 动态库显式链接 声明
- //////////////////////////////////////////////////////////////////////////
- #ifndef _DLL_SHOW_CALCULATE_H_
- #define _DLL_SHOW_CALCULATE_H_
- #ifdef CALCULATE_EXPORTS
- #define CALCULATE_API __declspec(dllexport)
- #else
- #define CALCULATE_API __declspec(dllimport)
- #endif
- extern "C" CALCULATE_API int Add(int nNum1, int nNum2);
- extern "C" CALCULATE_API int Minus(int nNum1, int nNum2);
- #endif // end of define _DLL_SHOW_CALCULATE_H_
定义文件:
- //////////////////////////////////////////////////////////////////////////
- // CopyRight(c) 2009, YOYO, All Rights Reserved.
- // Author: LIN YiQian
- // Created: 2009/09/15
- // Describe: 动态库显式链接 定义
- //////////////////////////////////////////////////////////////////////////
- #include "Calculate.h"
- int Add(int nNum1, int nNum2)
- {
- return nNum1 + nNum2;
- }
- int Minus(int nNum1, int nNum2)
- {
- return nNum1 - nNum2;
- }
使用文件:
- //////////////////////////////////////////////////////////////////////////
- // CopyRight(c) 2009, YOYO, All Rights Reserved.
- // Author: LIN YiQian
- // Created: 2009/09/15
- // Describe: 动态库显式链接 使用
- //////////////////////////////////////////////////////////////////////////
- #include <Windows.h>
- #include <iostream>
- int main(void)
- {
- HMODULE hModule = LoadLibrary("动态库显式链接.dll");
- if (NULL != hModule)
- {
- int (*pFun)(int, int) = (int (*)(int, int)) (GetProcAddress(hModule, "Add"));
- std::cout << pFun(1, 2) << std::endl;
- pFun = (int (*)(int, int)) (GetProcAddress(hModule, "Minus"));
- std::cout << pFun(1, 2) << std::endl;
- }
- FreeLibrary(hModule);
- system("pause");
- return 0;
- }