intptr

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

六月ゝ 毕业季﹏ 提交于 2019-12-01 03:51:23
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 = User32.FindWindow(null, "Name") , is there a case where that handle might be invalidated by the .NET runtime? EDIT I need to know the handles because I want to use SendMessage and WM_COPYDATA and the like for IPC. A window handle is guaranteed to be valid and not get reused for as long as the window lives. It's index like in nature, valid

What do LRESULT, WPARAM and LPARAM mean?

柔情痞子 提交于 2019-11-30 12:41:48
问题 I'm importing WinApi functions, writing callbacks etc. (example) in C# and always wonder: what do they mean ? LRESULT as last result ? W-PARAM ? L-PARAM ? how to safely "wrap" them WPARAM and LPARAM contain structs sometimes. So I need to use them as IntPtr . How about LRESULT ? Am I safe with int or better IntPtr ? What type do I use for LRESULT in C# ? int or IntPtr ? 回答1: That's Charles Simonyi, the former head of the Application Software group at Microsoft, the group that developed Word

Win api in C#. Get Hi and low word from IntPtr

北慕城南 提交于 2019-11-30 11:37:30
问题 I am trying to process a WM_MOUSEMOVE message in C#. What is the proper way to get an X and Y coordinate from lParam which is a type of IntPtr? 回答1: Try: (note that this was the initial version, read below for the final version) IntPtr xy = value; int x = unchecked((short)xy); int y = unchecked((short)((uint)xy >> 16)); The unchecked normally isn't necessary (because the "default" c# projects are unchecked) Consider that these are the definitions of the used macros: #define LOWORD(l) ((WORD)(

unsigned char ** equivalent in c# and have to write the return value in a file

六月ゝ 毕业季﹏ 提交于 2019-11-30 09:37:16
问题 I have to call a win32 dll function int func1( int arg1, unsigned char **arg2, int *arg3); and i need wrapped in c# as public extern int fuc1(int arg1, out IntPtr arg2, out IntPtr arg3); and i called it from a c# application as int arg1; IntPtr arg2 = IntPtr.Zero; IntPtr arg3 = IntPtr.Zero; func1(arg1,out arg2,out arg3); Is the function declared in the c# wrapper as well as called in C# test app Correct ? Now i need to store the arg2 in a text file. How to do that. Got answer from Hans and i

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

拟墨画扇 提交于 2019-11-30 09:19:37
问题 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 XC_GetFrame(Int32 h, FrameType type, ulong ulFlags, IntPtr buff, uint size); and then using it here: if (XC_GetFrame(myCam, XC_GetFrameType(myCam), 0, IntPtr.Zero, (uint)fs) != ErrorCode.E_NO_FRAME) However, when I run this in .NET 4.0 I get a P/INVOKE

Correct way to marshal SIZE_T*?

限于喜欢 提交于 2019-11-30 06:38:34
I have the following C++ function definition, which I am trying to call through PInvoke from managed code: bool FooBar(SIZE_T* arg1); My managed declaration looked as follows: [DllImport("mydll", SetLastError=true, CharSet=CharSet.Unicode)] private static extern bool FooBar(ref uint arg1); Some of you may notice the same bug I eventually did. This is not 64bit portable. SIZE_T is of variable size (32-64 bit) as is the pointer to it. On the managed size the pointer correctly translates to 64bit, but the uint does not, and you can end up with trash in the upper bits of arg1. This was an

What do LRESULT, WPARAM and LPARAM mean?

二次信任 提交于 2019-11-30 03:23:32
I'm importing WinApi functions, writing callbacks etc. ( example ) in C# and always wonder: what do they mean ? LRESULT as last result ? W-PARAM ? L-PARAM ? how to safely "wrap" them WPARAM and LPARAM contain structs sometimes. So I need to use them as IntPtr . How about LRESULT ? Am I safe with int or better IntPtr ? What type do I use for LRESULT in C# ? int or IntPtr ? Hans Passant That's Charles Simonyi, the former head of the Application Software group at Microsoft, the group that developed Word and Excel. He's the one that set identifier naming standards. Since nobody knows how to

.NET Interop IntPtr vs. ref

浪尽此生 提交于 2019-11-30 02:25:08
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, int msg, int wParam, IntPtr lParam); And use them like this: IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(formatrange)); Marshal.StructureToPtr(formatrange, lParam, false); int returnValue = User32.SendMessage(_RichTextBox.Handle, ApiConstants.EM_FORMATRANGE, wParam, lParam); Marshal.FreeCoTaskMem(lParam); Rather than creating a targeted

Win api in C#. Get Hi and low word from IntPtr

。_饼干妹妹 提交于 2019-11-30 00:34:26
I am trying to process a WM_MOUSEMOVE message in C#. What is the proper way to get an X and Y coordinate from lParam which is a type of IntPtr? Try: (note that this was the initial version, read below for the final version) IntPtr xy = value; int x = unchecked((short)xy); int y = unchecked((short)((uint)xy >> 16)); The unchecked normally isn't necessary (because the "default" c# projects are unchecked) Consider that these are the definitions of the used macros: #define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff)) #define HIWORD(l) ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff)) #define GET_X

unsigned char ** equivalent in c# and have to write the return value in a file

做~自己de王妃 提交于 2019-11-29 16:11:11
I have to call a win32 dll function int func1( int arg1, unsigned char **arg2, int *arg3); and i need wrapped in c# as public extern int fuc1(int arg1, out IntPtr arg2, out IntPtr arg3); and i called it from a c# application as int arg1; IntPtr arg2 = IntPtr.Zero; IntPtr arg3 = IntPtr.Zero; func1(arg1,out arg2,out arg3); Is the function declared in the c# wrapper as well as called in C# test app Correct ? Now i need to store the arg2 in a text file. How to do that. Got answer from Hans and i wrote it in a file using System.IO.StreamWriter(@Application.StartupPath + "\\Filename.txt"); file