在混合模式程序集中导出签名中具有非托管类型的方法
我有一个混合模式程序集,使用 /clr
选项构建。我试图从中导出一个类,供另一个混合模式程序集使用,该程序集也是使用 /clr
选项构建的。
我的问题是该方法的签名包含托管和非托管类型的混合。例如:
static System::String ^Convert( const CString from );
最初,我尝试在实现此功能的非引用类上使用 __declspec(dllexport) 。此操作失败,并出现错误 C3395: __declspec(dllexport) 无法应用于具有 __clrcall 调用约定的函数,大概是由于签名中的托管类型所致。我的下一步是让该类成为 ref
类。现在程序集构建完毕,Reflector 显示导出的方法,如下所示:
public static unsafe string Convert(CStringT<wchar_t,ATL::StrTraitATL<wchar_t,ATL::ChTraitsCRT<wchar_t> > > modopt(IsConst) modreq(IsCopyConstructed)* from);
但是,在客户端程序集中,我无法引用导出的方法……
CString atlString("test");
AtlCStringConverter::Convert( atlString );
产生错误 C2039: 'Convert' : is not “XXX::AtlCStringConverter”的成员。我检查了明显的错误,例如混合不同的字符类型,可能会导致签名不匹配。
我意识到这些导出尝试都不是真正的彻底,因为托管/非托管类型的混合在签名中并排公开,但由于这种托管/非托管的混合在混合模式中很好程序集,我想知道是否没有办法使用混合模式 DLL 之间的签名中的这种混合类型来导出类型?
I have a mixed mode assembly, built with the /clr
option. I am trying to export a class from it, for consumption by another mixed mode assembly, also built with the /clr
option.
My problem is that the signature of the method contains a mixture of managed and unmanaged types. For instance:
static System::String ^Convert( const CString from );
Initially, I tried to use __declspec(dllexport)
on the non-ref class implementing this. This failed with error C3395: __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention, presumably, because of the managed type in the signature. My next take was to make the class a ref
class instead. Now the assembly builds and Reflector displays the exported method like so:
public static unsafe string Convert(CStringT<wchar_t,ATL::StrTraitATL<wchar_t,ATL::ChTraitsCRT<wchar_t> > > modopt(IsConst) modreq(IsCopyConstructed)* from);
However, in the client assembly, I fail to be able to reference the exported method ...
CString atlString("test");
AtlCStringConverter::Convert( atlString );
... yields the error C2039: 'Convert' : is not a member of 'XXX::AtlCStringConverter'. I've checked for obvious mistakes like mixing different char types that might cause the signature to not be matched.
I realize that neither of these export attempts are really kosher in that a mixture of managed/unmanaged types are exposed side by side in the signature, but since this mixture of managed/unmanaged is fine within a mixed mode assembly, I was wondering if there is no way to export types using this mixture of types in the signature between mixed mode DLLs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题和答案可能会有所帮助:
编译器错误 C2158 的最佳解决方法: make_public 不支持原生模板类型
This question and answer might help:
Best workaround for compiler error C2158: make_public does not support native template types