Saturday 15 March 2014

c++ cli - Exporting C++/CLI native class (C4679) -


The C ++ / CLI assembly (MySpad) has a public ref class, which has a public static method, which accepts the original parameters.
  #pragma make_public (nativeTypeA) namespace namespaceA {public ref class MyClass: namespaceB :: MyClass {public: static managedTypeA ^ MethodA (nativeTypeA ultimate); Stable managedTypeB ^ methib (original type b param); }}   

I want to expose this method to another C ++ / CLI assembly. Managed assembly properly compiled but assembly gives it context (CallingAssembly) generates the following warning for MethodB:

  warning C4679: member could not import it clinically: 'namespaceA :: MyClass :: MethodB 'assembly' MyAssembly, version = 0.0.0.0, culture = neutral, public kiton = null 'type' Nameshon A: Michels' occurred during import.   

I can not use make_public on nativeTypeB, because it is a typedef a templated class, however, I am using make_public non templated native types (eg nativeTypeA) and works (ie no C4679 instead of using Make_public when compiling Colingasampakbl), I native class publicly declared and posted as suggested __declspik native head through Preprocessor directives (dl Lexport) is used. It is also conditional "public" modifier (through CLR_ACCESS_MODIFIER) as class out to include other native projects was necessary: ​​

  #ifdef managed #define CLR_ACCESS_MODIFIER public #ifdef MYASSEMBLY_DEF #define MYASSEMBLY_LINKAGE __declspec (dllexport) #else #define MYASSEMBLY_LINKAGE __declspec (dllimport) #endif #else #define MYASSEMBLY_LINKAGE #define CLR_ACCESS_MODIFIER #endif template & lt; & Gt; CLR_ACCESS_MODIFIER class MYASSEMBLY_LINKAGE Basic Type B & lt; TT & gt; : Public type B_base & lt; TT & gt; {...}   

I have also done this for the original text (necessary to compile), and its typefiff:

 < Code> typedef public type B & lt; TT & gt; MYASSEMBLY_LINKAGE Basic Type B;   

I'm not sure whether the line above is necessary or not, but the C4679 still happens in any way.

I have made a general inquiry: Managed preprocessor instructions define both projects; MYASSEMBLY_DEF is defined in the MyAssembly; And I have added MyAssembly.lib to the link line in MySound Assembly as well as in its link line in CallingAssands. The project build order is correct and there is no dependency in it, but I am still receiving C 4679.

I can change the interface to accept non-temval types, but I really do not want to do this because the code is lead to bloat and less elegant

any Can also help?

Thank you in advance!

It is never good to pass the objects of basic classes in the boundaries of DLL, because it is very < Em> very is a rule that is easy to violate.

C ++ / CLI does nothing for this help, instead it provides the ability to generate managed types that are specially designed to be shared in assemblies. . This prevents disaster (ODR violation) from employing by sharing native types. You can use to override make_public pragma, but with the restriction (such as a template)

The best way to share native types is through the COM-style interface.

No comments:

Post a Comment