473,651 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Will a GCHandle::Alloc be enough for a native class to hold on to the pointer??

Hi,

I need to have a native class hold on to a managed function pointer.
Not a unmanaged class in a manged block. I mean an unmanaged class in
an unmanaged block via #pragma unmanaged.

I'm wondering if GCHandle will be enough. I can't use gcroot because
it's a #pragma unmananged so if I declare a gcrooted variable

gcroot<ManagedD elegateInstance ^pointer

This won't work. SO what I do is in the managed class I hold a
reference to the managed delegate I'm using and instantiate it with my
managed function. Then I do somehting like this

GChandle::Alloc (ManagedDelegat eInstance);

And hope that if I hold that gch reference in scope, the native class
will always be able to access it. Will this be enough?

Jul 31 '07 #1
0 1423

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

Similar topics

3
2091
by: music4 | last post by:
Greeting, My platform is Solaris 2.8. My question is that if there is a simple way to put a class object in share memory, so that multiple process can use this object. Thanks in advance! Evan
11
1396
by: Ted Miller | last post by:
Hi folks. So I'm in the middle of porting a large (previously COM-based) imaging library to .Net. The clients of this library are VB programmers within the company I work for. Their code will be getting ported to .Net at some point in the near future too. In the .Net world, many of my objects are forced to implement the IDisposable+Finalizer pattern because they hold onto unmanaged resources or represent resources where deterministic...
1
2601
by: Hexar Anderson | last post by:
Why can't you pin an enumeration? For example, the with the following code: public enum MyEnum : byte { ValueOne = 1, ValueTwo = 2 } public class MyClass {
2
3075
by: roni | last post by:
im allocating an object that is a wrapper of unmanaged code. how can i pin that object in memory ,so the gc will not move it. the reason is some other data members of the object,are sent to unmanaged code. hope im clear
8
2342
by: XYZ | last post by:
I need to pass the address of a variableto some win32 API functions like RTLMoveMemory I noticed some weird behavior when pinning objects and using the handle's pointer to write data to the memory location. it seems as if after pinning an object the memory and the object are not updated at the same time anymore
0
1103
by: Lonewolf | last post by:
Hi, please pardon me if I sound stupid. I want to check the status of the GChandle to see if a previous call to Alloc is successful, or whether it has been called before hand, before I call the Free function. I tried the following code, GCHandle gch; gch=GCHandle::Alloc(Mydelegate); <== How do I check if this is successful? gch.Free();
2
7900
by: steve | last post by:
Hi all, I want to understand more about how the pinvoke pinning process works. I'm writing some code that calls DeviceIoControl. DeviceIoControl provides a generic interface to device drivers. Its signature is deliberately open-ended so that it can be highly generic. Refer SDK for more. I want to access the drive geommetry of an SD-Card via
9
3117
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for this, I want to use it. Is it possible to call Managed class functions from Unmanaged class? How to do it? I did something like this. I declared a managed class (in C++ CLI) called as MyManagedClass whose
1
4613
by: =?Utf-8?B?SkE=?= | last post by:
I use a method for threading that instantiates an object that is a wrapper to a DLL (written in C). The wrapper class is passed a byte array, and then does GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); IntPtr ptr = (IntPtr)(handle.AddrOfPinnedObject().ToInt32() + buffer.Length-1); It passes ptr to the DLL function FunctionX().
0
8357
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8277
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8700
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8581
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6158
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.