casting a c++ pointer to a c# class

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.
 
T

Todos Menos [MSFT]

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
W

Willy Denoyette [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top