void DragFiles( HWND hWnd, HDROP hDrop)
{
TCHAR szFileName[_MAX_PATH + 1];
DragQueryFile( hDrop, 0, (LPTSTR)szFileName, _MAX_PATH + 1 );
OFSTRUCT sOFile;
HFILE hFile = OpenFile( (LPTSTR)szFileName, &sOFile, OF_READ );
DWORD BytesToRead;
BytesToRead = GetFileSize( (void*)hFile, NULL );
TCHAR* lpBuffer = new TCHAR[BytesToRead]; // Problematic
ULONG lpBytesRead;
if( !( ReadFile( (void*)hFile, &lpBuffer , BytesToRead, &lpBytesRead, NULL ) ) )
{
return;
}
}
Dynamic array doesn't work properly
I'm using MS Visual C++ 6.0
When I want to use a new operator to declare new TCHAR array, the function doesn't work properly anymore. When I execute this, then the reading-result should be in lpBuffer. But instead it is assigning it in the szFileName array.
What am I doing wrong?
read this line carefully:
You are sending the adress of your pointer to ReadFile. The pointer should be sent by value, that way readfile will write to wherever the pointer is pointing to.
if( !( ReadFile( (void*)hFile, &lpBuffer , BytesToRead, &lpBytesRead, NULL ) ) )
You are sending the adress of your pointer to ReadFile. The pointer should be sent by value, that way readfile will write to wherever the pointer is pointing to.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement