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

How to convert IntPtr/Int to Socket?

I want to convert message.WParam to Socket. protected override void WndProc(ref Message m) { if (m.Msg == Values.MESSAGE_ASYNC) { switch (m.LParam.ToInt32()) { case Values.FD_READ: …
Ivan Prodanov
  • 34,634
  • 78
  • 176
  • 248
5
votes
2 answers

C# out IntPtr equivalent in Java

I have a methods in C# which I call from .dll [DllImport("somedll.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int find([MarshalAs(UnmanagedType.AnsiBStr, SizeConst = 64)] string atr, out IntPtr…
vuis
  • 53
  • 1
  • 6
5
votes
2 answers

What does IntPtr.Zero mean in System.Drawing.Graphics

I need to get the exact meaning of IntPtr.Zero in below function. I used this function for convert word document text range position pixel value to WPF unit value. Graphics g = Graphics.FromHwnd(IntPtr.Zero) That normally said to pass the…
KIS
  • 129
  • 1
  • 10
5
votes
2 answers

PostMessage unable to pass a string C#

Here is my prototype: [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern bool PostMessage(int hhwnd, uint msg, IntPtr wparam, IntPtr lparam); And here is how I'm using it: PostMessage(HWND_BROADCAST, msg,…
Nick
  • 2,913
  • 12
  • 40
  • 52
5
votes
1 answer

Equivalent of (IntPtr)1 in VBNET?

I've taken a piece of code from a @Hans Passant code from here: Bold text in MessageBox this is the C# code: SendMessage(hText, WM_SETFONT, mFont.ToHfont(), (IntPtr)1) Which would be the translation into vb.net? This will not work (cant be…
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
5
votes
2 answers

C# - Emgu cv How to load an image from a folder using CvInvoke.cvLoadImage("ClassPic1.jpg") as intptr and access it

How to load an image from a specific folder using Emgu cv CvInvoke.cvLoadImage(...)?I am tryng to do it like this IntPtr inputImage = CvInvoke.cvLoadImage("C:\\Users\\...\\ClassPic1.jpg"); Is that ok? If so, How am i gonna access it later as an…
Sisay
  • 681
  • 7
  • 16
  • 31
5
votes
2 answers

How to allocate array of IntPtr [] in unmanaged memory?

To allocate memory in managed code i use: IntPtr [] params_list_n = new IntPtr [5]; But for unmanaged memory i use Marshal.AllocHGlobal And I do not understand how, in this case to allocate memory for the array. Ideally I want to use the function…
Mixer
  • 1,292
  • 3
  • 22
  • 41
5
votes
1 answer

Why IntPtr.ToInt32 throws OverflowException in 64 bit mode and Explicit(IntPtr to Int32) doesn't

The operator's description on MSDN has a remark: An exception is only thrown if the value of value requires more bits than the current platform supports. while ToInt32's description doesn't so I suppose the title is not entirely correct(for…
axk
  • 5,316
  • 12
  • 58
  • 96
4
votes
3 answers

PInvokeStackImbalance exception when using IntPtr in .NET 4? (Works in .NET 3.5)

Might be a bit of noob question but it's something that's been getting me in a pickle for the past few hours (or days)... I'm calling a method from a DLL in my code in .NET Framework 4.0 [DllImport("xeneth.dll")] public static extern ErrorCode…
Haden693
  • 174
  • 1
  • 8
4
votes
2 answers

Can't change DEVMODE of a printer

I need to change DEVMODE of printer for current printing task to pass standard and device-specific settings. I do the following: PrintDocument d = new PrintDocument(); d.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"; // example…
Bogdan Verbenets
  • 25,686
  • 13
  • 66
  • 119
4
votes
4 answers

DLLImport -> how to handle a HANDLE in C#

in my C# code I want to import a C++ DLL. I use the dllimport and it works fine with a some of the functions. But in one function I get a HANDLE which I need later to call another function. [DllImport("SiUSBXp.dll")] public static extern int…
Toby
  • 43
  • 1
  • 1
  • 4
4
votes
1 answer

What is the difference between IntPtr and Marshal.ReadIntPtr?

I did like to understand what is the difference between: new IntPtr(pointer.ToInt64() + 0x4); and Marshal.ReadIntPtr(pointer + 0x4); They give out a different result but does it not do the same thing? If possible could you provide a practical…
Guapo
  • 3,446
  • 9
  • 36
  • 63
4
votes
1 answer

Is GCHandleType.Pinned similar to using "fixed" keyword?

I'm experimenting with IntPtr in "safe" code, comparing it to how things are done in the "unsafe" mode. Is GCHandleType.Pinned similar to using "fixed" in unsafe mode? GCHandle pinnedArray = GCHandle.Alloc(byteArray, GCHandleType.Pinned); IntPtr…
makerofthings7
  • 60,103
  • 53
  • 215
  • 448
4
votes
1 answer

Converting a structure to an intptr

I have a class definition as follows: [StructLayout(LayoutKind.Sequential)] public class OUR_MEM_STR { public byte[] p; public int len; }; This is an equivalent defintion of the C structure…
Tyler Durden
  • 1,188
  • 2
  • 19
  • 35
4
votes
1 answer

User created pixel byte array does not appear to update correctly (WPF)

I have a system where I am able to collect 8-bit Gray images from a camera, place the data into a WriteableBitmap and display the images on a WPF Image object. This work happens in a camera thread. I used this article to help me: How to create a…
CDitchman
  • 65
  • 5