您的位置:程序门 -> vc/mfc -> 进程/线程/dll



[新手]如何再次封装dll


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


[新手]如何再次封装dll[已结贴,结贴人:abeixu]
发表于:2007-01-10 10:23:21 楼主
需求是这样的,我现在拿到一个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)

发表于:2007-01-10 10:26:181楼 得分:0
相关的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,导入程序来用。
发表于:2007-01-10 10:29:552楼 得分:30
去掉这个,不要再定义一次导入

printer.h(这个是导入那个动态链接库的头文件)
#define   dllimport   __declspec(dllimport)
dllimport   bool   __stdcall   zqopenprinter(lpstr);
发表于:2007-01-10 10:41:073楼 得分:20
要把lib文件添加到工程中间
不是简单拷进来
发表于:2007-01-10 10:42:214楼 得分:20
可能你的lib库路径没放好,呵呵
发表于:2007-01-10 10:42:455楼 得分:0
如果去掉这个
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)
发表于:2007-01-10 10:45:526楼 得分:0
lib文件,我配置了

在project   settings-> link下
类别:general
然后在object/library   modules   最后增加了这个lib

这样对不?
发表于:2007-01-10 10:48:437楼 得分:0
你先按楼上的做,应该是ok的。。
有问题再贴过来。。。。
发表于:2007-01-10 10:50:188楼 得分:0
你把代码和dll发给我,干脆我帮你搞好得了。。。。
max.shao@liteon.com
发表于:2007-01-10 10:51:189楼 得分:30
你需要的函数已经在printer.h里面声明过了,你又声明一次。。。
发表于:2007-01-10 10:55:2310楼 得分:0
谢谢各位热心的帮助,刚才试验了一下成功了。我把那个printer.h文件delete掉,编译通过了。

谢谢。

ps:to   shaojun1314(好好学习,天天向上)
谢谢你,我搞不定再找你   o_o


谢谢各位了,结贴。我以前没来过vc版块,但是我的分多,那位兄弟有这方面的需求尽管跟我开口:)
发表于:2007-01-11 13:02:2811楼 得分:0
mark
发表于:2007-01-11 14:28:1912楼 得分:0
mark


快速检索

最新资讯
热门点击