intptr

How to get window's position? [duplicate]

被刻印的时光 ゝ 提交于 2019-11-27 01:57:53
问题 This question already has an answer here: How to get and set the window position of another application in C# 4 answers I'd like to know the way of getting process'es window position. I've been looking for that on the internet but with no results. Thanks :) Process[] processes = Process.GetProcessesByName("notepad"); Process lol = processes[0]; IntPtr p = lol.MainWindowHandle; 回答1: Try this: [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr FindWindow(string

Using intptr_t instead of void*?

前提是你 提交于 2019-11-26 22:33:08
Is it a good idea to use intptr_t as a general-purpose storage (to hold pointers and integer values) instead of void* ? (As seen here: http://www.crystalspace3d.org/docs/online/manual/Api1_005f0-64_002dBit-Portability-Changes.html ) For what I've already read: int -> void* -> int roundtrip is not guaranteed to hold original value; I guess int -> intptr_t -> int will do pointer arithmetics on both void* and intptr_t require casts, so none gets advantage here void* means less explicit casts when storing pointers, intptr_t means less casts when storing integer values intptr_t requires C99 What

Just what is an IntPtr exactly?

心不动则不痛 提交于 2019-11-26 16:55:39
Through using IntelliSense and looking at other people's code, I have come across this IntPtr type; every time it has needed to be used I have simply put null or IntPtr.Zero and found most functions to work. What exactly is it and when/why is it used? It's a "native (platform-specific) size integer." It's internally represented as void* but exposed as an integer. You can use it whenever you need to store an unmanaged pointer and don't want to use unsafe code. IntPtr.Zero is effectively NULL (a null pointer). Daniel Earwicker It's a value type large enough to store a memory address as used in

C# - How To Convert Object To IntPtr And Back?

六眼飞鱼酱① 提交于 2019-11-26 13:09:18
问题 I want to pass an object from managed code to a WinApi function as IntPtr . It will pass this object back to my callback function in managed code as IntPtr . It\'s not a structure, it\'s an instance of a class. How do I convert object to IntPtr and back ? 回答1: So if I want to pass a list to my callback function through WinApi I use GCHandle // object to IntPtr (before calling WinApi): List<string> list1 = new List<string>(); GCHandle handle1 = GCHandle.Alloc(list1); IntPtr parameter = (IntPtr

Why / when to use `intptr_t` for type-casting in C?

你说的曾经没有我的故事 提交于 2019-11-26 10:18:22
问题 I have a question regarding using intptr_t vs. long int . I\'ve observed that incrementing memory addresses (e.g. via manual pointer arithmetic) differs by data type. For instance incrementing a char pointer adds 1 to the memory address, whereas incrementing an int pointer adds 4, 8 for a double, 16 for a long double, etc... At first I did something like this: char myChar, *pChar; float myFloat, *pFloat; pChar = &myChar; pFloat = &myFloat; printf( \"pChar: %d\\n\", ( int )pChar ); printf( \

Just what is an IntPtr exactly?

廉价感情. 提交于 2019-11-26 04:59:02
问题 Through using IntelliSense and looking at other people\'s code, I have come across this IntPtr type; every time it has needed to be used I have simply put null or IntPtr.Zero and found most functions to work. What exactly is it and when/why is it used? 回答1: It's a "native (platform-specific) size integer." It's internally represented as void* but exposed as an integer. You can use it whenever you need to store an unmanaged pointer and don't want to use unsafe code. IntPtr.Zero is effectively