我初学VC++,
我想在我的程序中调用别人做的DLL,人家只提供了DLL文件和里面函数的用法。
请问如何做?谢谢!

解决方案 »

  1.   

    一、用AppWizard生成了一个dll,(是MFC Appwizard(dll)),命名为MyDll
       1、在MyDll.cpp中添加函数://系统是把他作为全局的函数好像
       void DllTest(void)
       {
          AfxMessageBox("this is a dll function");
         }   2、在MyDll.def中添加
         DllTest      @1二、建立基于对话框的一个应用程序UseDll,添加一个按钮,    1、在UserDllDlg.cpp中定义变量如下:    HINSTANCE dll_handle=NULL;
        typedef void (*DLLTEST)(void);
        DLLTEST DllTest;//这两个变量是作为全局变量定义在类的外部    2、在OnButton()中添加代码:想显示链接dll并调用DllTest()函数,添加的代码如下:     Dll_handle=LoadLibrary("...\...\...\Mydll.dll");//dll文件的路径
         if(Dll_handle==NULL)
           {
             AfxMessageBox("dll has not be loaded !");
             return;
             }
         DllTest=(DLLTEST)GetProcAddress(Dll_handle,"DllTest");
          if(DllTest==NULL)
           {
             AfxMessageBox("dll function has not be loaded !");
             return;
             }
         AfxMessageBox("begin to  use function");
         DllTest();
         AfxMessageBox("end of use function");
         FreeLibrary(Dll_handle);
      

  2.   

    静态加载更简单,把Mydll.lib加进工程,
    #include "MyDll.h" 然后直接使用里面的函数。
      

  3.   

    if a dll is all you have, you have to use LoadLibrary and GetProcAddress, consider to write a wrapper class, seeUsing Run-Time Dynamic Linking
    http://msdn.microsoft.com/library/en-us/dllproc/base/using_run_time_dynamic_linking.asp?frame=true