I call an unmanaged function in my C # code.
The declaration of this function is as follows:
int myFun(unsigned char* inputBuffer, unsigned char* &outputBuffer);
I use this function as follows:
[DllImport("myDLL.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int myFun([In] byte[] inputBuffer, out IntPtr outputBuffer); byte[] a = Encoding.ASCII.GetBytes("sampletext!"); IntPtr b; res = myFun(a, out b);
Although I mentioned [InAttribute] for byte[] inputBuffer , the function still changed the values โโof a . The CLR seems to use its own default marshaling behavior. I used byte[] because it is the C # equivalent for unsigned char* .
When I replace byte[] with char[] , the CLR will follow my In-Out attributes.
I really appreciate your help. For more information, please read the msdn page .
source share