大家帮我看一下这段有关文件操作和内存分配代码问题出在什么地方?执行后会提示"存取未命名档案遭拒绝"错误.void myfunction(LPCTSTR strFileName)
{
CFile file;
HGLOBAL hGlobal=NULL; if(!file.Open(strFileName,CFile::modeRead||CFile::typeBinary))
return NULL;
DWORD dwSize=file.GetLength();
hGlobal=::GlobalAlloc(GHND,dwSize);
ASSERT(hGlobal!=NULL);
LPVOID pData=::GlobalLock(hGlobal);
ASSERT(pData!=NULL);
//read file and store in the global memorry;
DWORD dwReadSize=file.ReadHuge(pData,dwSize);
ASSERT(dwReadSize==dwSize);
file.Close();
::GlobalUnlock(hGlobal);
.......
.....
}
{
CFile file;
HGLOBAL hGlobal=NULL; if(!file.Open(strFileName,CFile::modeRead||CFile::typeBinary))
return NULL;
DWORD dwSize=file.GetLength();
hGlobal=::GlobalAlloc(GHND,dwSize);
ASSERT(hGlobal!=NULL);
LPVOID pData=::GlobalLock(hGlobal);
ASSERT(pData!=NULL);
//read file and store in the global memorry;
DWORD dwReadSize=file.ReadHuge(pData,dwSize);
ASSERT(dwReadSize==dwSize);
file.Close();
::GlobalUnlock(hGlobal);
.......
.....
}
CFile MyFilel(Namel,CFile::modeRead);
DWORD dwSize=MyFilel.GetLength();
void far *p=::GlobalAlloc(0,dwSize);
if(p==NULL)
AfxMessageBox("Alloc memory error");
MyFilel.ReadHuge(p,dwSize);
MyFilel.Close();
if(!file.Open(strFileName,CFile::modeRead|CFile::typeBinary))
return NULL;