Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1204
  • Last Modified:

usage of System.IntPtr

Hello,

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."

thanks
0
xRalf
Asked:
xRalf
  • 3
  • 2
2 Solutions
 
angus_young_acdcCommented:
Its a method of referring between different development languages, and for handles such as FileStream (it will hold the file handles).
0
 
xRalfAuthor Commented:
Try to send some minimalistic code snippet that will do something useful...
0
 
angus_young_acdcCommented:
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);
MessageBox.Show(ok.ToString());
g.ReleaseHdc (bmDC);
}
}
0
Industry Leaders: 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!

 
xRalfAuthor Commented:
Thanks,

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.
0
 
angus_young_acdcCommented:
Here is an example to play a wave file from MS:

http://msdn.microsoft.com/en-us/library/ms173187(VS.80).aspx
0
 
Jaime OlivaresSoftware ArchitectCommented:
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:
http://www.codeproject.com/KB/cs/unmanaged_memory_pointers.aspx
http://www.ondotnet.com/pub/a/dotnet/2002/02/18/cominterop.html
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now