pinvoke

How to force Nunit to release handles on native DLLs?

I have code which require me to Pinvoke into a 3rd party native DLL. The issue is that when I use the Nunit test runner for those tests, the native dll is locked by the nunit processes (nunit.exe and nubit-agent.exe). Thus my post-build copy command fails because of this. The only way to generate a 'successful build' (includes post-buil...

Passing a const char* character string from unmanaged to managed

I have two communicating components - one managed, the other unmanaged. The managed needs to retrieve a character string from the unmanaged implementation (the same string or just a copy). I tried the following code. // Unmanaged code const char* GetTestName(Test* test) { return test->getName(); } // Managed wrapper [DllImport(DllN...

How can I get text from another application in c#?

Hello, I am a beginner in C#, and I try to get text in list box of an application but i don't know how to begin. I tried this code to get the list of IDM: [DllImport("user32.dll")] static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = fa...

64 Bit P/Invoke Idiosyncrasy

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&lt;/summary&gt; [StructLayout(LayoutKind.Sequential)] private struct MIB_IPNETTABLE { [MarshalAs(UnmanagedT...

Mono: DllImport unable to load library '(null)'.

I'm trying to use the C# ZeroMQ bindings. However on Mono 2.8 and OSX 10.6.4, when I try to run an example application, I get a DLLImport error. Specifically: Unhandled Exception: System.DllNotFoundException: libzmq at (wrapper managed-to-native) ZMQ/C:zmq_init (int) at ZMQ+Context..ctor (Int32 io_threads) [0x00000] in <filename u...

What's the lifetime of an unmanaged DLL once it's been pInovked from managed code?

For example if you have a simple managed console app and a simple unmanaged C++ DLL. You pInvoke into a function in the C++ DLL, does the DLL stay loaded in the unmanaged process until said process comes down? Or does the DLL get unloaded at the completion of every pInvoke call? ...

VB.NET - Calling Kernel32.DLL's Wow64DisableWow64FsRedirection.

Looking at Microsoft's page on Wow64DisableWow64FsRedirection, I see some C code. What if you want to call this function and it's revert from VB.net? So far I have done this: <Runtime.InteropServices.DllImport("KERNEL32.DLL", EntryPoint:="Wow64DisableWow64FsRedirection")> _ Public Shared Function DisableWow64Redirection() As Boolean...

Aero arrows using native hacks?

Using some P/Invoke, one can create a command link from a button in .NET (see http://blogs.msdn.com/b/knom/archive/2007/03/12/command_5f00_link.aspx). I was wondering if a similar procedure was possible for the Previous/Following arrows visible in, for instance, Aero wizards or the Aero Explorer. I know I can extract the files myself...

C# .NET: Turning TabControl into Wizard

From what I read on MSDN, TabControl is seemingly the wrapped version of property sheets. (About Property Sheets on MSDN). Now sending messages to the property sheets, one can apparently turn them into an automatically created wizard: (Creating Wizards on MSDN). My question is: Is there a way to send those p/invoke messages to our TabC...

Using p/invoke and win-api to monitor audio line-in (C#)

Hi everyone In the last few days I was trying to write small program to monitor the audio line-in using win-api (winmm.dll). I can pinvoke api functions such as waveInOpen but I can't figure out how to use these functions to achieve my target. the question is - can someone can briefly tell me how can I get the data from the audio line ...

ExecutionEngineException thrown when calling native code

Hi, I have a function that is exported by a C library with the following signature: extern "C" BOOL Func() The function is declared in VB.NET code like this: <DllImport("mylib.dll", CallingConvention:=CallingConvention.Cdecl)> Private Shared Function Func() As Boolean End Function The problem is that I get an ExecutionEngineExcept...

4-bit Enum in C#

I know that its possible to make enums that use signed or unsigned 64, 32, 16, and 8 bit values as their underlying valud type using (:ulong, :uint, :ushort, :byte). But is it possible to create a 4 bit enum? (I'm writing some code that will interop with C++ and the struct that I have in C# for a return type has one field that would be...

Convert callback function from C++ to VB.Net

I'm trying to convert C++ API to VB.Net, but this function is too hard and i don't know how make it work. Here is the API doc for this function: void RemoteDllSetReceiver(void *inst, on_received_buffer_t received_buf_cb); Sets a callback function to receive notifications from the DLL. The prototype of the callback is: typedef bool...

How to return string array using Pinvoke

My c/c++ skills are non-existent and there's some custom string array data that needs to be returned from an old C dll fyi - The C/C++ code can be modified as needed ...

.NET CF - MSMQ ActivateDevice() Crash

I have a .NET 3.5 Compact Framework application that uses MSMQ. We are running this application on an Intermec CN3, Windows Mobile 5.0 device. However, when our application first tries to active the MSMQ service with ActivateDevice (pinvoke), the application crashes and we get the error report message: A problem has occuurred with m...

PInvoke Libraries when the lib is not accessible

I have a library that contains a class that references dwm. If this library is use in an XP system but the class is not used, would this cause an error? Supposed this library was to be used on WP7 or XNA? Would this cause an error? ...

C# calling C++ method that returns a pointer. Explain memory management.

Can someone explain what exactly is happening at a low level / memory management perspective on the 2 C# lines in "Main" in the following? C++ Code (unmanaged): #define DLLEXPORT extern "C" __declspec(dllexport) DLLEXPORT MyClass* MyClass_MyClass() { return new MyClass(); } DLLEXPORT void MyClass_setName(My...

C# SetSystemTime (WIN API) hooking

Hello. I need restriction for time changes coming from different sources. The best way, as i think, is to hook WINAPI function SetSystemTime (and maybe SetLocalTime). I tried to hook this by using EasyHook library with injection in all running processes, owned by current system user. But it had no effect. How can I do that? ...

Fixed statement with jagged array

Hi all! I have jagged array which I need to pass to external method. [DllImport(...)] private static extern int NativeMethod(IntPtr[] ptrArray); ... fixed (ulong* ptr = array[0]) { for (int i = 0; i < array.Length; i++) { fixed (ulong* p = &array[i][0]) { ptrArray[i] = new IntPtr(p); } ...

IIS: Unable to load DLL "<dllName>": The specified module could not be found. (Exception from HRESULT: 0x8007007E)

I have an application that uses .Net remoting. The remotable calls our unmanaged dll that is a client to a Versant database. The previous release of our app communicated with an earlier release of Versant in exactly the same way. We now have 2 different dlls to communicate with the different versions of the database. The new dll resides...