在混合模式程序集中导出签名中具有非托管类型的方法

发布于 2024-10-24 23:36:42 字数 1015 浏览 0 评论 0原文

我有一个混合模式程序集,使用 /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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文