Question about IntPtr

  • Thread starter Thread starter Ron Vecchi
  • Start date Start date
R

Ron Vecchi

I am creating my own MainMenu control similar to VS.Net. (yes I know theirs
some out their).
I have predominatly been a web developer for about 5 years and am playing
with Windows forms. So this should help me learn.

My question is about IntPtr.
Basically what is it, I know its a pointer but what is a pointer.(of course
I know it points to something but how) .
In my MenuControl I needed a graphics object in my OnPaint override.

This works great but I dont know why...
//////////////////////////////////
protected override void OnPaint(PaintEventArgs e) {

this.rmm_Graphics = Graphics.FromHwnd(this.Parent.Handle);

}

I think by understanding what pointers are and how they work I will
understand exactly how I extracted the grapics object from my containing
form.
Does any one know of some newbie windows resopurces that expain this on a
moronic level.


Thanks,
 
Any intro to computer science text book using C. For example, mine was
"Introduction to Computer Science Using C" by Roger Eggen. Highly
recommended.

The pointer contains a memory address. 32 bit operating systems use 32 bit
ints to address each available memory position. Conceptually, you can start
to get a handle on it by thinking of your street address "pointing" to your
house's physical location. Someone writes your address on a box and the USPS
delivers it to you. That's what a pointer can do.

Of coursed managed code complicates this because your "house" is moved when
the garbage collector runs.
 
ok, I think I understand. using the IntPtr is like saying "at this memory
location"
so in my case am I abstractly saying "give me the graphics object from the
form at this memory location"

Oh, also Im an idiot, I didn't realize that the PaintEventArgs supplied a
graphics object. Although that didn't stop me from still wondering about
the IntPtr. It just accelerated it.


Mountai Bikn' Guy said:
Any intro to computer science text book using C. For example, mine was
"Introduction to Computer Science Using C" by Roger Eggen. Highly
recommended.

The pointer contains a memory address. 32 bit operating systems use 32 bit
ints to address each available memory position. Conceptually, you can start
to get a handle on it by thinking of your street address "pointing" to your
house's physical location. Someone writes your address on a box and the USPS
delivers it to you. That's what a pointer can do.

Of coursed managed code complicates this because your "house" is moved when
the garbage collector runs.
 
Personally, I would first try to understand pointers outside the context of
dotnet. I wouldn't try to understand IntPtr without understanding a plain
generic pointer. That's just my opinion. BTW, the text book I mentioned is
available for $15 used at
http://www.amazon.com/exec/obidos/t...002-8702177-3519244?v=glance&s=books&n=507846

But I'm sure you can find coverage of this topic by searching on Google.

In general, a pointer holds the address of another variable. It's that
simple.

Ron Vecchi said:
ok, I think I understand. using the IntPtr is like saying "at this memory
location"
so in my case am I abstractly saying "give me the graphics object from the
form at this memory location"

Oh, also Im an idiot, I didn't realize that the PaintEventArgs supplied a
graphics object. Although that didn't stop me from still wondering about
the IntPtr. It just accelerated it.


Mountai Bikn' Guy said:
Any intro to computer science text book using C. For example, mine was
"Introduction to Computer Science Using C" by Roger Eggen. Highly
recommended.

The pointer contains a memory address. 32 bit operating systems use 32 bit
ints to address each available memory position. Conceptually, you can start
to get a handle on it by thinking of your street address "pointing" to your
house's physical location. Someone writes your address on a box and the USPS
delivers it to you. That's what a pointer can do.

Of coursed managed code complicates this because your "house" is moved when
the garbage collector runs.
on
 
Back
Top