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
3
votes
0 answers

Moving to .Net 4.6 caused an overflow exception

I have several projects (managed and unmanaged) which run on 32 and 64 bit operating systems with .Net 4.0 for a long time. When we upgraded to .Net 4.6 (4.0 --> 4.6) and run this code: Marshal.PtrToStructure(DataInfo, info); DataInfo =…
Kfir Nuna
  • 31
  • 1
3
votes
0 answers

A pointer type static field's value is displayed as zero 0x0 by the debugger while it actually has a valid value

I came across this behaviour while trying to access the value of a struct's static field with type uint* While debugging, watch window shows the static field StaticBitMask's value as zero, but actually (and as expected) it is a valid pointer, and…
Oguz Ozgul
  • 6,809
  • 1
  • 14
  • 26
3
votes
2 answers

Tell if IntPtr points to managed or unmanaged memory

I'm using a wrapped C-library in C# and need to convert an image from that library to a Bitmap and back, but without copying the pixel buffer. Converting to a Bitmap was simple: Bitmap WrapAsBitmap(CImage image) { return new Bitmap(image.Width,…
huysentruitw
  • 27,376
  • 9
  • 90
  • 133
3
votes
1 answer

converting IntPtr as c# struct pointer

I have an unmanaged C++ function that reads like :int myfunction(LPVOID p1, LPVOID p2) My wrapper in C# takes extern static int mywrapperFunction(IntPtr p1, IntPtr p2) Within my wrapper function definition, i want to deference IntPtr to a…
Samer
  • 1,923
  • 3
  • 34
  • 54
3
votes
3 answers

C# - Converting IntPtr pointing to sockaddr structure to IPAddress

From a P/Invoked native function, I get an IntPtr which points to a sockaddr structure. How can I convert it to an IPAddress? Thanks!
kol
  • 27,881
  • 12
  • 83
  • 120
3
votes
1 answer

Cast IntPtr to CWPSTRUCT

In my c# project I’m trying to intercept mouse clicks from another program, but only the ones that come from a certain hwnd as well… I’ve read here that I can filter my messages using the lParam but I’ve not succeeded to cast it to something I can…
VincentC
  • 245
  • 4
  • 14
3
votes
4 answers

IntPtr cast vs. new

I was just looking at an example, and in it I saw the code return new IntPtr(handle); After poking around our code, I found that we have already used a similar pattern, but in our code we had almost the same thing: return (IntPtr)handle; Is…
Noam Gal
  • 3,315
  • 3
  • 36
  • 53
3
votes
3 answers

Access to 32bit memory address c#

I'm trying to access a 32bit address, but when i create the IntPtr it throws an OverflowException. Here's the code: uint memAddr = 0xF5920824; IntPtr bufPtr = new IntPtr(memAddr); byte[] data = new byte[4]; Marshal.Copy(bufPtr, data, 0, 4); How…
giuse
  • 337
  • 1
  • 2
  • 12
3
votes
0 answers

PInvoke C# to C++. Strange characters at the end of strings

I read almost all the questions on this topic but I still have no solution. This is the DLL function: int start(char* ipad, char* porta, char* codec, char* key_TX, char* key_RX){ FILE *myfile; myfile = fopen("parameters.txt", "w"); fprintf(myfile,…
hirish
  • 188
  • 9
2
votes
1 answer

Send content of memory pointed by an IntPtr into a MemoryStream variable on C#

Im new to this languaje. I think the question is very clear, i have an intptr received after calling a dll function and need to save the buffer that it points to into a MemoryStream variable. ¿how do i do it ?
Martin
  • 510
  • 1
  • 6
  • 15
2
votes
1 answer

C99: Will arrays or heap-allocated buffers ever end at UINTPTR_MAX?

Can I assume the following invariant? void foo(char *buf, size_t len) { // "buf" points to either an array or memory allocated with malloc(). assert((uintptr_t)(buf + len) < UINTPTR_MAX); } In a parser I am writing I want to mark certain…
Josh Haberman
  • 4,170
  • 1
  • 22
  • 43
2
votes
1 answer

Get the process id from a window handle without GetWindowThreadProcessId (c#.net 4.0)

Our application recently switched from .net 3.5 to .net 4. One issue that has cropped up is that GetWindowThreadProcessId no longer works. Microsoft have a hotfix available, but it would be a pain to have to install that on every customer machine,…
Sugrue
  • 3,629
  • 5
  • 35
  • 53
2
votes
2 answers

tinyfiledialogs how to save file in russian naming folder

I am using tinyfiledialogs lib and i am able to save files in folders which names are in English but when i try to save the exact same file in folder which name is like for example "Кот" in other words in Russian letter i could not. This is the…
So_oP
  • 1,211
  • 15
  • 31
2
votes
0 answers

SafeHandle vs IntPtr in WinAPIs and CloseHandle in C#

I read many articles about SafeHandle and IDiposable but I still don't understand whether I should use SafeHandle and CloseHandle or not in C#. MSDN SafeHandle example IntPtr, SafeHandle and HandleRef -…
nop
  • 4,711
  • 6
  • 32
  • 93
2
votes
1 answer

pinvoke: How to free an array of structures containing LPWSTR

Simplifying the problem, here is the native methods that I try to invoke from my .NET class. [NativeDll.dll] Header typedef struct _ADDRESS { LPWSTR City; } ADDRESS, *PADDRESS; typedef struct _ADDRESS_SET { ULONG AddressCount; PADDRESS…