需求是这样的,我现在拿到一个dll,但是他并不符合程序的需求,我需要把他封装成另外一个dll,但是总是编译不过。(我不是做vc的,但是没有人搞这个东西,被逼来搞vc了,所以问题可能很新手,望多多指教,谢谢)环境:vc6目前我有dll,lib和def以及它导出的h文件。我的步骤,File->New->Projects->Win32 Dynamic-Link Library写了如下的文件:
Printer.h(这个是导入那个动态链接库的头文件)
#define DLLIMPORT __declspec(dllimport)DLLIMPORT bool __stdcall ZQOpenPrinter(LPSTR);T.H(这个是我再次封装,想导出的头文件)
#define DLLEXPORT __declspec(dllexport)DLLEXPORT bool OpenPrinter(LPSTR);在我的主函数里调用如下:
#include "stdafx.h"
#include "Printer.h"
#include "T.h"DLLEXPORT bool OpenPrinter(LPSTR printName){
return ZQOpenPrinter(printName);
}
在Project->Setting->Link->Object/Library modules add the lib file.
编译报错:
Linking...
   Creating library Debug/T.lib and object Debug/T.exp
T.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) bool __stdcall ZQOpenPrinter(char *)" (__imp_?ZQOpenPrinter@@YG_NPAD@Z)
Debug/T.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.T.dll - 2 error(s), 0 warning(s)

解决方案 »

  1.   

    相关的dll,lib我已经拷贝到当前的项目中了,我看到他的头文件是这样的:
    #ifndef _DLL_H_
    #define _DLL_H_#define USE_STDCALL 1#if USE_STDCALL
    #define CALL_TYPE __stdcall
    #else
    #define CALL_TYPE __cdecl
    #endif#define DLLAPI __declspec(dllexport)extern "C"{DLLAPI BOOL  CALL_TYPE ZQOpenPrinter(LPSTR);
    }#endif /* _DLL_H_ */所以上面的那个printer.h就仿照他写了,将dllexport改为dllimport,导入程序来用。
      

  2.   

    去掉这个,不要再定义一次导入Printer.h(这个是导入那个动态链接库的头文件)
    #define DLLIMPORT __declspec(dllimport)
    DLLIMPORT bool __stdcall ZQOpenPrinter(LPSTR);
      

  3.   

    要把lib文件添加到工程中间
    不是简单拷进来
      

  4.   

    可能你的lib库路径没放好,呵呵
      

  5.   

    如果去掉这个
    DLLIMPORT bool __stdcall ZQOpenPrinter(LPSTR);
    他不是就不认识这个函数了吗?--------------------Configuration: T - Win32 Debug--------------------
    Build : warning : failed to (or don't know how to) build 'D:\workspace\dll\T\Printer.h'
    Compiling...
    T.cpp
    D:\workspace\dll\T\T.cpp(8) : error C2065: 'ZQOpenPrinter' : undeclared identifier
    Error executing cl.exe.T.dll - 1 error(s), 1 warning(s)
      

  6.   

    lib文件,我配置了在Project Settings->Link下
    类别:General
    然后在Object/library modules 最后增加了这个lib这样对不?
      

  7.   

    你把代码和dll发给我,干脆我帮你搞好得了。
    [email protected]
      

  8.   

    你需要的函数已经在printer.h里面声明过了,你又声明一次
      

  9.   

    谢谢各位热心的帮助,刚才试验了一下成功了。我把那个printer.h文件delete掉,编译通过了。谢谢。ps:to shaojun1314(好好学习,天天向上)
    谢谢你,我搞不定再找你 o_o
    谢谢各位了,结贴。我以前没来过vc版块,但是我的分多,那位兄弟有这方面的需求尽管跟我开口:)