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
4
votes
2 answers

Pointer to function for unmanaged code in C#

I have a dll which accepts a struct that contains a pointer to a function to do a callback. How can I get an IntPtr to a function of my application to build the struct? [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public…
Sergi
  • 85
  • 1
  • 4
4
votes
1 answer

Passing strings to c dll from C#

I have some trouble using a c dll in a c# application. The function which gives me an error is defined in the header file of the dll like this: int __stdcall DDC_CreateFilePropertyString (DDCFileHandle file, …
Devkev
  • 119
  • 1
  • 1
  • 5
4
votes
2 answers

How to convert a Bitmap Image to IntPtr in C#?

I made this from an example i saw, it never threw any error, but the image is displayed as grey. Is there a better way to do this? private unsafe void menuItem7_Click(object sender, EventArgs e) { var settings =…
Martin Ongtangco
3
votes
1 answer

How to "fill" an IntPtr parameter with a float value?

I am using dllImport to use a C library in C# .NET. One of the methods in this library uses data type void* as parameter. I found out, that I can use the data type IntPtr in C# matching the void*. Now I simply don't know how to set the value of…
Simone Frank
3
votes
1 answer

Convert IntPtr to int* in C#?

I have a C++ DLL returning an int* to a C# program. The problem is the int* in C# remains null after the assignment. When I assign the C++ result to an IntPtr, I get a correct non-null value. However any attempt to convert this to an int* results…
user20493
  • 5,704
  • 7
  • 34
  • 31
3
votes
2 answers

Convert double[,] to IntPtr C#

I need to convert a double array in c# to an IntPtr to properly send it to my c DLL. I have successfully been able to convert from IntPtr to double[,] using the method from this answer. Ive also found another answer that is close to what I need but…
3
votes
0 answers

Marshalling a variable from int to struct in 64X

When my application is running on x86 the program works fine. When I run it on x64, the Access Violation exception occurs. Exception details mentioned below. "System.AccessViolationException: 'Attempted to read or write protected memory. This is…
3
votes
3 answers

How can I get IntPtr pointer from object

I'm working on a finger-print device, the manufacture (Upek) gave me a c++ BSAPI.dll so I need to use wrappers to get this to work in .net. I'm able to work with it all from in-memory, I could grab and match the finger prints. Now I'm stuck trying…
Ezi
  • 2,212
  • 8
  • 33
  • 60
3
votes
1 answer

IntPtr causing memory leak?

This function is in a loop. When I run the program, the line with IntPtr is giving me memory problems, I've put delete[], but it still doesn't solve the memory problem, can anyone help please? thanks void showImage(IplImage…
Qmage
  • 289
  • 4
  • 13
3
votes
1 answer

How to get byte[] from IntPtr in C#

I want to pass a IntPtr to a method takes a byte[] Parameter in c#. Is that possible and if it is possible how can I do that? thx
user594810
  • 149
  • 4
  • 9
3
votes
1 answer

Is default(IntPtr) legal in an extern function?

Let's say I have the following signature: static extern void External(int foo, IntPtr bar); I want to make it use defaults: static extern void External(int foo = 10, IntPtr bar = default(IntPtr)); Is this valid? In C++, I would use the pointer to…
Lazlo
  • 8,518
  • 14
  • 77
  • 116
3
votes
1 answer

Interop question about passing a struct by ref, null pointer and IntPtr

Colleagues, Preamble. My question is more about best practices. I know one workaround. This is the first time I have to deal with interop in C#, at the same time I’ve written a fair amount of code in C and C++. I need to invoke 2 times a…
Nick Alexeev
  • 1,688
  • 2
  • 22
  • 36
3
votes
1 answer

How do I marshal a wstring * in C#?

I have a function in C++, _GetFileList, that I am trying to get to return a list/array of strings to C# code. I am not married to wstring * or any other type, this is just how the example I had found did it, but I am trying to get it to return a…
WWZee
  • 494
  • 2
  • 8
  • 23
3
votes
2 answers

The new IntPtr.Add method - am I missing the point of the int?

Starting from FW 4.0, the IntPtr structure has the Add method: public static IntPtr Add( IntPtr pointer, int offset ) Which is great, as it's supposed to address all those questions on IntPtr math we have had (1, 2, probably more). But why…
GSerg
  • 76,472
  • 17
  • 159
  • 346
3
votes
1 answer

Do I need to release an IntPtr inside a callback?

I'm Marshalling data across C/C# boundary. I have the following structure: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct Message { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string From; …
Eternal21
  • 4,190
  • 2
  • 48
  • 63