How to Convert a UnManaged class to a managed one?Or the oposite?  
Author Message
Brant Yin





PostPosted: Visual C++ General, How to Convert a UnManaged class to a managed one?Or the oposite? Top

The project process is:

C# -->C++/CLI -->C++'s DLL(Exporting some classes)

There is a parameter of Class Type in the DLL.

How to use it in C#

What will be done in C++/CLI

Thank U!



Visual C++12  
 
 
cgraus





PostPosted: Visual C++ General, How to Convert a UnManaged class to a managed one?Or the oposite? Top

Does it just contain data members, or does it also contain code If just data members, then you can look at www.pinvoke.net for examples on how to marshall structs between C# and C++.



 
 
Brant Yin





PostPosted: Visual C++ General, How to Convert a UnManaged class to a managed one?Or the oposite? Top

Do you have more information for me

Are there relative functions or Samples


 
 
Brant Yin





PostPosted: Visual C++ General, How to Convert a UnManaged class to a managed one?Or the oposite? Top

ps:

I don't use [DllImport],

I use C++/CLI doing the Convertion.

But I don't know how to convert a class from managed one to unmanaged one.

So please help me.

Thank you !


 
 
cgraus





PostPosted: Visual C++ General, How to Convert a UnManaged class to a managed one?Or the oposite? Top

A good starting point would be to answer my question. Is this a struct with data members, or a class with methods What are you trying to get between managed and unmanaged code



 
 
Brant Yin





PostPosted: Visual C++ General, How to Convert a UnManaged class to a managed one?Or the oposite? Top

oh.

Both a struct with data members, and a class with methods will be uesd.

 For example:

there is a function in DLL:

   ReturnData GetData(InputData data)

 {..... }

  the definition of ReturnData is:

 struct ReturnData

{

  char* buf;

  unsigned long length;

 //and so on.

};

 

struct InputData

{

 int left;

 int right;

//and so on.

};

In C++/CLI. the InputData and ReturnData will be recognized,

But C# will not.

 

In addition:

There are some Callbacks in my DLL.

So a class with methods will be uesd.

 

Thank U!


 
 
cgraus





PostPosted: Visual C++ General, How to Convert a UnManaged class to a managed one?Or the oposite? Top

I'm not sure how it's done with callbacks, but with structs, you can just define a struct in C# and make sure it's the same size ( the char * makes this harder, can you move it to the end of your structure ).