pinvoke

Opening pipe connection to a file descriptor in C#

I have a legacy app where it reads message from a client program from file descriptor 3. This is an external app so I cannot change this. The client is written in C#. How can we open a connection to a specific file descriptor in C#? Can we use something like AnonymousPipeClientStream()? But how do we specify the file descriptor to connec...

Hooking into Windows with C# to Produce Windows 7 New Feature

I just saw a really useful UI feature of the forthcoming Windows 7 ( visit http://www.gizmodo.com.au/2008/10/windows_7_walkthrough_boot_video_and_impressions-2.html and scroll down to the video entitled Super Scientific Video of New Window Resizing Feature) In a nutshell you can drag a window by the title bar to the top of the screen to...

Bring a window to the front in WPF

How can I bring my WPF application to the front of the desktop? So far I've tried: SwitchToThisWindow(new WindowInteropHelper(Application.Current.MainWindow).Handle, true); SetWindowPos(new WindowInteropHelper(Application.Current.MainWindow).Handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); SetForegroundWindow(new WindowInter...

How do you draw a Taskbar button using visual styles?

I've created a DeskBand toolbar and I want to display a button on the toolbar that has the style visual style as a taskbar button. In .NET you can use the VisualStyleRenderer to render the Taskbar BACKGROUND, but there's way to render a button. Are there any Win32 API's I can use to draw the button using Visual Styles rather than emula...

When a DLL is not found while P/Invoking, how can I get a message about the specific unmanaged DLL that is missing ?

When you link to an unmanaged library (say 'A.dll') which in turn links to another library ('B.dll'), and B.dll is missing, you will get a run-time error message about failing to load 'B.dll'. But when you P/Invoke into 'A.dll' from managed code, you'll get a general exception of this form: Unhandled Exception: System.DllNotFoundExcept...

How to work with an interface dynamically loaded from an assembly and invoke its members

I have got some code to load an assembly and get all types, which implement a certain interface, like this (assume asm is a valid and loaded assembly). var results = from type in asm.GetTypes() where typeof(IServiceJob).IsAssignableFrom(type) select type; Now I'm stuck: I need to create instances of these objects and invoke method...

How to use libFLAC to read FLAC tags in c#

Is there an .net c# wrapper for the libFLAC library? If not, how can I read FLAC tags using the libFLAC in a .net framework c# application? If neither, are there other opensource libraries to read flac tags in c#? Thanks! ...

dllimport failed to locate dll even though it is in the PATH

I use [Dllimport("DllName.dll")] where I'm sure a path to my dll exists in the process PATH environment variable, and still I get "DllName.dll could not be found" ...

using a class defined in a c++ dll in c# code

I have a dll that was written in c++, I need to use this dll in my c# code. After searching I found that using P/Invoke would give me access to the function I need, but these functions are defined with in a class and use non-static private member variables. So I need to be able to create an instance of this class to properly use the func...

How do I solve the .NET CF exception "Can't find PInvoke DLL"?

This is to all the C# gurus. I have been banging my head on this for some time already, tried all kinds of advice on the net with no avail. The action is happening in Windows Mobile 5.0. I have a DLL named MyDll.dll. In the MyDll.h I have: extern "C" __declspec(dllexport) int MyDllFunction(int one, int two); The definition of MyDllFu...

Converting COM object returned by IHTMLDocument2.Script.InvokeMember() to something useful

I'm working with some code in C#.NET for an Internet Explorer extension that calls Javascript in the browser and gets the return value from the Javascript call. When the Javascript returns a primitive type or an array of primitive types, I get something that I can deal with, but when the Javascript returns an object, I get an opaque COM...

How do I remove minimize and maximize from a resizable window in WPF?

WPF doesn't provide the ability to have a window that allows resize but doesn't have maximize or minimize buttons. I'd like to able to make such a window so I can have resizable dialog boxes. I'm aware the solution will mean using pinvoke but I'm not sure what to call and how. A search of pinvoke.net didn't turn up any thing that jumped...

How to convert from HBITMAP to .NET's Bitmap class?

I am using some C++ code that employs the CreateDIBSection function to create a bitmap and return a HBITMAP handle. What is the best way of getting this information into my .NET assembly? ...

In .NET CF 2.0, will a global keyboard hook interfere with P/Invokes that require a keypress?

My details: custom mobile device running Windows CE 4.2, Compact Framework 2.0 SP1. C# app making decent use of P/Invokes with no problems until now. I've written a low-level keyboard hook (similar to, but not identical to, this CodeProject post) which works marvelously with one exception. One thing that our software does is allow acces...

How do I use DMProcessConfigXML to provision my Windows Mobile device?

I want to create a C# program to provision Windows Mobile devices. I have found MSDN documentation on a function called DMProcessConfigXML, but no instructions on how to use this function. How can I use this function in my Windows Mobile app? I suspect it has something to do with using pinvoke. Thanks, Paul ...

.NET WinForms: How to use an API call that requires a window handle?

Short version How do i use an API call when i cannot guarantee that the window handle will remain valid? i can guarantee that i'm holding a reference to my form (so the form is not being disposed). That doesn't guarantee that the form's handle will stay valid all that time. How can a form's window handle become invalid even though ...

Can I embed a win32 DLL in a .NET assembly, and make calls into it using P/Invoke?

I'm writing a C# wrapper for a third-party native library, which we have as a DLL. I would like to be able to distribute a single DLL for the new assembly. Is it possible for me to embed the win32 DLL in my .NET DLL, and still make calls into it using P/Invoke? If so, how? ...

P/Invoke to correct version of Win32 DLL?

I've got some P/Invoke code that invokes DBGHELP.DLL. I'll add the signatures to pinvoke.net later. The version of DBGHELP.DLL that ships with Windows 2003 is too old, and my code requires the version of DBGHELP.DLL that shipped with "Debugging Tools for Windows" version 6.9. How do I do one of the following? Ensure that DllImport re...

PInvoke for C function that returns char *

I'm trying to write some C# code that calls a method from an unmanaged DLL. The prototype for the function in the dll is: extern "C" __declspec(dllexport) char *foo(void); In C#, I first used: [DllImport(_dllLocation)] public static extern string foo(); It seems to work on the surface, but I'm getting memory corruption errors duri...

Using a debug mode for a program that runs on a remote desktop.

I have a short program that is used exclusively with a remote desktop connection that's been set to only run that program and not allow any other access into the remote machine. Previously, the program just exited and let the connection terminate, but it was very slow, so I wrote the following code to terminate the remote session when th...