p-invoke

How can I pass a pointer to an array using p/invoke in C#?

Example C API signature: void Func(unsigned char* bytes); In C, when I want to pass a pointer to an array, I can do: unsigned char* bytes = new unsigned char[1000]; Func(bytes); // call How do I translate the above API to P/Invoke such that I can pass a pointer to C# byte array? ...

How can I pass a reference parameter (&) (not pointer) using p/invoke in C#?

I have a C++ API prototype void Func(int& size); How can I translate it to P/Invoke in C#? From what I know, if I use public static extern Func(ref int size); , the function will receive a pointer to the int instead of the value. ...

How to call "CreateFile" in C#?

After getting so much information about retrieving .MBR from a storage device, conclusion is to use P/Invoke to call CreateFile. But how this can be done in C#? Please illustrate! Your help will be greatly appreciated!!! ...

Overhead for native interop using only primitive types

I am considering porting a small portion of the code in a C# project of mine to C/ASM for performance benefits. (This section of code uses many bitwise operations and is one of the few places where there may exist a real performance increase by using native code.) I then plan to simply call the native function in the separate DLL via P/I...

Best way to access COM objects from C#

I am planning to use various objects that are exposed as COM objects. To make them easier to use, I'd like to wrap them as C# objects. What is the best approach for this? ...