473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

casting a c++ pointer to a c# class

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.

Apr 9 '07 #1
3 1871
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

On Apr 9, 2:16 pm, j...@nospam.com
<jamesnospam...@discussions.microsoft.comwrote:
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.

Apr 9 '07 #2
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ja***@nospam.com" <ja************@discussions.microsoft.comwrote in
message news:69**********************************@microsof t.com...
>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.

Apr 10 '07 #3
"ja***@nospam.com" <ja************@discussions.microsoft.comwrote in message
news:69**********************************@microsof t.com...
>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.
>

Apr 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Vinodh Kumar | last post by:
I see that casting changes the value of a pointer in case of multiple inheritance.In single inheritance also it is the same know?Isn't it? Vinodh Kumar P
4
by: Jacob Jensen | last post by:
This question has probably been asked a million time, but here it comes again. I want to learn the difference between the three type cast operators: static_cast, reinterpret_cast, dynamic_cast. A...
5
by: Ingo Nolden | last post by:
Hi there, I am writing a smart pointer that is similar to the boost intrusive ptr. I am trying to make it behave like a c++ pointer including the implicit and explicit casting behaviour. Below...
16
by: He Shiming | last post by:
Hi, I'm having a little bit of trouble regarding pointer casting in my program. I don't understand why the following two cases produce different results. Case 1: IInterface *pInterface = new...
44
by: Agoston Bejo | last post by:
What happens exactly when I do the following: struct A { int i; string j; A() {} }; void f(A& a) { cout << a.i << endl;
8
by: Yin99 | last post by:
I have the following code (Mammal base class, Dog inherits from Mammal): Dog *spot= new Dog; spot->Speak(); Mammal *fido = dynamic_cast<Mammal*>(spot); fido->Speak(); Dog *bandit =...
5
by: brekehan | last post by:
I've always been a little sketchy on the differences between static, dynamic, and reinterpret casting. I am looking to clean up the following block by using C++ casting instead of the C style...
9
by: Jess | last post by:
Hello, It seems both static_cast and dynamic_cast can cast a base class pointer/reference to a derived class pointer/reference. If so, is there any difference between them? In addition, if I...
9
by: Taras_96 | last post by:
Hi everyone, I was experimenting with static_cast and reinterpret cast #include <iostream> struct A1 { int a; }; struct A2 { double d; }; struct B : public A1, A2
4
by: Wally Barnes | last post by:
Can someone help a poor C++ programmer that learned the language before there was a standard lib .. etc ? Basically I have two classes that look something like below: template <class T>...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.