c# method in managed c++

254 views Asked by At

I'm creating a c# dll library to scan process memory. I have static method:

int searchASCII(int pid, SByte[] text, int pos)
        {
            ReadProcessApi RApi = new ReadProcessApi(pid, pos);
            return RApi.ASCIIScan(text);
        }

and want to make it usable in Visual C++ Managed. Which type should be used for text param, if I want to call method like this in c++: searchASCII((int)pid, (char[])text, (int)position) ?

In current scenario I get error:

"cannot convert parameter from 'char [6]' to 'cli::array<Type,dimension> ^' "  
1

There are 1 answers

1
linuxuser27 On

If you want to call a C# function in C++\CLI you will need use the same types. An array in C# is actually a cli::array<T,d> in C++\CLI. You will not just be able to cast a C++ char[] to a cli:array<T,d>. I would take a look at the native\managed interop on MSDN.

To call the function from C++\CLI you will have to create an array like this:

cli::array<System::SByte> ^text = gcnew cli::array<System::SByte>(/* some_size */);