2011-03-03 50 views
3

我正在创建一个c#dll库来扫描进程内存。 我有静态方法:托管C++中的c#方法

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

,并希望把它在Visual C++托管使用。 如果我想在C++中调用像这样的方法,应该使用哪种类型的文本参数: searchASCII((int)pid, (char[])text, (int)position)

在当前情况下,我得到错误:

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

退房[此帖](http://stackoverflow.com/questions/2179270/pass-c -string-to-c-and-pass -c-result-string-char-whatever-to-c) – 2011-03-03 21:03:20

+0

那篇文章是错误的。 – 2011-03-03 21:17:18

回答

1

如果你想调用C++ \ CLI C#的功能,您将需要使用相同类型的。 C#中的数组实际上是C++ \ CLI中的cli::array<T,d>。您不会只能将C++ char[]转换为cli:array<T,d>。我会看看MSDN上的本地\管理interop

要调用从C++ \ CLI的功能,你必须创建一个这样的数组:

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

它是C++/CLI,MC++是一种不具有数组<>的不同语言。 – 2011-03-03 21:16:52