开发者

Exporting method with unmanaged type in signature in mixed mode assembly

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 s开发者_开发知识库tatic 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?


This question and answer might help: Best workaround for compiler error C2158: make_public does not support native template types

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜