I'm writing a c# console application that uses a C++ class library. In C++ language class library I have a method:
public:bool GetMDC(char fileName[], char mdcStrOut[]){
// My Code goes Here
}
This method gets a file path in fileName parameter and puts a value in mdcStrOut.
I add this class library as reference to my C# console application. when I want to call GetMDC method the method needs two sbyte parameters. So it's signature in c# is GetMDC(sbyte* fileName, sbyte* mdcStrOut).
My code looks like this:
unsafe{
byte[] bytes = Encoding.ASCII.GetBytes(fileName);
var _mdc = new TelsaMDC.TelsaMDCDetection();
var outPut = new sbyte();
fixed (byte* p = bytes)
{
var sp = (sbyte*)p;
//SP is now what you want
_mdc.GetMDC(sp, &outPut);
}
}
It works without error. But the problem is that outPut variable only contains the first character of mdcStrOut. I'm unfamiliar with C++. I know that I'm passing the memory address of output to the GetMDC. So how can I get the value of it in my console application?
EDIT
when I declare output variable like this var outPut = new sbyte[MaxLength] I get an error on _mdc.GetMDC(sp, &outPut); line on the & sign. It says: Cannot take the address of, get the size of, or declare a pointer to a managed type ('sbyte[]')