Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

usage of System.IntPtr

Posted on 2008-10-08
6
Medium Priority
?
1,199 Views
Last Modified: 2013-11-05
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
Comment
Question by:xRalf
[X]
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
6 Comments
 
LVL 15

Expert Comment

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

Author Comment

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

Expert Comment

by:angus_young_acdc
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);
MessageBox.Show(ok.ToString());
g.ReleaseHdc (bmDC);
}
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Author Comment

by:xRalf
ID: 22669547
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
 
LVL 15

Assisted Solution

by:angus_young_acdc
angus_young_acdc earned 400 total points
ID: 22669826
Here is an example to play a wave file from MS:

http://msdn.microsoft.com/en-us/library/ms173187(VS.80).aspx
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 600 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:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

688 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