pinvoke

How to get list or enumerate all handles of unmanaged windows with same class and name

只谈情不闲聊 提交于 2019-12-22 11:23:53
问题 Using pinvoke I can find Handle of a window with particular class & name easily: [DllImport("user32.dll")] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); IntPtr hWnd = FindWindow("Foo Class", "Foo Window"); The above code works perfect if there is only 0 or 1 matching windows. However the unmanaged application I am working with spans multiple windows. Calling FindWindow multiple times returns the same Window Handle each time. What do I need to do to get ALL

Marshalling arrays of VARIANT using P/Invoke

瘦欲@ 提交于 2019-12-22 10:40:00
问题 Situation: I have a managed (C#, .NET 2.0) application which uses an unmanaged (C++) DLL using P/Invoke. Along with the "simple" methods (POD arguments/return value) there's a requirement to pass a boost::variant value arrays to the code. The reason for it is that these methods pass report data (similar to Excel cells, which can be of any type). C# code accepts them as boxed "object"'s. The previous implementation called for use of SafeArray of COM VARIANT's. However, due to poor coding/not

c# Pinvoke for GetWindowDpiAwarenessContext

做~自己de王妃 提交于 2019-12-22 10:26:17
问题 I am trying to implement GetWindowDpiAwarenessContext in a C# application with no success. The relevent header files are: windef.h DECLARE_HANDLE(DPI_AWARENESS_CONTEXT); typedef enum DPI_AWARENESS { DPI_AWARENESS_INVALID = -1, DPI_AWARENESS_UNAWARE = 0, DPI_AWARENESS_SYSTEM_AWARE = 1, DPI_AWARENESS_PER_MONITOR_AWARE = 2 } DPI_AWARENESS; #define DPI_AWARENESS_CONTEXT_UNAWARE ((DPI_AWARENESS_CONTEXT)-1) #define DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ((DPI_AWARENESS_CONTEXT)-2) #define DPI_AWARENESS

Calling Pocketsphinx in C# AccesViolationException

空扰寡人 提交于 2019-12-22 09:21:14
问题 I'm trying to do the pocketsphinx tutorial in C# using pinvoke but get an AccessViolationException when I try to decode using ps_decode_raw(). IntPtr ps = PocketSphinx.ps_init(config); IntPtr fh = Win32Util.fopen(@"goforward.raw", "rb"); int rv = PocketSphinx.ps_decode_raw(ps, fh, "goforward", -1); The functions are wrapped as follows //ps_decoder_t* ps_init(cmd_ln_t* config) [DllImport("pocketsphinx.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] public extern static

How to get the number of open TCP connections held by a certain process in .NET

廉价感情. 提交于 2019-12-22 08:38:14
问题 I need to monitor the number of open TCP connections held by a single process on a 64 bit Windows 7 machine from .NET 4.0. This article describes the undocumented Win32 API method "AllocateAndGetTcpExTableFromStack" that accomploshes this task on 32 bit windows: http://www.codeproject.com/KB/IP/iphlpapi.aspx?display=Print But this fails on my machine (presumably because I am on 64 bit) with: Unable to find an entry point named 'AllocateAndGetTcpExTableFromStack' in DLL 'iphlpapi.dll'. How can

.NET Runtime Error 80131506 - Passing Lambda to Native Function

你。 提交于 2019-12-22 07:03:45
问题 So I'm getting this error that looks as though it's a corrupted garbage collection: Application Crashes With "Internal Error In The .NET Runtime" The full error is: The process was terminated due to an internal error in the .NET Runtime at IP 71C571C8 (71B20000) with exit code 80131506. It's running on: Framework Version: v4.0.30319 This occurs inconsistently when running this function repeatedly: public static int GetMdiTitledChildWindows(IntPtr parentWindow) { IntPtr mdiClient =

C++ “system()” in C#

时光怂恿深爱的人放手 提交于 2019-12-22 06:54:27
问题 I am currently developing an application in C# which needs to work sort of like a "Command Prompt", therefore I was wondering whether the C++ function int system ( const char * command ); in cstdlib exists in C#? A reference to an dynamic-link library containing this function would be accepted aswell. 回答1: Look into System.Diagnostics.Process.Start : http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx 回答2: If you want to execute program from an application then you

PInvoke - Marshal an array of structs from pointer

会有一股神秘感。 提交于 2019-12-22 05:51:30
问题 I'm attempting to follow the answer at this question My struct looks like this in C typedef struct drive_info_t { unsigned char drive_alias[32]; } drive_info_t; My function looks like this in C unsigned int get_drive_info_list(drive_info_t **list, unsigned int *item_count) { //fill list in native C //print out in native C printf("list.alias - %s\r\n",list[i]->drive_alias); } My C# struct looks like this [StructLayout(LayoutKind.Sequential)] public struct drive_info_t { [MarshalAs

C# console application stdin/stdout redirection

一曲冷凌霜 提交于 2019-12-22 05:09:15
问题 I have an interesting (read: frustrating) problem kicking off a console application from a C# WPF app and redirecting its stdin and stdout. It is mostly up and working but I seem to end up not getting some data from stdout as soon as I start redirecting stdin. I'll clarify with an example. If I don't set hStdInput in the STARTUPINFO structure, when I start the child process I receive the following: MongoDB shell version: 2.2.0 connecting to: test local:PRIMARY> Once I set hStdInput however, I

Does the managed main UI thread stay on the same (unmanaged) Operation System thread?

柔情痞子 提交于 2019-12-22 01:43:17
问题 I am creating a managed WPF UI front-end to a legacy Win32-application. The WPF front-end is the executable; as part of its startup routines I start the legacy app as a DLL in a second thread. Any UI-operation (including CreateWindowsEx , etc.) by the legacy app is invoked back on the main UI-thread. As part of the shutdown process of the app I want to clean up properly. Among other things, I want to call DestroyWindow on all unmanaged windows, so they can properly clean themselves up. Thus,