casting a c++ pointer to a c# class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an existing MFC c++ ocx control that I need to work with a c# class.

If I use a locally defined data structure, everything works. For example,
in my C++ app I declare.

MyCSharpClass DataStructure;

To use the data structure in my c# class I use

DataAccess::Select(%DataStructure);

This works great.

However, when I retreive my DataStructure from the MFC C++ ocx control, I
can not pass the structure to the c# class, I get compile errors. For example

char* pDataStructure;
//ocx call returns a pointer to the data structure
myControl.GetData(pDataSturcture);

Now I need pass (by reference) the data structure to a c# class.

I have tried:
DataAccess::Select(pDataStructure);
as well as other variations to cast the data structure to the c# class.

The data structures in the C++ ocx and the c# class are identical. The data
is allocated on the heap.

How can I pass the pointer returned from my control to the c# class.

Thanks for any assistance.
 
I think that C# is not ready for primetime.. VB is the worlds most
popular langauge

I've never had this problem in VB


Hope that helps

-Todos
 
Since your C++ class is exposed through COM, your best bet is to expose
your data structure through COM as well and then pass that around.

Hope this helps.
 
I have an existing MFC c++ ocx control that I need to work with a c# class.

If I use a locally defined data structure, everything works. For example,
in my C++ app I declare.

MyCSharpClass DataStructure;

To use the data structure in my c# class I use

DataAccess::Select(%DataStructure);

This works great.

However, when I retreive my DataStructure from the MFC C++ ocx control, I
can not pass the structure to the c# class, I get compile errors. For example

char* pDataStructure;
//ocx call returns a pointer to the data structure
myControl.GetData(pDataSturcture);

Now I need pass (by reference) the data structure to a c# class.

I have tried:
DataAccess::Select(pDataStructure);
as well as other variations to cast the data structure to the c# class.

The data structures in the C++ ocx and the c# class are identical. The data
is allocated on the heap.

How can I pass the pointer returned from my control to the c# class.

Thanks for any assistance.

How did you declare the Select method? Please no pseudo code.


Willy.
 
Back
Top