日期:2014-05-18 浏览次数:21411 次
unsafe
{
// read file to buffer and close the file.
FileStream sFile = new FileStream("d:\\Microsoft C Program.doc", FileMode.Open);
long nFileLen = sFile.Length;
byte[] fileData = new byte[nFileLen];
sFile.Read(fileData, 0, (int)nFileLen);
sFile.Close();
// allocate buffer for compressing
int nCompress = 0;
byte[] data = new byte[nFileLen+100];
fixed (byte* pCompress = data, pFile = &fileData)
{
CheckMem(pFile, nFileLen, pCompress, nFileLen + 100);//pCompress访问出错
nCompress = Compress2(pFile, nFileLen, pCompress);
}
}
unsafe
{
// read file to buffer and close the file.
FileStream sFile = new FileStream("d:\\Microsoft C Program.doc", FileMode.Open);
long nFileLen = sFile.Length;
byte[] fileData = new byte[nFileLen];
sFile.Read(fileData, 0, (int)nFileLen);
sFile.Close();
IntPtr pData = Marshal.AllocHGlobal((int)nFileLen);
Marshal.Copy(fileData, 0, pData, (int)nFileLen);
int nCompress = 0;
// allocate buffer for compressing
IntPtr pCompress = Marshal.AllocHGlobal((int)(nFileLen+100));
CheckMem(pData, pCompress, nFileLen, nFileLen+100);
}