pinvoke

Give a windows handle (Native), how to close the windows using C#?

点点圈 提交于 2021-02-20 09:27:45
问题 Given a handle of a window, how can I close the window by using the window handle? 回答1: The easiest way is to use PInvoke and do a SendMessage with WM_CLOSE . [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); private const UInt32 WM_CLOSE = 0x0010; void CloseWindow(IntPtr hwnd) { SendMessage(hwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero); } 回答2: Not sure if there is another way but you could PInvoke

Get type of binary on filesystem via C# running in 64 bit

和自甴很熟 提交于 2021-02-20 03:49:37
问题 I have a C# application, compiled in Visual Studio 2017 on the 'Any CPU' target, with the 'Prefer 32-bit' option disabled. In this application, I am trying to pinvoke kernel32!GetBinaryType(). When running with 'Prefer 32-bit' enabled, it works fine. When running in either 32 or 64-bit mode from a C++ executable, it works fine. I am not sure what I am doing wrong with the 64-bit C# application. This is my pinvoke signature: [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError =

Get type of binary on filesystem via C# running in 64 bit

拈花ヽ惹草 提交于 2021-02-20 03:47:04
问题 I have a C# application, compiled in Visual Studio 2017 on the 'Any CPU' target, with the 'Prefer 32-bit' option disabled. In this application, I am trying to pinvoke kernel32!GetBinaryType(). When running with 'Prefer 32-bit' enabled, it works fine. When running in either 32 or 64-bit mode from a C++ executable, it works fine. I am not sure what I am doing wrong with the 64-bit C# application. This is my pinvoke signature: [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError =

How To Create lParam Of SendMessage WM_KEYDOWN

为君一笑 提交于 2021-02-17 23:59:26
问题 I'm trying to use SendMessage to send a keystroke, and don't really understand the lParam. I understand that the different bits represent each parameter and that they need to be arranged in order. I've read this question & this, so I know which order the bits need to be in, I just don't know how to do it... How would I create the following lParam? repeat cound = 0, scan code = {Don't know what this is?}, extended key = 1, reserved = 0, context code = 0, previous key state = 1, transition

c# dllimport with pointers

寵の児 提交于 2021-02-17 01:59:15
问题 I have a dll that I cannot import in my vs2012 c# project. I have used dllImport before but I have never had to use Marshal or pointers before. Lucky me I guess. This is the code that I currently have. The function being called is fnLDA_GetDevInfo(DEVID *ActiveDevices) DEVID is a normal unsigned integer (#define DEVID unsigned integer) //Allocate an array big enough to hold the device ids for the number of devices present. //Call fnLDA_GetDevInfo(DEVID *ActiveDevices), which will fill in the

Passing pointer to pointer of array of structure from C# to C++

五迷三道 提交于 2021-02-17 00:01:12
问题 I want to pass pointer to pointer of an array of structure from C# to C++. With following code I only get the first element in c++, second and third element of the array is not passed. Why? Also, tried using StructureToPtr but didn't help. What I am doing wrong? C++ code struct structure { short ps; }; __declspec(dllexport)short Testmethod(structure** aa) { if (aa!= 0 && aa[0]->ps == 26 && aa[1]->ps == 27) { return 1; } return 0; } C# code [DllImport("Wrapper.dll", CallingConvention =

Passing pointer to pointer of array of structure from C# to C++

ε祈祈猫儿з 提交于 2021-02-17 00:00:16
问题 I want to pass pointer to pointer of an array of structure from C# to C++. With following code I only get the first element in c++, second and third element of the array is not passed. Why? Also, tried using StructureToPtr but didn't help. What I am doing wrong? C++ code struct structure { short ps; }; __declspec(dllexport)short Testmethod(structure** aa) { if (aa!= 0 && aa[0]->ps == 26 && aa[1]->ps == 27) { return 1; } return 0; } C# code [DllImport("Wrapper.dll", CallingConvention =

BadImageFormatException: PInvoke ImportDll with hdf5dll.dll

孤人 提交于 2021-02-16 20:11:05
问题 Ok, I have the HDF5 library downloaded from the official site, and I have a few DLLs, including hdf5dll.dll, and hdf5_hldll.dll. I have what I think to be some wrappers around the native calls, in my classes H5 , H5LT , H5F , and H5T . Example from H5.cs: namespace HDF5 { using hid_t = System.Int32; using herr_t = System.Int32; using hsize_t = System.UInt64; using size_t = System.UInt32; // hbool_t is 0:false, +:true using hbool_t = System.UInt32; // htri_t is 0:false, +:true, -:failure using

BadImageFormatException: PInvoke ImportDll with hdf5dll.dll

只愿长相守 提交于 2021-02-16 20:10:28
问题 Ok, I have the HDF5 library downloaded from the official site, and I have a few DLLs, including hdf5dll.dll, and hdf5_hldll.dll. I have what I think to be some wrappers around the native calls, in my classes H5 , H5LT , H5F , and H5T . Example from H5.cs: namespace HDF5 { using hid_t = System.Int32; using herr_t = System.Int32; using hsize_t = System.UInt64; using size_t = System.UInt32; // hbool_t is 0:false, +:true using hbool_t = System.UInt32; // htri_t is 0:false, +:true, -:failure using

Passing byte array to PInvoke call changes it to null

夙愿已清 提交于 2021-02-11 17:46:15
问题 After migration from Visual Studio 2012 to 2013 some PInvoke calls not working as previously. For example, I'm struggling with this code: Signature: [DllImport(LzoDll64Bit)] private static extern int lzo1x_decompress(byte[] src, int src_len, byte[] dst, ref int dst_len, byte[] wrkmem); Usage: byte[] dst = new byte[origlen]; int outlen = origlen; if (Is64Bit()) lzo1x_decompress(src, src.Length - 4, dst, ref outlen, _workMemory); else lzo1x_decompress32(src, src.Length - 4, dst, ref outlen,