C # method in managed C ++

I am creating a C # dll library to scan process memory. I have a 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 suitable for use in Visual C ++ Managed. What type should be used for the text parameter if I want to call a method like this in C ++ searchASCII((int)pid, (char[])text, (int)position):?

In the current scenario, I get an error message:

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

If you want to call the C # function in C ++ \ CLI, you will need the same types. An array in C # is actually cli::array<T,d>in C ++ \ CLI. You can't just tell C ++ char[]to cli:array<T,d>. I would look at native \ managed interop on MSDN.

To call a function from C ++ \ CLI, you need to create an array like this:

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

Source: https://habr.com/ru/post/1796146/


All Articles