c++ - 在托管 C++ 项目中使用 wchar_t 时未解析的外部符号

标签 c++ mfc c++-cli wchar-t

我有一个 C++ 项目,其设置为 Unicode 作为字符集和/clr 选项以支持公共(public)语言运行时。我正在调用 MFC dll 的某些函数(设置了 MultiByte 字符集),但在那些使用 wchar_t 的函数上出现了一些类似的错误。对于未设置/clr 选项的那些 unicode c++ 项目(即没有公共(public)语言运行时支持),相同的 dll 是工作文件。我已经完成了谷歌并尝试了一些类似的东西:--

  1. 用 std:string 替换 Cstring 但两者都给出相同的错误。

std 的示例:字符串:--

error LNK2001: unresolved external symbol "public: __thiscall CEventLog::CEventLog(wchar_t const *)" (??0CEventLog@@QAE@PB_W@Z)

对于 Cstring:--

error LNK2019: unresolved external symbol "public: bool __thiscall CIITAdoField::GetValue(class ATL::CStringT > > &)" (?GetValue@CIITAdoField@@QAE_NAAV?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@@Z) referenced in function "public: bool __thiscall Iit::DataFeedSvr::SpeedCache::CacheLoader > >,class Iit::DataFeedSvr::SpeedCache::HolidayScheduleInfo,struct Iit::DataFeedSvr::SpeedCache::HolidayScheduleSpeedCacheParam>

::Reload(class Iit::DataFeedSvr::SpeedCache::DoubleKeyCacheInstance > >,class Iit::DataFeedSvr::SpeedCache::HolidayScheduleInfo,struct Iit::DataFeedSvr::SpeedCache::HolidayScheduleSpeedCacheParam> &,class CIITAdoRecordset &,enum Iit::DataFeedSvr::SpeedCache::ERefreshType,class Iit::DataFeedSvr::SpeedCache::CacheObserver const *)" (?Reload@?$CacheLoader@V?$DoubleKeyCacheInstance@JV?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@VHolidayScheduleInfo@SpeedCache@DataFeedSvr@Iit@@UHolidayScheduleSpeedCacheParam@456@@SpeedCache@DataFeedSvr@Iit@@@SpeedCache@DataFeedSvr@Iit@@QAE_NAAV?$DoubleKeyCacheInstance@JV?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@VHolidayScheduleInfo@SpeedCache@DataFeedSvr@Iit@@UHolidayScheduleSpeedCacheParam@456@@234@AAVCIITAdoRecordset@@W4ERefreshType@234@PBVCacheObserver@234@@Z)

  1. 我已经检查了“将 Wchar_t 视为内置类型”之类的设置,它是文件。
  2. 我尝试使用 __declspec(dllexport) 显式导出函数和类,但没有成功。
  3. 我无法将我的项目从 unicode 更改为多字节,或者无法更改/clr 选项的设置,因为它开始出现其他错误。

请提出解决方案。提前致谢。

最佳答案

对外部 DLL 执行“dumpbin”以查看导出的内容。如果您的 CEventLog::CEventLog 没有导出基于字符的构造函数,您将无法导入它,就这么简单。

从您的示例来看,/clr 开关不会导致问题。尝试创建一个全新的 Unicode 项目(没有 CLR)以检查您是否真的可以链接到外部 DLL。

关于c++ - 在托管 C++ 项目中使用 wchar_t 时未解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12458269/

相关文章:

c++ - 如何将 Visual-Studio 2010 切换到 C++11

c++ - 使用 MFC 在 opencv 中的函数 cvInitImageHeader 中输入 roi 错误

c++ - 将 CreateCompatibleDC 与 MM_TEXT 以外的映射模式一起使用

c# - 当 T 正在实现类时,C++/CLI 中的 IComparable<T>

c++ - 设置QScrollBar的 slider 大小与内容对应

c++ - 在 C 中使用 pow、XOR 或指针时出现段错误

c++ - 使用 cin 和 do-while 的无限循环,即使在使用 cin.sync 刷新缓冲区时也是如此

winapi - MFC:如何打开 Windows 对话框 "Open With"(选择要用于打开此文件的程序)?

wpf - 复合类中的 C++/CLI DLL 和 ObservableCollections

c++ - 如何#include 在 C++/CLI 项目中使用 nullptr 的第三方 native C++ header