<p>Example C API signature:</p>

<p><code>void Func(unsigned char* bytes);</code></p>

<p>In C, when I want to pass a pointer to an array, I can do:</p>

<pre><code>unsigned char* bytes = new unsigned char[1000];
Func(bytes); // call
</code></pre>

<p>How do I translate the above API to P/Invoke such that I can pass a pointer to C# byte array?</p>

You can use unsafe code:
```
```
unsafe 
{
     fixed(byte* pByte = byteArray)
     IntPtr intPtr = new IntPtr((void *) pByte);
     Func(intPtr);
}
```
```
If you need to use safe code, you can use a few tricks:
```
```
IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(byteArray));
Marshal.Copy(byteArray, 0, intPtr, Marshal.SizeOf(byteArray));

Func(intPtr);

Marshal.FreeHGlobal(intPtr);
```
```
However, the safe code is going to be slow IMHO.