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

How to get a handle of a object in c#

I want to get the address of a c# object,and store that
address in a IntPtr value, like we use handle in VC6.How
can i achieve it?
Nov 15 '05 #1
3 11490
Hi,

In VC6, we have pointers that actually hold addresses in RAM, and we have
handles that identify Windows kernel, GDI and user objects like files, pens,
memory mappings etc.

So it is unclear which of them do you actully need and what is your ultimate
goal. May be we could suggest a more efficient approach if you would tell us
what do you want to do with the address of a managed object instance?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"violin" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
I want to get the address of a c# object,and store that
address in a IntPtr value, like we use handle in VC6.How
can i achieve it?


Nov 15 '05 #2
What are you trying to do exactly? There are a couple of possible different
scenarios here.

Maybe you can just use an object ref.
If you just want a cookie, you could consider using a GCHandle.
If you want to manipulate the contents using pointers, or pass to unmanaged
code, you can pin the object using the fixed statement, or perhaps you need
some marshaling/interop help.

Some more info about what you want to do would enable us to help you better.

"violin" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
I want to get the address of a c# object,and store that
address in a IntPtr value, like we use handle in VC6.How
can i achieve it?

Nov 15 '05 #3
thank all of you to have patience to answer my question.
actually,I want to use c lib to store c# object address,
like this:
In c lib, I wrote a structure, and two method operate on
it.
typedef struct
{
void *csharp_obj;
}c_struct;

void set_c_charp_obj(c_struct *cstr, void *csharpObj)
{
cstr->csharp_obj = csharpObj;
}

void *get_c_charp_obj(c_struct *cstr)
{
return cstr->csharp_obj;
}

In C#, I define c lib function prototype:

public extern void SetCCharpObj(IntPtr cStruct, IntPtr
obj);
public extern IntPtr GetCCharpObj(IntPtr cStruct);

then ,you will understand that I want to get C# object
addr and send it as IntPtr to c lib.so that, I store the
pointer of the c# object in c lib for future use.But when
i debug the program, I always get a error.How can I
handle this scenario?and when I fetch the pointer of c#
object, how can i cast it and use it as a object in c#?

thanks

-----Original Message-----
What are you trying to do exactly? There are a couple of possible differentscenarios here.

Maybe you can just use an object ref.
If you just want a cookie, you could consider using a GCHandle.If you want to manipulate the contents using pointers, or pass to unmanagedcode, you can pin the object using the fixed statement, or perhaps you needsome marshaling/interop help.

Some more info about what you want to do would enable us to help you better.
"violin" <an*******@discussions.microsoft.com> wrote in messagenews:02****************************@phx.gbl...
I want to get the address of a c# object,and store that
address in a IntPtr value, like we use handle in VC6.How can i achieve it?

.

Nov 15 '05 #4

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

Similar topics

7
by: Tony Johansson | last post by:
Hello!! Assume I have a handle body pattern with classes called Handle and Body. In the Body class I store one int value for example 7 or some other integer value. In the Handle class I have...
0
by: Tony Johansson | last post by:
Hello! Here I have two classes these are called Handle and Body and a main. You have the class definition below. Some basic information. In the Handle class is there a pointer to the Body. Each...
14
by: Howard | last post by:
Hi, I recently had a problem where I decided to store objects in a vector. (Previously, I had always stored pointers in vectors). Well, naturally, when storing an object in a vector, using...
4
by: Terry | last post by:
There are a number of things about using unmanaged resources in Windows Forms programming that is unclear to me. In C++, if you loaded an icon resource using "ExtractIcon()", the resource was...
7
by: Ken Varn | last post by:
I am working in managed C++. I have a Mutex object in which I need to replace the Handle property with a new handle. The new handle is being constructed using Win32 CreateMutex call. I need to...
3
by: Jarod_24 | last post by:
Dim p As Diagnostics.Process Debug.WriteLine(p.Id) Debug.WriteLine(p.Handle) What is the difference between a process's ID and Handle I see that they are different, and i know that the...
15
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
2
by: SM | last post by:
Hello, I've created this 'wonderful' function the embeds a youtube video in a specified div section using the Javascript DOM. Everything works OK... until I realize how bad the logical programming...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
4
by: Donos | last post by:
Hi I have a HANDLE to an Event, like this.. HANDLE h = ::CreateEvent(NULL, FALSE, FALSE, NULL); This is running in one thread in one class. For example we will call that class as "Class A"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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.