需求是这样的,我现在拿到一个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)
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)
#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,导入程序来用。
#define DLLIMPORT __declspec(dllimport)
DLLIMPORT bool __stdcall ZQOpenPrinter(LPSTR);
不是简单拷进来
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)
类别:General
然后在Object/library modules 最后增加了这个lib这样对不?
[email protected]
谢谢你,我搞不定再找你 o_o
谢谢各位了,结贴。我以前没来过vc版块,但是我的分多,那位兄弟有这方面的需求尽管跟我开口:)