我使用的混合組件用下面的代碼:託管C++/CLI陣列轉換錯誤
#include "stdafx.h"
#pragma managed
using namespace System::Security::Cryptography;
array<System::Byte, 1> ^ComputeHashS(array<System::Byte, 1> ^Data) {
RIPEMD160Managed^ r = gcnew RIPEMD160Managed();
return r->ComputeHash(Data);
}
#pragma unmanaged
BYTE *DoWork(BYTE *Data) {
BYTE *n = ComputeHashS(Data);
return DoSomething(n, 20);
}
其中DoSomething的(陣列,LEN)是一個非託管C++函數。不過,我得到以下錯誤:
argument of type "BYTE *" is incompatible with parameter of type "cli::array<unsigned char, 1> ^".
我是新的C++/CLI,特別是混合模式的組件,所以我怎麼能解決這個問題?
使用pin_ptr:http://msdn.microsoft.com/en-us/library/1dz8byfh.aspx – 2014-09-01 07:53:32
不能編譯功能非託管代碼。您不能使用pin_ptr <>,當其他代碼訪問BYTE *時,該數組將不再被鎖定。返回指向數組的原始指針的最明顯的問題是調用者不知道數組可能會有多久,並且不能可靠地釋放爲數組分配的內存。您需要首先解決這些問題,然後才能考慮從託管代碼調用該功能。 – 2014-09-01 10:48:35