>In my c#-app I have got a byte[]-array, which should somehow be mapped to a
>char* in my managed-c++-function.
If you're really using managed C++, why don't you wrap this in a class
and reference the assembly from C# instead of going through P/Invoke?
>void MyFunction(char* buffer)
>{
> buffer = "Hello from managed c++!";
>}
This is briken. All your code is doing is reassigning the local copy
of the buffer pointer. To write into the existing buffer you should
use a function like memcpy or strcpy.
And to prevent a buffer overrun, you should pass in the buffer size as
an additional parameter.
>[DllImport("c++ClassLib.dll")] // import the c++ dll
>private extern static void MyFunction(ref byte[] byteStream);
The parameter shouldn't be declared "ref".
>On the other hand, I could use some "intermediate" data types like an Array
>if this would make things work (that is first converting the byteStream to
>the Array, call the function, and within MyFunction convert the Array back
>to char*).
You already have an array of bytes. I'm not sure why you've chosen to
name the variable byteStream, because it isn't a stream (at least not
in .NET System.IO terminology).
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.