#if 0
/*使用lib和头文件静态加载*/
#include <iostream>
#include "Circle.h"
using namespace std;
#pragma comment(lib, "..\\Debug\\testDll.lib")
int main()
{
CCircle c;
c.SetCentre(CPoint(1, 1));
c.SetR(1);
cout << c.GetAreaSize() << endl;
cout << c.GetLineLength() << endl;
system("pause");
return 0;
}
#endif
#if 1
/*无需lib,动态加载*/
#include <iostream>
#include <windows.h>
#include <WinUser.h>
using namespace std;
typedef int(*tpAddFun) (int, int);
DWORD WINAPI testThread(LPVOID lp)
{
cout << "Access Thread" << endl;
tpAddFun addFun = NULL;
HINSTANCE hDll = LoadLibrary(L"..\\Debug\\testDll.dll");
if (hDll)
{
addFun = (tpAddFun)GetProcAddress(hDll, MAKEINTRESOURCEA(1));
if (addFun)
{
cout << "1 + 2 = " << (*addFun)(1, 2) << endl;
}
else
{
cout << "Found add Function Error" << endl;
}
FreeLibrary(hDll);
}
else
{
cout << "Open dll Error" << endl;
}
return 0;
}
int main()
{
tpAddFun addFun = NULL;
HINSTANCE hDll = LoadLibrary(L"..\\Debug\\testDll.dll");
if (hDll)
{
addFun = (tpAddFun)GetProcAddress(hDll, "add");
if (addFun)
{
cout << "1 + 2 = " << (*addFun)(1, 2) << endl;
}
else
{
cout << "Found add Function Error" << endl;
}
int *pGlobalInt = (int *)GetProcAddress(hDll, "nGlobalInt");
if (pGlobalInt)
{
cout << "nGlobalInt = " << *pGlobalInt << endl;
*pGlobalInt = 100;
pGlobalInt = (int *)GetProcAddress(hDll, "nGlobalInt");
cout << "nGlobalInt = " << *pGlobalInt << endl;
}
else
{
cout << "Not Fount nGlobalInt" << endl;
}
FreeLibrary(hDll);
}
else
{
cout << "Open dll Error" << endl;
}
system("pause");
CreateThread(NULL, 0, testThread, NULL, 0, NULL);
system("pause");
return 0;
}
#endif
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
DLL学习.zip (50个子文件)
DLL学习
testMain
testMain
Debug
testMain.log 3B
testMain.tlog
testDll.Build.CppClean.log 1KB
testDll.log 3B
testDll.tlog
testMain.Build.CppClean.log 1KB
testMain
testMain.vcxproj.filters 1KB
Debug
vc120.pdb 396KB
testMain.log 1KB
testMain.tlog
cl.command.1.tlog 664B
CL.read.1.tlog 28KB
link.read.1.tlog 3KB
link.write.1.tlog 486B
CL.write.1.tlog 508B
link.command.1.tlog 1KB
testMain.lastbuildstate 172B
main.obj 175KB
vc120.idb 691KB
testMain.Build.CppClean.log 889B
main.cpp 2KB
testMain.vcxproj 4KB
Point.h 301B
Circle.h 418B
testMain.v12.suo 21KB
testMain.sln 970B
testDll
Debug
testDll.sln 1KB
.vs
testDll
v14
.suo 30KB
testDll
Debug
vc120.pdb 164KB
testDll.Build.CppClean.log 1KB
Function.obj 4KB
Point.obj 32KB
testDll.log 5KB
testDll.tlog
cl.command.1.tlog 2KB
CL.read.1.tlog 19KB
link.read.1.tlog 3KB
link.write.1.tlog 680B
CL.write.1.tlog 1KB
link.command.1.tlog 1KB
testDll.write.1u.tlog 344B
testDll.lastbuildstate 162B
vc120.idb 515KB
Circle.obj 8KB
testDll.vcxproj 8KB
Function.cpp 98B
Circle.cpp 548B
testDll.def 52B
testDll.vcxproj.filters 2KB
Function.h 79B
Point.cpp 822B
Point.h 301B
Circle.h 418B
testDll.v12.suo 33KB
共 50 条
- 1
资源评论
baidu_32554385
- 粉丝: 1
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功