dll
1.cl创建并调用dll
//testdll.cpp
main
2.使用Def文件(模块定义文件)导出dll中的函数
设文件名为MathLib.def
用Dependency Walker查看动态库MathLib.dll.导出的函数,为add 和 subtract//(它的导入库名称仍为testdll.lib)
用vc自带工具dumpbin查看testdll.lib导出的函数为
?add@@YANNN@Z (double __cdecl add(double,double))
?subtract@@YANNN@Z (double __cdecl subtract(double,double))
和1例的一样,有些奇怪.
3.调用约定对导出函数的影响
调用约定4.显示调用DLL中的函数
显示调用
//testdll.cpp
_declspec(dllexport) double add(double da ,double db)
{
return da+db;
}
_declspec(dllexport) double subtract(double da , double db)
{
return da-db;
}
//main.cpp{
return da+db;
}
_declspec(dllexport) double subtract(double da , double db)
{
return da-db;
}
打开命令提示符,输入以下命令
cl /c testdll.cpp //生成testdll.obj
link /dll testdll.obj //生成testdll.lib testdll.exp testdll.dll
cl /c main.cpp //生成main.obj
link main.obj testdll.lib //生成main.exe
执行main.exe
结果:
testdll
3.2+6.5=9.7
2.使用Def文件(模块定义文件)导出dll中的函数
设文件名为MathLib.def
LIBRARY "MathLib.dll"
DESCRIPTION 'MathLib'
EXPORTS
add @1
subtract @2
testdll.cpp改写成如下样子:DESCRIPTION 'MathLib'
EXPORTS
add @1
subtract @2
double add(double da ,double db)
{
return da+db;
}
double subtract(double da , double db)
{
return da-db;
}
{
return da+db;
}
double subtract(double da , double db)
{
return da-db;
}
打开命令提示符,输入以下命令
cl /c testdll.cpp //生成testdll.obj
link /DEF:MathLib.def /dll testdll.obj //生成testdll.lib testdll.exp testdll.dll
cl /c main.cpp //生成main.obj
用Dependency Walker查看动态库MathLib.dll.导出的函数,为add 和 subtract//(它的导入库名称仍为testdll.lib)
用vc自带工具dumpbin查看testdll.lib导出的函数为
?add@@YANNN@Z (double __cdecl add(double,double))
?subtract@@YANNN@Z (double __cdecl subtract(double,double))
和1例的一样,有些奇怪.
3.调用约定对导出函数的影响
浙公网安备 33010602011771号