如果使用隐含调用,把lib和dll放在程序目录,把lib文件加入工程,编译即可。
如果使用显式调用,要使用LoadLibrary.

解决方案 »

  1.   

    显式调用的例子:工程mydll(win32应用):mydll.def:LIBRARY "mydll"
    EXPORTS
    donothingmydll.cpp:#include"windows.h" int  donothing(void)//_declspec(dllexport)
    {
    MessageBox(NULL,
    "断点:donothing",
    "TestDll",
    MB_OK); return 1;
    }工程testdll(win32应用):testdll.cpp:#include"windows.h"//int donothing(char addordel,char filename);
    int WINAPI WinMain (HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
                        PSTR szCmdLine, 
    int iCmdShow)
    {
    HMODULE hMyDll;
    int  (* pMyFun)(void);
    int bReturn; MessageBox(hInstance,
    "断点:1",
    "TestDll",
    MB_OK);
    hMyDll=LoadLibrary("mydll.dll"); MessageBox(hInstance,
    "断点:2",
    "TestDll",
    MB_OK);
    pMyFun=(int(*)(void))GetProcAddress(hMyDll,"donothing");

    if(pMyFun)
    MessageBox(hInstance,
    "断点:3",
    "TestDll",
    MB_OK);
    bReturn=(*pMyFun)(); MessageBox(hInstance,
    "断点:4",
    "TestDll",
    MB_OK); FreeLibrary(hMyDll); return 1;
    }两个工程三个文件,把第一个工程的DLL文件放到第二个工程的目录里。
    这是我学习dll是写的练习。
      

  2.   

    显式调用的例子:
    win32应用
    DLL:
    file mydll.cpp
    #include"windows.h"int  donothing(void)
    {
        MessageBox(NULL,"断点:donothing","TestDll",MB_OK);
        return 1;
    }file mydll.def
    LIBRARY "mydll"
    EXPORTS
    donothing调用DLL:
    file testdll.cpp
    #include"windows.h"
    int WINAPI WinMain (HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
                      PSTR szCmdLine, 
    int iCmdShow)
    {
    HMODULE hMyDll;
    int  (* pMyFun)(void);
    int bReturn; hMyDll=LoadLibrary("mydll.dll"); pMyFun=(int(*)(void))GetProcAddress(hMyDll,"donothing");

    bReturn=(*pMyFun)(); FreeLibrary(hMyDll); return 1;
    }把第一个工程输出的DLL放到第二个工程的目录里。
      

  3.   

    选中VC菜单Project下的Setting项,在link属性页中的Object/library modules下加上你的lib文件名,即可。
      

  4.   

    选取菜单Project-->Setting,中的link属性页,在Object/library modules项添加自己的lib文件即可。