473,411 Members | 1,997 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,411 software developers and data experts.

void* to managed object

Hi everybody:

I am developing an application where I tried to assign a pointer to a
managed object in an unmanaged struct:

void* pUnmanaged;
pUnManaged = (void*) pManaged;

But the compiler did not allow me to do that cast. I read some stuff and I
learned that I cannot reference managed pointers using unmanaged pointers or
viceversa, so I am assigning a GCHandle in my pUnmanaged void pointer:

GCHandle gch = GCHandle::Alloc(pManaged, GCHandleType::Pinned);
pUnmanaged = static_cast<void*>(gch.AddrOfPinnedObject());

That code compiles fine but the following exception is thrown:

"Object contains non-primitive or non-blittable data."

My managed class contains .NET objects and not only primitive types.

Am I doing something wrong here? Can I do what I want to do? How?

Best regards


Nov 17 '05 #1
0 836

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

Similar topics

6
by: Mr.Tickle | last post by:
Hi, I have a C function in a DLL that takes a void* that is passing back some other type, what is the general way to do this with object rather than declaring the actual type that its...
7
by: Lev | last post by:
Hi, I have an unmanaged pointer to a class that I want to hold in a managed class. I pass the pointer (from unmanaged code) in the constructor of the managed class, and at that point it has...
0
by: Stephen Walch | last post by:
I am writing a managed C++ app that calls a third party "C" library. One of the functions I need to call is a standard callback routine: I supply a "C" style callback function and a optional...
1
by: Nanditha Chandra | last post by:
Hi! I am new to Managed C++ and am working on my first project with this. In native C++, we could have a function that takes void* and call that function with any type. Is there a way to do...
1
by: yaron | last post by:
Hi, my unmanaged method return void* pointer to my managed c++ wrapper class. How do i convert this pointer to a managed object so that a c# client could use it ? Thanks.
5
by: Maxwell | last post by:
Hello, Newbie question here. I have a VS.NET 2003 MC++ (not C++/cli) project where I have a managed class reference in a unmanaged class...simple enough. To keep things short I am for the most...
21
by: ashish.sadanandan | last post by:
Hi, I haven't done a lot of C++ programming (done a lot of it in C) and the reason why I'm considering switching now is also the question I'm posting here. I have some library functions that...
49
by: elmar | last post by:
Hi Clers, If I look at my ~200000 lines of C code programmed over the past 15 years, there is one annoying thing in this smart language, which somehow reduces the 'beauty' of the source code...
3
by: vijay.gandhi | last post by:
Hi, I am trying to convert some unmanaged code (C++) to managed code (using C++/CLI). 1) One of the functions used returns a void* which I need to cast into a handle of a managed object. Can...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.