I have a Memory stream object in C# containing xml data.
fileEntity = new FileEntity();
fileEntity.Bytes = new byte[stream[0].Length];
fileEntity.FileName = ConfigurationManager.AppSettings["BackupPath"].ToString() + "\\" + backupEntity.BackupFileName;
stream.Position = 0;
stream.Read(fileEntity.Bytes, 0, (int)stream[0].Length);
When I write the fileEntity.Bytes to a file in C#, it gets generated correctly.
However, I need to access bytes in C++ using COM and write the bytes to file.
pSABytes = fileentity->GetBytes();
bytes = (byte*)pSABytes;
LONG ub;
HRESULT res = SafeArrayGetUBound(pSABytes, 1, &ub);
FILE* file = fopen("c:\\Abc.xml", "w+");
fwrite( bytes, 1, ub, file );
fclose(file);
However I get an exception on line fwrite(bytes,1,ub,file)
Unhandled exception at 0x5f268962 (msvcr100d.dll) in COM.exe: 0xC0000005: Access violation reading location 0x000000001cf1d000.