0

There are two separate project which are trying to communicate like this :
I have following native class in C++ CLI

public class Data{
    public:
    int x;
}

By importing I mean that have added reference to C++ CLI project in my C# project.
On other side I'm importing this C++ CLI project into my C# project and in C# I want to do :

Data k = new Data() //It's ok till here
int b = k.x; //The field x is not visible here !

Is there any way to force C# or C++ CLI to share the field and methods ?
EDIT: Also C# assume the class data as a struct !

Mohsen Sarkar
  • 5,910
  • 7
  • 47
  • 86
  • I'm not sure what you mean by "importing into your C# project". You can't have C# and C++ CLI in _one project_. Do you mean you're referencing the CLI _assembly_ from your C# project within _one solution_? – D Stanley Mar 11 '13 at 19:00
  • @DStanley I have edited my answer, please check it again. – Mohsen Sarkar Mar 11 '13 at 19:03

1 Answers1

1

I would imagine you would need to make it a ref class.

public ref class Data{
    public:
    int x;
}

C# can't construct Data in the way you have it now. It's not on the managed heap. ref will make it show up on the managed heap. If you want Data to remain unmanaged, you will have to write a wrapper.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445