Questions tagged [intptr]

IntPtr is a .NET Framework platform-specific type that is used to represent a pointer or a handle.

IntPtr is a .NET Framework platform-specific type that is used to represent a pointer or a handle.

296 questions
16
votes
3 answers

Which is better/safer to use: HandleRef or IntPtr (newer source code from Microsoft no longer uses HandleRef)

For example, in the old .NET Framework 2.0 Source Code (Windows Forms, Visual Studio 2005 - Whidbey), the GetClientRect function was defined using HandleRef: [DllImport(ExternDll.User32, ExactSpelling=true, CharSet=CharSet.Auto)] public…
TechAurelian
  • 5,561
  • 5
  • 50
  • 65
16
votes
3 answers

C# Process.MainWindowHandle always returns IntPtr Zero

this is my code: using (Process game = Process.Start(new ProcessStartInfo() { FileName="DatabaseCheck.exe", RedirectStandardOutput = true, CreateNoWindow = true, UseShellExecute = false })) { …
Kfir Eichenblat
  • 449
  • 2
  • 8
  • 27
14
votes
3 answers

Difference between IntPtr and UIntPtr

I was looking at the P/Invoke declaration of RegOpenKeyEx when I noticed this comment on the page: Changed IntPtr to UIntPtr: When invoking with IntPtr for the handles, you will run into an Overflow. UIntPtr is the right choice if you wish this to…
xxbbcc
  • 16,930
  • 5
  • 50
  • 83
12
votes
2 answers

It is possible to get an IntPtr from an int[] array?

Greetings. In C#: If I have an int[] array declared like this int[] array = new array[size]; there is an way to get the IntPtr from this array? The thing is that I'm using the EmguCV framework, and there is an constructor to create an image which…
João Cardoso
  • 351
  • 3
  • 5
  • 13
12
votes
5 answers

.NET Interop IntPtr vs. ref

Probably a noob question but interop isn't one of my strong points yet. Aside from limiting the number of overloads is there any reason I should declare my DllImports like: [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd,…
Cory Charlton
  • 8,868
  • 4
  • 48
  • 68
11
votes
1 answer

error: unknown type name 'intptr_t'

I am receiving this error while compiling a C program in MinGW. As far as I know, I thought 'intptr_t' was a type in the C99 standard. Am I not including a file?
liamzebedee
  • 14,010
  • 21
  • 72
  • 118
10
votes
2 answers

How to get window's position?

I'd like to know the way of getting process'es window position. I've been looking for that on the internet but with no results. Thanks :) Process[] processes = Process.GetProcessesByName("notepad"); Process lol = processes[0]; IntPtr p =…
Patryk
  • 3,042
  • 11
  • 41
  • 83
10
votes
3 answers

Convert an array of pointers to an array of IntPtr

I'm stuck on a seemingly trivial task and need your help. I need to write a method with the following signature: System.Array ToIntPtrArray(System.Array a) where an actual argument can be an array of any pointer type (e.g. int*[], long**[],…
Peter Smolensky
  • 101
  • 1
  • 5
9
votes
1 answer

Can't add an IntPtr and an Int

I have this lines in C# Visual Studio 2010: IntPtr a = new IntPtr(10); IntPtr b = a + 10; And it says: Operator '+' cannot be applied to operands of type 'System.IntPtr' and 'int'. MSDN says that this operation should work.
Sp3ct3R
  • 715
  • 1
  • 12
  • 24
9
votes
6 answers

what is intptr?

I didn't understand what is IntPtr, could someone explain this? thanks
lital maatuk
  • 5,921
  • 20
  • 57
  • 79
8
votes
3 answers

GetPhysicalMonitorsFromHMONITOR returned handle is always null

On the Media Foundation SDK there is the GetPhysicalMonitorsFromHMONITOR function that I am trying to implement using C# but with no luck ... In the returned PHYSICAL_MONITOR[], the function returns the string description of the monitor but for some…
Aybe
8
votes
1 answer

Can a Window Handle in .NET change it's value?

During the lifetime of a .NET process, does the handle of a System.Windows.Forms.Form, lets say the main form used in Application.Run(form) actually change it's value, i.e. if using the value of the handle in a different process, e.g. IntPtr handle…
Sebastian
  • 6,293
  • 6
  • 34
  • 47
8
votes
2 answers

What are handles for? IntPtr

I have been reading up on IntPtr and have read that it is used to represent a Handle(s). What does this mean exactly? I'm sure it is a simple explanation, but the light bulb is just not turning on at the moment..
LunchMarble
  • 5,079
  • 9
  • 64
  • 94
8
votes
4 answers

Why doesn't IntPtr need the unsafe keyword?

When you use a pointer like int* in C#, you need to use the unsafe keyword, but when you use an IntPtr, you don't. What is the difference of these? They both can point to an address. How does the garbage collector deal with these two types? Are they…
hattenn
  • 4,371
  • 9
  • 41
  • 80
7
votes
2 answers

How to convert an IntPtr back into an object

All, this is a follow up from a previous question here: C# formatting external Dll function parameters Here specifically is the code that I am trying to convert to C#: FILES_GetMemoryMapping((LPSTR)(LPCTSTR)MapFile, &Size, (LPSTR)MapName,…
Nick
  • 2,913
  • 12
  • 40
  • 52
1
2
3
19 20