usage of System.IntPtr

Posted on 2008-10-08
Last Modified: 2013-11-05

where would you use the System.IntPtr class?
The documentation writes "A platform-specific type that is used to represent a pointer or a handle."

Question by:xRalf
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 15

Expert Comment

ID: 22667764
Its a method of referring between different development languages, and for handles such as FileStream (it will hold the file handles).

Author Comment

ID: 22667902
Try to send some minimalistic code snippet that will do something useful...
LVL 15

Expert Comment

ID: 22669311
Snippet for print window on a picturebox.

private System.Windows.Forms.PictureBox pp;
pp = new PictureBox();
System.IntPtr hwnd = pp.Handle;
Bitmap bm = new Bitmap (pp.Size.Width, pp.Size.Height);
if (bm != null)
using (Graphics g = Graphics.FromImage (bm))
System.IntPtr bmDC = g.GetHdc ();
bool ok =true;
ok = PrintWindow (hwnd, bmDC,0);
g.ReleaseHdc (bmDC);
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 22669547

I tried to compile the snippet, but it doesn't compile because function PrintWindow doesn't exist. I'd like to compile it to see why IntPtr is useful and what is it good for.
LVL 15

Assisted Solution

angus_young_acdc earned 100 total points
ID: 22669826
Here is an example to play a wave file from MS:
LVL 55

Accepted Solution

Jaime Olivares earned 150 total points
ID: 22669887
IntPtr represents a pointer, that obviuosly point to a non-managed resource (since managed environment don't use pointers but references). Also can represent an arbitrary 32-bit value like a resource handle (hWnd, hProcess, etc.)
So, IntPtr can be used when invoking a non-managed function like Platform (WinAPI) invoking.
Some related articles with real examples:

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question