tagged [pinvoke]

Any difference between malloc and Marshal.AllocHGlobal?

Any difference between malloc and Marshal.AllocHGlobal? I write a module in C# that exports some functions to be used in C. I need to allocate some memory for some structs to be passed between C C#. W...

10 Jul at 17:38

Is there a tool that generates P/Invoke signatures for arbitrary unmanaged DLL?

Is there a tool that generates P/Invoke signatures for arbitrary unmanaged DLL? I stumbled upon a tool that generates P/Invoke signatures for Microsoft's own unmanaged DLLs: [PInvoke Interop Assistant...

Dynamically P/Invoking a DLL

Dynamically P/Invoking a DLL What is the best way to dynamically P/Invoke unmanaged code from .NET? For example, I have a number of unmanaged DLL's with common C-style exports between them. I would li...

29 Jul at 20:11

C++ and C# interoperability : P/Invoke vs C++/CLI

C++ and C# interoperability : P/Invoke vs C++/CLI In the course of finding a way to interoperate between C# and C++ I found this [article](http://msdn.microsoft.com/en-us/magazine/cc164123.aspx) that ...

30 Jun at 15:19

Getting the Windows System Error Code title/description from its hex number

Getting the Windows System Error Code title/description from its hex number I'm messing around with some windows functions using p/invoke. Occasionally, I get an error code that is not ERROR_SUCCESS (...

29 Jun at 15:57

When passing a managed byte[] array through PInvoke to be filled in by Win32, does it need to be pinned?

When passing a managed byte[] array through PInvoke to be filled in by Win32, does it need to be pinned? Suppose you're calling a Win32 function that will fill in your byte array. You create an array ...

7 Feb at 21:32

Entry Point Not Found Exception

Entry Point Not Found Exception I'm trying to use a C++ unmanaged dll in a C# project and I'm getting an error when trying to call a function that says that entry point cannot be found. ``` public cla...

18 Aug at 18:24

Check if a DLL is present in the system

Check if a DLL is present in the system quick question. I want to find out if a DLL is present in the system where my application is executing. Is this possible in C#? (in a way that would work on ALL...

18 Feb at 22:6

P/Invoke or C++/CLI for wrapping a C library

P/Invoke or C++/CLI for wrapping a C library We have a moderate size (40-odd function) C API that needs to be called from a C# project. The functions logically break up to form a few classes that will...

20 Aug at 18:22

What exactly happens during a "managed-to-native transition"?

What exactly happens during a "managed-to-native transition"? I understand that the CLR needs to do marshaling in some cases, but let's say I have: ``` using System.Runtime.InteropServices; using Sys...

8 Feb at 21:8

PInvoke error when marshalling struct with a string in it

PInvoke error when marshalling struct with a string in it I have a C++ struct and a C# struct the C++ library exposes And it is imported like

3 Aug at 17:52

Does P/Invoke on 64-bit windows require different signatures than on 32-bit?

Does P/Invoke on 64-bit windows require different signatures than on 32-bit? When I create a signature that refers to `user32.dll` for example should I be building this with `user64.dll` if the target...

15 Sep at 10:12

Performance differences between P/Invoke and C++ Wrappers

Performance differences between P/Invoke and C++ Wrappers In the process of learning P/Invoke, I asked this previous question: > [How to P/Invoke when pointers are involved](https://stackoverflow.com/...

23 May at 11:54

Returning a string from PInvoke?

Returning a string from PInvoke? I am using PInvoke for interoperability between Native Code (C++) and Managed Code (C#). I just write a simple function which gets a string from C++ code. My code look...

13 Nov at 12:7

Read other process current directory in C#

Read other process current directory in C# I am trying to get current working directory of selected process. I am sure that it is possible, because tools like Process Explorer can show this informatio...

19 Apr at 18:7

How do I pass a const char* to a C function from C#?

How do I pass a const char* to a C function from C#? I try to call a plain C-function from an external DLL out of my C#-application. This functions is defined as Now I have some problems using this fu...

7 May at 13:49

PInvoke for GetLogicalProcessorInformation Function

PInvoke for GetLogicalProcessorInformation Function I want to call via c#/PInvoke the [GetLogicalProcessorInformation](http://msdn.microsoft.com/en-us/library/ms683194.aspx) function, but I'm stuck wi...

7 Aug at 11:19

keybd_event KEYEVENTF_EXTENDEDKEY explanation required

keybd_event KEYEVENTF_EXTENDEDKEY explanation required In [documentation](http://msdn.microsoft.com/en-us/library/windows/desktop/ms646304%28v=vs.85%29.aspx) it says: (0x0001): If specified, the scan ...

20 Jun at 09:12

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

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 functi...

24 Nov at 18:49

How do I marshal a pointer to an array of pointers to structures?

How do I marshal a pointer to an array of pointers to structures? I have a C function with the following signature: `players` is a pointer to an array of pointers to `struct player` objects. `n` is th...

2 Apr at 23:32

Unblock File from within .net 4 c#

Unblock File from within .net 4 c# Is there a possibility to unblock a file that is downloaded from the internet from within a c# program. Surfing the internet I have learned, that the information is ...

Add offset to IntPtr

Add offset to IntPtr I'm looking for a way to perform pointer operations in C# or .NET in particular. I want to do something very simple Having a pointer IntPtr I want to get IntPtr object which point...

27 Jul at 11:14

Bring a window to the front in WPF

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).Han...

6 Dec at 18:11

PInvoke for C function that returns char *

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: In C#, I first used: It seems to wo...

15 Dec at 23:42

int vs IntPtr when you have a handle?

int vs IntPtr when you have a handle? First a background question: In general, what is the difference between `int` and `IntPtr`? My guess is that it is an actual object rather than a value like an `i...

23 Dec at 23:39