How to: Declare public and private on Native Classes
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

How to: Declare public and private on Native Classes

It is possible for a native type to be referenced from a managed type. For example, a function in a managed type can take a parameter whose type is a native struct. If the managed type and function is public in an assembly, then the native type must also be public.


// mcppv2_ref_class3.h
// native type
public struct N {
   int i;

Next, create the source code file that will consume the native type:

// mcppv2_ref_class3.cpp
// compile with: /clr /LD
#include "mcppv2_ref_class3.h"
// public managed type
public ref struct R {
   // public function that takes a native type
   void f(N nn) {}

Next, compile a client:

// mcppv2_ref_class4.cpp
// compile with: /clr
#using "mcppv2_ref_class3.dll"

#include "mcppv2_ref_class3.h"

int main() {
   R ^r = gcnew R;
   N n;

See Also

© 2015 Microsoft