intptr

Is it necessary to utilize the IntPtr constructor to set an IntPtr to equal another IntPtr?

不打扰是莪最后的温柔 提交于 2021-02-11 12:23:42
问题 I am currently refactoring an application to 64 bit and I am trying to understand a specific use of the IntPtr. The code that I am trying to understand is in the form of: IntPtr a = Marshal.AllocHGlobal(SomeObjectSize); //SomeObjectSize is calculated based on some standard IntPtr b = IntPtr(a.ToInt32()); Now at first blush I figured I could just change a.ToInt32() to a.ToInt64() , which worked for instances where an int needed to go into an IntPtr , but since a and b are both IntPtr types,

C# how to get Byte[] from IntPtr

家住魔仙堡 提交于 2020-05-09 19:23:31
问题 I have a .dll(not my own) that has a delegate. This delegate Callback function is: "CallBackFN(ushort opCOde, IntPtr payload , uint size, uint localIP)" How can i convert IntPtr to Byte[]? I think that payload is actually Byte[]. If it's not Byte[] and it's something else would i lose some data? 回答1: Have you looked into Marshal.Copy? http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.copy.aspx 回答2: If it's a byte[] array: byte[] managedArray = new byte[size];

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

三世轮回 提交于 2020-01-21 07:21:04
问题 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 its (base address + memory size). I'm testing this on a process with a known value at a known address. When I look up that specific address, I get the value I expect. However, when I scan (what I believe to be) all address space used by the

C# Proper Disposing of Structure with Char*

吃可爱长大的小学妹 提交于 2020-01-05 04:07:26
问题 I'm quite new to C# and I'm having trouble releasing unmanaged resource. For the function CharPtrToString, is it necessary to release IntPtr? In addition, would it be safe to call List < MyStruct >.clear() without causing a memory leak? public string CharPtrToString(MycharArray chararray) { IntPtr ipp = (IntPtr)chararray; string s = Marshal.PtrToStringAnsi(ipp) //need to free Ipp? return s; } public struct MyStruct { public Int int1; public MyCharArray charArray; } public unsafe struct

IntPtr addition

♀尐吖头ヾ 提交于 2020-01-03 03:04:13
问题 So from what I can tell, every managed example of IntPtr addition I have found is WRONG . For example: http://www.atalasoft.com/cs/blogs/stevehawley/archive/2006/10/16/10987.aspx My thought being, that if IntPtr is at (or near) int32.MaxValue on a 32-bit system, and you add an offset which overflows int32, isn't that still a valid memory address (as it would be valid in uint32, and would be represented by a negative number in IntPtr)?! I believe the code should be something like: public

It is possible to get an IntPtr from an int[] array?

前提是你 提交于 2019-12-30 17:35:27
问题 Greetings. In C#: If I have an int[] array declared like this int[] array = new array[size]; there is an way to get the IntPtr from this array? The thing is that I'm using the EmguCV framework, and there is an constructor to create an image which takes an IntPtr to the pixel data, in order to build an image from an array (int[]). Image<Gray,Int32> result = new Image<Gray,int>(bitmap.Width,bitmap.Height,stride,"**array.toPointer??**"); By the way if someone could told me how to calculate the

Can IntPtr be cast into a byte array without doing a Marshal.Copy?

回眸只為那壹抹淺笑 提交于 2019-12-29 04:14:12
问题 I want to get data from an IntPtr pointer into a byte array. I can use the following code to do it: IntPtr intPtr = GetBuff(); byte[] b = new byte[length]; Marshal.Copy(intPtr, b, 0, length); But the above code forces a copy operation from IntPtr into the byte array. It is not a good solution when the data in question is large. Is there any way to cast an IntPtr to a byte array? For example, would the following work: byte[] b = (byte[])intPtr This would eliminate the need for the copy

C# Process.MainWindowHandle always returns IntPtr Zero

让人想犯罪 __ 提交于 2019-12-28 03:00:12
问题 this is my code: using (Process game = Process.Start(new ProcessStartInfo() { FileName="DatabaseCheck.exe", RedirectStandardOutput = true, CreateNoWindow = true, UseShellExecute = false })) { lblLoad.Text = "Loading"; int Switch = 0; while (game.MainWindowHandle == IntPtr.Zero) { Switch++; if (Switch % 1000 == 0) { lblLoad.Text += "."; if (lblLoad.Text.Contains("....")) lblLoad.Text = "Loading."; lblLoad.Update(); game.Refresh(); } } Problem is, that game.MainWindowHandle is always IntPtr

Refreshing a folder that doesn't exist in the file system

偶尔善良 提交于 2019-12-25 04:12:17
问题 In my shell extension I have folders that don't actually exist in the file system, but only appear so to the user. When the content of those folders is changed, I want to refresh them, and currently I do it in the same method I do for regular folders: Win32.SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_IDLIST | SHCNF_FLUSH, PIDL, IntPtr.Zero); Whereas PIDL is a list of shell folders IDs, as required by SHCNF_IDLIST . The problem is that explorer doesn't handle my non existing folders. Instead of

How to pass IntPtr between process/apps

我与影子孤独终老i 提交于 2019-12-24 16:46:04
问题 I have got 2 application. One of them is a WPF app and another is sys tray app. The first one should somehow pass to another one his window pointer IntPtr IntPtr thisWindowHandle = (new WindowInteropHelper(this)).Handle; And the second one should accept it and detect the active screen of WPF app. Screen activeScreen = Screen.FromHandle(thisWindowHandle); My question is how we can send IntPtr between those apps and is it possible to do at all? Thank you! 回答1: It is possible, window handles can