pinvoke

How can I return a StringBuilder or other string buffer from a PInvoke native callback

这一生的挚爱 提交于 2020-01-21 05:42:50
问题 I would like a clean way to increase the size of a StringBuilder() as required for population by native code, the callback method below seems clean, but somehow we get a copy of the buffer instead of the actual buffer - I'm interested in explanations and solutions (preferably sticking to the callback type allocation as it would be nice and clean if only it could be made work). using System; using System.Runtime.InteropServices; using System.Text; namespace csharpapp { internal class Program {

How do I bring an unmanaged application window to front, and make it the active window for (simulated) user input

安稳与你 提交于 2020-01-19 03:46:09
问题 I am assuming I need to use pinvoke but I am not sure which function calls are needed. Detailed scenario. A legacy application will be running. I will have Handle for that application. I need to: a) bring that application to the top (in front of all other windows). b) Make it the active window. Which windows function calls are needed? 回答1: If you don't have a handle to the window, use this before : [DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindow(string

How do I bring an unmanaged application window to front, and make it the active window for (simulated) user input

最后都变了- 提交于 2020-01-19 03:45:19
问题 I am assuming I need to use pinvoke but I am not sure which function calls are needed. Detailed scenario. A legacy application will be running. I will have Handle for that application. I need to: a) bring that application to the top (in front of all other windows). b) Make it the active window. Which windows function calls are needed? 回答1: If you don't have a handle to the window, use this before : [DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindow(string

C# - Method's type signature is not PInvoke compatible

岁酱吖の 提交于 2020-01-17 15:41:12
问题 I am trying to use the VC++ (2003) dll in C# (2010) When am calling the method of dll from c# am getting this error "Method's type signature is not PInvoke compatible" I am returning the structure from VC++ Code: struct SLFData { public: char ByLat[10]; char ByLong[10]; }; And I am marshalling in C# Code: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct SLFData { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] public char[] ByLat; [MarshalAs(UnmanagedType

On Terminal Server, how does a service start a process in a user's session?

旧街凉风 提交于 2020-01-16 05:14:29
问题 From a Windows Service running on a Terminal Server (in global space), we would like to be able to start up a process running a windows application in a specific user's Terminal Server sessions. How does one go about doing this? The Scenerio: the windows service starts at boot time. After the user has logged into a Terminal Server user session, based on some criteria known only to the windows service, the windows service wants to start a process in the user's session running a windows

Debugging DLLImport in C#

◇◆丶佛笑我妖孽 提交于 2020-01-15 09:01:00
问题 I have been attempting to get the MySQL Embedded Library working in my C# application for the past 12 hours or so, and have been stuck for quite some time. I am getting the following error when I call mysql_server_init() ... Unhandled Exception: System.AcessViolationException: Attempted to read or write protected memory. The C++ method takes an int and two char** as parameters, but I was told a null terminated string[] array would suffice in C#. As this is the first method that you're

64 Bit P/Invoke Idiosyncrasy

情到浓时终转凉″ 提交于 2020-01-15 04:18:06
问题 I am trying to properly Marshal some structs for a P/Invoke, but am finding strange behavior when testing on a 64 bit OS. I have a struct defined as: /// <summary>http://msdn.microsoft.com/en-us/library/aa366870(v=VS.85).aspx</summary> [StructLayout(LayoutKind.Sequential)] private struct MIB_IPNETTABLE { [MarshalAs(UnmanagedType.U4)] public UInt32 dwNumEntries; public IntPtr table; //MIB_IPNETROW[] } Now, to get the address of the table, I would like to do a Marshal.OffsetOf() call like so:

To show the properties page of a file and navigate to a tab

妖精的绣舞 提交于 2020-01-14 14:43:09
问题 In my software i need to show the property dialog of a file and navigate to a specific tab in that property dialog? please tell me how to acheive this using c#? or Is it possible to replace the default property dialog with a custom one? 回答1: private bool properties(string Filename) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpParameters = "Details"; info.lpFile = Filename; info.nShow =

Obtain a filename from a file handle?

我怕爱的太早我们不能终老 提交于 2020-01-14 10:24:47
问题 I have the ntdll.dll's NtCreateFile() function hooked to allow/deny the access of certain files. Unlike kernel32.dll's CreateFile() which easily gives you the full path to the file in question, ntdll.dll's NtCreateFile() function only gives you the handle to the file. I need to obtain the full path of the file from a file handle, to consequently allow/deny access. I've searched around and there doesn't seem to be a working C# solution. This solution is in C++, and documented from Microsoft. I

Obtain a filename from a file handle?

给你一囗甜甜゛ 提交于 2020-01-14 10:23:26
问题 I have the ntdll.dll's NtCreateFile() function hooked to allow/deny the access of certain files. Unlike kernel32.dll's CreateFile() which easily gives you the full path to the file in question, ntdll.dll's NtCreateFile() function only gives you the handle to the file. I need to obtain the full path of the file from a file handle, to consequently allow/deny access. I've searched around and there doesn't seem to be a working C# solution. This solution is in C++, and documented from Microsoft. I