DLL导出函数错点错

tr821021 2008-05-21 03:31:01
def文件; PrinterDll.def : Declares the module parameters for the DLL.

LIBRARY "PrinterDll"
DESCRIPTION 'PrinterDll Windows Dynamic Link Library'

EXPORTS
Init @1
CheckPrinter @2
WarningCheck @3
CheckPrinterTotalNum @4
PrintImage @5
.h文件:
_declspec(dllexport) int Init();
_declspec(dllexport) int CheckPrinter();
_declspec(dllexport) int WarningCheck ();
_declspec(dllexport) int CheckPrinterTotalNum();
_declspec(dllexport) int PrintImage(char* str,int paperNum);

.cpp
_declspec(dllexport) int CheckPrinter(){}
_declspec(dllexport) int WarningCheck (){}
_declspec(dllexport) int CheckPrinterTotalNum(){}
_declspec(dllexport) int PrintImage(char* str,int paperNum){}
错误:
Linking...
.\PrinterDll.def : warning LNK4022: cannot find unique match for symbol "Init"
.\PrinterDll.def : warning LNK4002: "public: int __thiscall PrinterFun::Init(void)" (?Init@PrinterFun@@QAEHXZ) defined in .\Debug\PrinterFun.obj
.\PrinterDll.def : warning LNK4002: "protected: void __thiscall CString::Init(void)" (?Init@CString@@IAEXXZ) defined in C:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB\mfc42d.lib
LINK : fatal error LNK1152: cannot resolve one or more undecorated symbols
LINK : fatal error LNK1141: failure during build of exports file
Error executing link.exe.

PrinterDll.dll - 2 error(s), 3 warning(s)
麻烦具体告诉下如何导出函数,导出类就不要说了,我会,现在我就是导出函数然后做个COM接口去调用
麻烦详细告诉下如何导出函数,COM里又该如何调用他
...全文
181 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
flm007 2008-06-16
  • 打赏
  • 举报
回复
并没有去实现,已经帮你调试好
吹雪 2008-05-22
  • 打赏
  • 举报
回复
COM里可以用BYTE来代替char
Kudeet 2008-05-21
  • 打赏
  • 举报
回复
你应该注意调用DLL的方法,看www.vckbase.com的示例
tr821021 2008-05-21
  • 打赏
  • 举报
回复
我想问下DLL里int PrintImage(char* str,int paperNum)
我在COM里STDMETHOD(CallDllPrintImage)(/*[in]*/char* str,int paperNum,/*[out retval]*/ int *pVal4);

我知道COM里好像不让用char*那该如何做啊,总不能DLL也给修改了吧
知道的指点我下吧,项目马上要出来了
高山-流水 2008-05-21
  • 打赏
  • 举报
回复
1:函数前加extern "C"
2:Init()函数没定义
3:导入函数库#pragma comment(lib, "PrinterDll.lib")
cnzdgs 2008-05-21
  • 打赏
  • 举报
回复
要导入lib文件,可以加在项目属性连接器设置里面,或者:
#pragma comment(lib, "PrinterDll.lib")

另外用_declspec(dllexport)导出并且隐式加载时不需要def文件。
jameshooo 2008-05-21
  • 打赏
  • 举报
回复
extern "C" int Init()
除了没实现的Init函数,其它导出函数都要用extern "C"修饰符
ouyh12345 2008-05-21
  • 打赏
  • 举报
回复
#include "PrinterDll.h"
#pragma comment(lib, "PrinterDll.lib")

STDMETHODIMP CIFun::CallDll (int *pVal)
{
*pVal = Init();
return S_OK;
}
快乐鹦鹉 2008-05-21
  • 打赏
  • 举报
回复
可COM里却还是找不到接口啊
===你在工程中有没有在project->setting的link页中引入你的动态库的lib文件呢?
tr821021 2008-05-21
  • 打赏
  • 举报
回复
_declspec(dllimport) int Init();
STDMETHODIMP CIFun::CallDll (int *pVal)
{
*pVal = Init();
return S_OK;
}

Linking...
Creating library Debug/IPrinterCom.lib and object Debug/IPrinterCom.exp
IFun.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl Init(void)" (__imp_?Init@@YAHXZ)
Debug/IPrinterCom.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

IPrinterCom.dll - 2 error(s), 0 warning(s)

我该添加的肯定都添加过lib文件了,头文件包含过了
tr821021 2008-05-21
  • 打赏
  • 举报
回复
2楼回复我取掉DEF文件定义,查看是得到这5个函数导出了,可COM里却还是找不到接口啊
Init我实现过了
快乐鹦鹉 2008-05-21
  • 打赏
  • 举报
回复
你没有写Init的函数体阿
ouyh12345 2008-05-21
  • 打赏
  • 举报
回复
看2楼和3楼的回复
scq2099yt 2008-05-21
  • 打赏
  • 举报
回复
up
tr821021 2008-05-21
  • 打赏
  • 举报
回复
现在就是我用类写的DLL在COM我就是找不到接口,
--------------------Configuration: IPrinterCom - Win32 Debug--------------------
Compiling...
IFun.cpp
Linking...
Creating library Debug/IPrinterCom.lib and object Debug/IPrinterCom.exp
IFun.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl Init(void)" (__imp_?Init@@YAHXZ)
Debug/IPrinterCom.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

IPrinterCom.dll - 2 error(s), 0 warning(s)
快乐鹦鹉 2008-05-21
  • 打赏
  • 举报
回复
.cpp中怎么没有Init函数体呢?
ouyh12345 2008-05-21
  • 打赏
  • 举报
回复
另外,源文件里,没有实现Init函数?
ouyh12345 2008-05-21
  • 打赏
  • 举报
回复
如果在def文件导出了的话,则头文件、源文件里的_declspec(dllexport)都要去掉

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧