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
7
votes
1 answer

gdip image save directly intptr in my local drive

I have this code to get the image file from the scanner and save it on local disk: IntPtr img = (IntPtr)pics[i]; SetStyle(ControlStyles.DoubleBuffer, false); …
Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180
7
votes
3 answers

IntPtr and avoiding unsafe code

I have an external library that takes an IntPtr. Is there any safe way to do this... int BytesWritten = 0; Output.WriteBytes(buffer, new IntPtr(&BytesWritten)); ...without having to use 'unsafe' code? I'm not that familiar with IntPtrs, but I'd…
Aric TenEyck
  • 8,002
  • 1
  • 34
  • 48
7
votes
1 answer

Convert/Cast String (from a textbox) to IntPtr C#

I have a textbox where I want to input (manually) a Handle (https://i.stack.imgur.com/4Zzrt.png) My problem: to get the value from the textbox I need to do this: textBoxHandle.Text; but when I initialize my Handle as IntPtr (handle), this doesn't…
сами J.D.
  • 483
  • 2
  • 5
  • 19
7
votes
1 answer

How to get an IntPtr to access the view of a MemoryMappedFile?

Is there a way to get a direct IntPtr to the data in a MemoryMappedFile? I have large data block with high frequency change and I don't want to copy it
ittay
  • 519
  • 5
  • 15
7
votes
2 answers

IntPtr allow implicit conversion from ulong to long

class A { public static explicit operator A(long mm) { return null; } } UInt64 ul = UInt64.MaxValue; IntPtr ptr = (IntPtr)ul;//no error A a = (A)ul;//Cannot convert type 'ulong' to 'A' why do IntPtr allow the behavior? following…
Vince
  • 896
  • 5
  • 18
7
votes
5 answers

IntPtr arithmetics

I tried to allocate an array of structs in this way: struct T { int a; int b; } data = Marshal.AllocHGlobal(count*Marshal.SizeOf(typeof(T)); ... I'd like to access to allocated data "binding" a struct to each element in array allocated with…
Luca
  • 11,646
  • 11
  • 70
  • 125
7
votes
1 answer

IntPtr.ToInt32() and x64 systems

In my c# dll I have some code like this to interact with some unmanaged dlls: IntPtr buffer = ...; TTPOLYGONHEADER header = (TTPOLYGONHEADER)Marshal.PtrToStructure( new IntPtr(buffer.ToInt32() + index),…
devdept2
  • 71
  • 1
  • 2
6
votes
2 answers

How to convert byte[] array to IntPtr?

Possible Duplicate: How to get IntPtr from byte[] in C# I'm reading strings from memory with byte[] array = reader.ReadProcessMemory((IntPtr)address, (uint)255, out bytesReadSize); and then I'm converthing this array to string. I've got a…
Patryk
  • 3,042
  • 11
  • 41
  • 83
6
votes
1 answer

How to get all memory address space used by a process?

I need to know all memory address space used by a process. The memory space will later be scanned to locate values within the process and identify their locations / addresses. My current process for this is to take each module's base address through…
tsilb
  • 7,977
  • 13
  • 71
  • 98
6
votes
5 answers

Why can't we do IntPtr and UIntPtr arithmetic in C#?

It's a simple-looking question: Given that native-sized integers are the best for arithmetic, why doesn't C# (or any other .NET language) support arithmetic with the native-sized IntPtr and UIntPtr? Ideally, you'd be able to write code like: for…
user541686
  • 205,094
  • 128
  • 528
  • 886
6
votes
2 answers

IntPtr to Byte Array and Back

Referencing How to get IntPtr from byte[] in C# I am attempting to read the data that an IntPtr is referencing into a byte [] and then back into another IntPtr. The pointer is referencing an image captured from a scanner device so I have also made…
Scruffy The Janitor
  • 472
  • 3
  • 5
  • 13
6
votes
1 answer

How to marshal int* in C#?

I would like to call this method in unmanaged library: void __stdcall GetConstraints( unsigned int* puiMaxWidth, unsigned int* puiMaxHeight, unsigned int* puiMaxBoxes ); My solution: Delegate…
MartyIX
  • 27,828
  • 29
  • 136
  • 207
6
votes
1 answer

Marshal.Copy, copying an array of IntPtr into an IntPtr

I can't figure out how does the Copy(IntPtr[], Int32, IntPtr, Int32) method works. I though it could copy the data contained in multiple IntPtrs into a single IntPtr (as MSDN states) but apparently it doesn't work as I expected: IntPtr[] ptrArray =…
mainvoid
  • 347
  • 1
  • 4
  • 17
6
votes
3 answers

How to wait for the first of the 2: a process and an EventWaitHandle

I want to WaitForMultipleObjects on 2 different types: an 'EventWaitHandle' a 'Process.Handle' ==> intptr I don't know how to convert (in the appropriate way) "process.Handle" to a WaitHandle in order to have the following code working: var…
Eric Ouellet
  • 10,996
  • 11
  • 84
  • 119
6
votes
1 answer

why is it not possible to compare IntPtr.Zero and default(IntPtr)?

I just learned the hard way that IntPtr.Zero cannot be compared to default(IntPtr). Can someone tell me why? IntPtr.Zero == new IntPtr(0) -> "could not evaluate expression" IntPtr.Zero == default(IntPtr) --> "could not evaluate…
John Smith
  • 4,416
  • 7
  • 41
  • 56
1 2
3
19 20