void CopyMemoryDataToNewArray(int *DataPointer, int DataSize) { array<System::Byte>^ ByteArray = gcnew array<System::Byte>(DataSize); pin_ptr<Byte> desPointer = &ByteArray[ByteArray->GetLowerBound(0)]; //exception is thrown in the line: Attempted to read or write protected memory. memcpy_s(desPointer, sizeof(ByteArray), DataPointer, sizeof(ByteArray)); } int main(array<System::String ^> ^args) { System::String ^ImgFileName = "SampleImage2.jpg"; //get the img byte array array<System::Byte>^ DataArray = ImageToByteArray(ImgFileName); //try to get the pointer of img address int* _pointer = (int*)DataArray[0]; CopyMemoryDataToNewArray(_pointer, DataArray::Length); }
int* _pointer = (int*)DataArray[0];
int* _pointer = (int*)&DataArray[0];
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)