pinvoke

Getting window screenshots, but text portions are transparent

This is a followup to this question. The code shown there has been very useful in obtaining a bitmap from a window and applying it as a BitmapSource on a WPF Image control. However, I'm finding that many areas of the image are showing up as transparent, particularly any areas of text. I've posted a sample of what I'm seeing here: http:/...

P/Invoke on x64 null reference exceptions

P/Invoke on x64 null reference exceptions I get null reference exceptions when I try to compile for x64 in .NET code that makes use of platform invocation services to call unmanaged code in dlls. Am I missing something obvious here? e.g. call to Private Declare Function waveOutOpen Lib "winmm.dll" (ByRef lphWaveOut As Int32, ByVal uDe...

Socket programming; shall I use pInvoke or write c# version of existing c++ app

Hello all, I have been assigned to a task where I need to connect to a socket and receive a lot of updates (3K-4K messages per second) I also need to send some message to server for authentication and configuration. There is an existing C++ apps given by the data provider and they have no c# sample. I have been trying to write this app...

Returning pointers from unmanaged to managed code

I've an unmanaged dll that exports the folowing function: SomeData* test(); Let's assume SomeData as: typedef struct _Data Data; struct _Data{ int a; int b; } Now i want to call this function from C# code. I start to define the C# Struture needed to custom marshaling like this: [StructLayout(LayoutKind.Sequen...

P/Invoke and Mono: EntryPointNotFoundException

I'm trying to access the Wine implementation of some user32 functions on Kubuntu Linux. I have the Wine 1.1.31 package installed. When try running this simple test program in MonoDevelop, I get a System.EntryPointNotFoundException. using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace PinvokeTesting...

Blocking WM_QUIT

Quick question. I have an app that use a native DLL through PInvoke, this DLL may call a PostQuitMessage(). How can I avoid it? (as my app should not close) I tried AddMessageFilter, but it doesn't trigger the WM_QUIT. ...

Avoid P/Invoke errors at startup time.

It seems that calling a P-Invoke while the App is not completed loaded make it spew the errors of the related functions. For example at the moment I'm trying to load at startup various DLL through LoadLibrary and test if they have exported a particular function. If I do that while the app completed its load procedure no error are give...

P/Invoke a purely C++ library?

I am just wondering if it is possible to P/Invoke a pure C++ library, or does it have to be wrapped in C? ...

Exchange stuctures (envolving pointers to other structures) between C and C#

I want to use PInvoke to bring to managed side something this: (C code) typedef struct{ //some fields... } A; type struct{ A* a; } B; int getB(B* destination){ //destionation will be an output parameter to C# //puts an B in 'destination' return 0; } Now, i need a way to tell managed...

How to access HKCU registry of currently logged on user(s), from a service?

From within a windows service I want to check some user preferences that are stored within each users' HKCU registry area. How can I do this? I see that HKEY_USERS has subkeys of each user that has logged in to the machine (or something like that?), and within these are the HKCU areas for each user. However, these subkeys are the SIDs o...

How would I import a function template using PInvoke?

In my C# code, I need to call a function from a C++ Dll that I wrote.The function is generic. So , should I just import it like this: [DllImport("myDll.dll")] private static extern TypeName functionName<TypeName>( int arg1, int arg2 ); Is this correct syntax? Thanks. ...

How I can replace the command of the minimize button?

First, sorry for my bad english :) Second, I can know when the form is being moved/resized, using this code: protected override void WndProc(ref Message m) { if (m.Msg == WM_WINDOWPOSCHANGING) { WINDOWPOS winPos = new WINDOWPOS(); winPos = (WINDOWPOS)Marshal.PtrToStructure(m.LParam, typeo...

Can safearrays take, and marshall, user defined types?

I would like to move fairly complex types from the managed to native world and visa versa. Currently this is being done by creating multidimensional safearrays, which has the advantage that marshalling is done for you, but means we end up with rather complex jagged arrays to get our heads around. I have tried to put some structs into S...

C#: Access 32-bit/64-bit DLL depending on platform

Hi, we use a self-written 32bit C++ DLL from our C# applications. Now we've noticed that when the C# applications are run on a 64bit system, the 64bit runtime is automatically used and of course the 32bit DLL can not be accessed from the 64bit runtime. My question is: is there a way of using the 32bit DLL? If not, if I created a 64bit ...

Reading C structures with "union" types from C# with PInvoke

I'm trying to bring to managed side (C#) a structure built in C. Let's assume this structure (C code): typedef struct S{ int i; union{ TypeA a; TypeB b; TypeC c; }uni; } S; Now, i create the C# wrapper classes: [StructLayout(LayoutKind.Explicit)] public class S { [FieldOffset(0)] p...

PInvokeStackImbalance C# call to unmanaged C++ function

After switching to VS2010, the managed debug assistant is displaying an error about an unbalanced stack from a call to an unmanaged C++ function from a C# application. The usuals suspects don't seem to be causing the issue. Is there something else I should check? The VS2008 built C++ dll and C# application never had a problem, no weird ...

Get an array of structures from native dll to c# application

I have a C# .NET 2.0 CF project where I need to invoke a method in a native C++ DLL. This native method returns an array of type TableEntry. At the time the native method is called, I do not know how large the array will be. How can I get the table from the native DLL to the C# project? Below is effectively what I have now. // in C# .N...

P/Invoke dynamic DLL search path

I have an existing app which P/Invokes to a DLL residing in the same directory as the app itself. Now (due to the fact that Canon produces one of the crappiest API's around) I need to support two versions of this API and determine at run-time which one I should use (old or new). Since the DLLs have the same name (the first one loads oth...

Enumerating Network Sessions

Hi, I wanted to pull data about the connected network users from the Computer Management -> Shared Folders -> Sessions tab into my c# application. Can anybody guide me on what namespaces have to be used along with some sample code to import username and ip address from Computer Management -> Shared Folders -> Sessions tab? Regards ...

C# :- P/invoke signature

I have a dll with following signature in C++. It is working in c++; void Decompress(unsigned char *in,int in_len,unsigned char * out, unsigned *o_len,int *e); Description of parameter *in : It is byte array passed to fucntion. in_len : Length of bytes in first parameter. *out : This would be the output as byte array. *o_len : N...