0

I have a header file that is included by both a native cpp file and a managed cpp file(compiled with /clr). It includes only native types, but I want to specify that the native types are visible outside the assembly
(see http://msdn.microsoft.com/en-us/library/4dffacbw(VS.80).aspx).

Essentially, I want:

public class NativeClass  // The public makes this visible outside the assembly.
{

};

If I include this code from a native cpp, I get the following error:

error C3381: 'NativeClass' : assembly access specifiers are only available in code compiled with a /clr option

Attempted solution:

I'm currently using a preprocessor solution that causes the public to appear when compiling with the managed client, but it does not appear for the native client:

#ifdef __cplusplus_cli
#define CLR_ASSEMBLY_ACCESS_SPECIFIER__Public public
#else
#define CLR_ASSEMBLY_ACCESS_SPECIFIER__Public 
#endif 

CLR_ASSEMBLY_ACCESS_SPECIFIER__Public
class NativeClass      
{

};

Question:

Is this the appropriate way to achieve this, or is there a better way?

Matt Smith
  • 17,026
  • 7
  • 53
  • 103

1 Answers1

0

Have you tried the make_public pragma listed on the MSDN page you linked to?

Otherwise, the solution you have is perfectly valid. I'm curious to know why you want to export native types from a CLR assembly though.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • I can use the make_public, but that seems to be more for fixing the issue when you can't modify the header file in question. Since I own the header file, I wanted to "properly" make it public. – Matt Smith Nov 08 '10 at 18:05
  • I want to make the Native type visible so I can have a method like `ManagedClass ^ GetManagedFromNative(const NativeClass & native)` be visible to another assembly. If I don't make the NativeClass public, then the call to call the method `GetManagedFromNative` causes `Error C3767 'function' candidate function(s) not accessible`. http://msdn.microsoft.com/en-us/library/19dh8yat(VS.80).aspx. – Matt Smith Nov 08 '10 at 18:12