pinvoke

How can I pass a .NET Bitmap to a native DLL?

Here is what I have: An external DLL, I have written in C. This DLL links to opencv. I don't want to call OpenCV directly from C# - there are already huge amounts of C code accessing OpenCV which will be used in the DLL. There is an exported function: passbitmap(void *mem, size_t s); A C# project from which I want to call the DLL. A Sy...

Marshalling an an unmanaged array of strings from a PInvoked OpenFileDialog (GetOpenFileName)

OpenFileDialog returns a pointer to memory containing a sequence of null-terminated strings, followed by final null to indicate the end of the array. This is how I'm getting C# strings back from the unmanaged pointer, but I'm sure there must be a safer, more elegant way. IntPtr unmanagedPtr = // start of the array ... ...

Calling MsiEnumRelatedProducts from C# is crashing

I'm having no end of trouble calling MsiEnumRelatedProducts from C#. I've tried a couple of variations on the p/invoke definition but no luck (out and ref). I think the problem is the last parameter, which is an LPTSTR that is supposed to point to a string 39 characters long. Here's the pinvoke and call: public static string EnumRelat...

C#: When using RegisterHotKey api call, why does it accept 1, 2, 4, and 8 as modifiers?

I reference to this post; http://www.pinvoke.net/default.aspx/user32/RegisterHotKey.html #region fields public static int MOD_ALT = 0x1; public static int MOD_CONTROL = 0x2; public static int MOD_SHIFT = 0x4; public static int MOD_WIN = 0x8; public static int WM_HOTKEY = 0x312; #endregion [DllImport("us...

C# PInvoke Delphi dll that returns a string fails in IIS only

I have a Delphi 7 dll that exports the following function: function StringTest(var StringOut : pchar) : boolean; stdcall; begin GetMem(StringOut, 100); StrPCopy(StringOut, 'Test output string.'); result := true; end; This function is imported in C# as follows: [DllImport(@"C:\\Test\\DelphiTest.dll")] public static extern...

How do I get the results from an FTP command run through FtpCommand?

I've wrapped most of wininet with no problems, but now I'm stuck. I am trying to p/invoke FtpCommand from wininet.dll, but every command I run returns "500 syntax error". Even simple commands like dir, or ls. If I connect to the same server with ftp.exe the commands work fine and return expected results. Here's the method definition: [...

Retrieving Device Context from .NET print API

I am working on a .NET application to control DataCard Desktop Card printers, and I have stumbled upon a problem. In order to execute Magnetic Stripe and Chip encoding, I have to call a function in a native printer API dll to enable the printers Interactive mode. I have managed to create the P/Invoke code to call this native function. B...

how can i change form shape in vb.net

I used to change the Form shape in VB 6.0 using the following code: Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVa...

Starting .exe from Visual C++ 2005 dll

Hi There, Does anyone know the code or have ideas on how to kick off an exe using visual c++ 2005. The environment the dll is on if Windows Mobile. The c# to do this using P/Invoke is [DllImport("coredll.Dll")] private static extern int CreateProcess(string strImageName, string strCmdLine, IntPtr pProcessAttributes, IntPtr pThreadAttr...

P/Invoke function call problem

I am working on a system that requires interaction with a native C API using P/Invoke. Now I've (yet again) stumbled upon a problem which I cannot seem to solve in any way. The original function is designed to return 2 kinds of structures, based on a parameter that specifies which structure to use. The C header file defines the structur...

Is it theoretically possible to access any library from C# (aka what does PInvoke do under the hood)?

Like a lot of places my workplace has legacy code floating around along with more modern applications. For example we have a server application that still uses the Microsoft Fortran77 compiler. The less old parts of the application are written for the Visual Studio 6 C compiler and lately there have been runours of writing some new libra...

Unable to find an entry point named 'TaskDialogIndirect' in DLL 'ComCtl32'

We have a particular Vista x64 machine that, when running our C# WinForms app, displays the following error: System.EntryPointNotFoundException: Unable to find an entry point named 'TaskDialogIndirect' in DLL 'ComCtl32'. This same code works fine on other Vista machines. For some reason, this particular Vista machine always t...

Calling GetGUIThreadInfo via P/Invoke

I want to send keyboard input to a window in another process, without bringing that window to the foreground. I can use PostMessage to fake the WM_KEYDOWN and WM_KEYUP; all I need to know is which window handle should receive the keyboard input -- i.e., something like GetFocus, but for another, non-active application. The GetGUIThreadIn...

Pinning a delegate within a struct before passing to unmanaged code

I'm trying to use an unmanaged C dll for loading image data into a C# application. The library has a fairly simple interface where you pass in a struct that contains three callbacks, one to receive the size of the image, one that receives each row of the pixels and finally one called when the load is completed. Like this (C# managed defi...

GetGuiResource for whole system

Hi, I'm trying to add the info from GetGuiResources to the exception handling system of my application. Getting the values for the current process is not a big deal, but I would like to add the values for the whole system as well. So I tried: foreach (Process p in Process.GetProcesses()) { gdiHandles += GetGuiResources(p.Handle, 0)...

DllImport and ASP.NET

Hi, I'm having some problems with DllImport and ASP.NET because when I use a imported method ASP.NET loads the Dll and locks the file even after it finished using it. Is there any way to force ASP.NET to release the lock on the file? ...

How do i send a VK_MEDIA_NEXT_TRACK in C#?

Yeah, the title almost says all. I found many things googling, but none I could actually use, so I'm just searching for a simple method, if that is possible. Thanks. ...

Disabling Accessibility Shortcuts in .NET Application?

This msdn article -- http://msdn.microsoft.com/en-us/library/bb219746(VS.85).aspx#Disabling_Accessibility_Shortcut_Keys -- provides information for C++ programmers on how to temporarily disable the windows shortcuts for accessibility (such as holding Shift for 8 seconds, or pressing Shift more than 5 times in quick succession). Surely t...

P/Invoke tutorials?

Does anyone know of a good tutorial/e-book that goes in depth on the System.Runtime.InteropServices namespace? I just got through reading this tutorial on how to make the UAC shield show up in a button and now I really want to learn this. P.S. How do look in the windows system files to know that a method exist to show a UAC shield in a...

C#: How to pass null to a function expecting a ref?

I've got the following function: public static extern uint FILES_GetMemoryMapping( [MarshalAs(UnmanagedType.LPStr)] string pPathFile, out ushort Size, [MarshalAs(UnmanagedType.LPStr)] string MapName, out ushort PacketSize, ref Mapping oMapping, out byte PagesPerSector);...