老师您好,我想要将C++语言编译为dll文件以便Addins程序来调用。想要生成dll的函数大致如下:
extern "C" DLLEXPORT WString GetPropertyzj(){...
WString pp;
return pp;
}
但是编译时出现报错信息:
C:\Users\51671\Desktop\GetPropertydll\GetPropertydll.cpp(34): error C2220: 警告被视为错误 - 没有生成“object”文件C:\Users\51671\Desktop\GetPropertydll\GetPropertydll.cpp(34): warning C4190: “GetPropertyzj”有指定的 C 链接,但返回了 与 C 不兼容的 UDT“Bentley::WString”C:\PROGRA~1\Bentley\MICROS~2\include\Bentley/WString.h(51): note: 参见“Bentley::WString”的声明C:\Users\51671\Desktop\GetPropertydll\GetPropertydll.cpp(34): error C2201: “GetPropertyzj”: 必须有外部链接才可进行导出/导入BMAKE: file [C:\Users\51671\AppData\Local\Temp\Bentley\MicroStationSDK\objects\GetPropertydll.obj] may be incompleteBMAKE: call trace line: 68, C:\Users\51671\Desktop\GetPropertydll\GetPropertydll.mkeSat Sep 19 17:17:53 2020, elapsed time: 0:03
请问如果我想要函数返回WString类型数据,应该怎样做?
谢谢老师,十分感谢。
WString是MDL中定义的一个类,非标准的C++类。请修改成如下写法试一试:
extern "C" DLLEXPORT WCharCP GetPropertyzj() { WString pp; return pp.GetWCharCP(); }
Answer Verified By: JolinMX
看一下这篇帖子里边的解释:stackoverflow.com/.../error-in-c-code-linkage-warning-c4190-type-has-c-linkage-specified-but-retu