免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3585 | 回复: 7

[C++] VC如何实现静态调用DLL? [复制链接]

论坛徽章:
0
发表于 2014-03-12 15:50 |显示全部楼层
20可用积分
#ifndef __ABC_H__
#define __ABC_H__

CString BootStart(CString Name);
CString StopBoot(CString Name);
CString Mount(CString SambaServerIp, CString User, CString Password, CString Disk);
CString uMount(CString Disk);
CString ChangeComputeName(LPCTSTR ComputeName);
CString ChangeDiskName(CString StorageServerIP, CString UserName,CString DiskName);

#endif

上面是我根据网上给的方法写的头文件 不知道也不知道对不对, DLL可以实现动态调用但是包含我写的头文件 就出现下面错误。怎么回事?

#include <disk.h>
#pragma comment(lib, "disk.lib")

错误        1        error LNK2019: 无法解析的外部符号 _mysql_num_fields@4,该符号在函数 "void __cdecl SelectSambaUser(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > >,class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > >,class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > &,class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > &)" (?SelectSambaUser@@YAXV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@0AAV12@1@Z) 中被引用        F:\C++代码\个性化磁盘\SkyDiskService\SkyDiskService\SkyDiskService.obj

错误        2        error LNK1120: 8 个无法解析的外部命令        F:\C++代码\个性化磁盘\SkyDiskService\Debug\SkyDiskService.exe

最佳答案

查看完整内容

根据“无法解析的外部符号 _mysql_num_fields@4”猜测,可能是你没有正确引用libmysql库导致的

论坛徽章:
0
发表于 2014-03-12 15:50 |显示全部楼层
根据“无法解析的外部符号 _mysql_num_fields@4”猜测,可能是你没有正确引用libmysql库导致的

论坛徽章:
0
发表于 2014-03-12 17:26 |显示全部楼层
已经解决了 我把解决方案的配置模板发出来 方便以后 也方便大家
  1. #ifndef _DLLMODULENAME_H
  2. #define _DLLMODULENAME_H

  3. //#include <>
  4. //#include ""

  5. /*
  6. *        if using C++ Compiler to compile the file, adopting C linkage mode
  7. */
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif

  11. // according to the control macro, deciding whether export or import functions
  12. #ifdef _DLLMODULENAME_
  13. #define DLLMODULENAME_LIB_API __declspec(dllexport)
  14. #else
  15. #define DLLMODULENAME_LIB_API __declspec(dllimport)
  16. #endif

  17. // functions declarations
  18. CString BootStart(CString Name);
  19. CString StopBoot(CString Name);
  20. CString Mount(CString SambaServerIp, CString User, CString Password, CString Disk);
  21. CString uMount(CString Disk);
  22. CString ChangeComputeName(LPCTSTR ComputeName);
  23. CString ChangeDiskName(CString StorageServerIP, CString UserName,CString DiskName);
  24. // ... more declarations as needs

  25. #undef DLLMODULENAME_LIB_API

  26. #ifdef __cplusplus
  27. }
  28. #endif

  29. #endif
复制代码

论坛徽章:
59
2015年亚洲杯之约旦
日期:2015-01-27 21:27:392015年亚洲杯之日本
日期:2015-02-06 22:09:41拜羊年徽章
日期:2015-03-03 16:15:432015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015元宵节徽章
日期:2015-03-06 15:50:392015年亚洲杯之阿联酋
日期:2015-03-19 17:39:302015年亚洲杯之中国
日期:2015-03-23 18:52:23巳蛇
日期:2014-12-14 22:44:03双子座
日期:2014-12-10 21:39:16处女座
日期:2014-12-02 08:03:17天蝎座
日期:2014-07-21 19:08:47
发表于 2014-03-12 17:51 |显示全部楼层
  1. extern "C" CString BootStart(CString Name);
复制代码
太强大了~~~

论坛徽章:
0
发表于 2014-03-13 11:49 |显示全部楼层
回复 4# folklore


    char用的不习惯

论坛徽章:
59
2015年亚洲杯之约旦
日期:2015-01-27 21:27:392015年亚洲杯之日本
日期:2015-02-06 22:09:41拜羊年徽章
日期:2015-03-03 16:15:432015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015元宵节徽章
日期:2015-03-06 15:50:392015年亚洲杯之阿联酋
日期:2015-03-19 17:39:302015年亚洲杯之中国
日期:2015-03-23 18:52:23巳蛇
日期:2014-12-14 22:44:03双子座
日期:2014-12-10 21:39:16处女座
日期:2014-12-02 08:03:17天蝎座
日期:2014-07-21 19:08:47
发表于 2014-03-13 12:22 |显示全部楼层
回复 5# tan1301230147


    我的意思, extern "C" 和CString 不能连用
extern "C"的函数只能接受和返回C类型, 不能返回类

论坛徽章:
0
发表于 2014-03-13 12:37 |显示全部楼层
恩 所以正在琢磨怎么才能用LPCTSTR类型替换掉CString
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP