memcpy用于托管数组到C ++中的托管类

时间:2018-07-31 10:23:50

标签: c++ marshalling memcpy managed-c++

如何将pinned_ptr复制到托管?

ManagedClass^ managed = gcnew ManagedClass();
array<unsigned char>^ temp = .....
pin_ptr<unsigned char> pinned_ptr = &temp[0];

//I TRIED THESE WAYS TO COPY:
memcpy(managed, pinned_ptr, sizeof(managed)); //ManagedStructure^ is incompatible parameter w,th void*
memcpy((void*)managed, pinned_ptr, sizeof(managed)); //invalid type conversion
memcpy((void*)&managed, pinned_ptr, sizeof(managed)); //invalid type conversion

然后,我尝试使用Marshal :: Copy那样:

Marshal::Copy(IntPtr((void*)managed), pinned_ptr, 0, sizeof(managed)); //no insatance of overloaded function Marshal::Copy 
//parameters list (System::IntPtr,  cli::pin_ptr<unsigned char>,int, unsigned int)

0 个答案:

没有答案