class="cnt">
.class="tags" href="/tags/DLL.html" title=dll>dll是在你的程序运行的时候才连接的文件c;因此它是一种比较小的可执行文件格式c;.class="tags" href="/tags/DLL.html" title=dll>dll还有其他的文件格式如.ocx等c;所有的.class="tags" href="/tags/DLL.html" title=dll>dll文件都是可执行。 .lib是在你的程序编译连接的时候就连接的文件c;因此你必须告知class="tags" href="/tags/BianYiQi.html" title=编译器>编译器连接的lib文件在那里。一般来说c;与color: #ff6600;">动态连接文件相对比c;lib文件也被称为是color: #ff6600;">静态连接库。当你把代码编译成这几种格式的文件时c;在以后他们就不可能再被更改。如果你想使用lib文件c;就必须: 如果你想从你的代码分离一个class="tags" href="/tags/DLL.html" title=dll>dll文件出来代替静态连接库c;仍然需要一个lib文件。这个lib文件将被连接到程序告诉操作系统在运行的时候你想用到什么 class="tags" href="/tags/DLL.html" title=dll>dll文件c;一般情况下c;lib文件里有相应的class="tags" href="/tags/DLL.html" title=dll>dll文件的名字和一个指明class="tags" href="/tags/DLL.html" title=dll>dll输出函数入口的顺序表。如果不想用lib文件或者是没有lib文件c;可以使用WIN32 API函数LoadLibrary、GetProcAddress。事实上c;我们可以在Visual C++ IDE中以二进制形式打开lib文件c;大多情况下会看到ASCII码格式的C++函数或一些重载操作的函数名字。 一般我们最主要的关于lib文件的麻烦就是出现color: #ff6600;">unresolved symble 这类错误c;这就是color: #ff6600;">lib文件连接错误或者没有包含.c、.cpp文件到工程里c;关键是如果在C++工程里用了C语言写的lib文件c;就必需要这样包含: =============================== 在VC中不用MFC如何制作class="tags" href="/tags/DLL.html" title=dll>dll 方法一:使用export 和 import 在VC中建立一个Console Applicationc;建立2个文件:Dll.h 和 Dll.cpp Dll.h color: #3366ff;">MYLIBAPI int Add (int iLeft, int iRight) Dll.cpp color: #3366ff;">#include "Dll.h" color: #3366ff;">int Add (int iLeft, int iRight) color: #3366ff;">int Sub (int iLeft, int iRight) 保存文件。在color: #ff6600;">Project->setting->link 最下面加上 “/class="tags" href="/tags/DLL.html" title=dll>dll”c; "/"之前一定要与前一项有空格。然后编译c;就可以在debug 或 release下面找到class="tags" href="/tags/DLL.html" title=dll>dll 和 lib 文件了使用的时候包含class="tags" href="/tags/DLL.html" title=dll>dll.h文件。 方法二:使用def文件 Dll.h Dll.cpp color: #3366ff;">int Add (int iLeft, int iRight) color: #3366ff;">int Sub (int iLeft, int iRight) 然后再当前目录下面建立一个.def文件c;文件名最好和要输出的class="tags" href="/tags/DLL.html" title=dll>dll名字一样c;扩展名为.def, 里面写上: color: #3366ff;">LIBRARY class="tags" href="/tags/DLL.html" title=dll>dllname.class="tags" href="/tags/DLL.html" title=dll>dll 再补充一点: |
摘自csdn论坛:
调用DLL有两种方法:静态调用和动态调用.
(一).静态调用其步骤如下:
1.把你的youApp.DLL拷到你目标工程(需调用youApp.DLL的工程)的Debug目录下;
2.把你的youApp.lib拷到你目标工程(需调用youApp.DLL的工程)目录下;
3.把你的youApp.h(包含输出函数的定义)拷到你目标工程(需调用youApp.DLL的工程)目
录下;
4.打开你的目标工程选中工程,选择Visual C++的Project主菜单的Settings菜单;
5.执行第4步后c;VC将会弹出一个对话框c;在对话框的多页显示控件中选择Link页。然
后在Object/class="tags" href="/tags/LIBRARY.html" title=library>library modules输入框中输入:youApp.lib
6.选择你的目标工程Head Files加入:youApp.h文件;
7.最后在你目标工程(*.cpp,需要调用DLL中的函数)中包含你的:#include "youApp.h "
注:youApp是你DLL的工程名。
2.动态调用其程序如下:
动态调用时只需做静态调用步骤1.
{
HINSTANCE hDllInst = LoadLibrary( "youApp.DLL ");
if(hDllInst)
{
typedef DWORD (WINAPI *MYFUNC)(DWORD,DWORD);
MYFUNC youFuntionNameAlias = NULL; // youFuntionNameAlias 函数别名
youFuntionNameAlias = (MYFUNC)GetProcAddress
(hDllInst, "youFuntionName ");
// youFuntionName 在DLL中声明的函数名
if(youFuntionNameAlias)
{
youFuntionNameAlias(param1,param2);
}
FreeLibrary(hDllInst);
}
}