Currently working on open/read images in VC++.
Some examples i came across on the internet use Windows.h I/O routines like ReadFile...but there seems to be inconsistency in there declaration.
Here's what i have got.
//So i have this function to load file
BYTE* LoadFile ( int* width, int* height, long* size, LPCWSTR bmpfile )
{
BITMAPFILEHEADER bmpheader;
BITMAPINFOHEADER bmpinfo;
DWORD bytesread = 0;
HANDLE file = CreateFile ( bmpfile , GENERIC_READ, FILE_SHARE_READ,NULL,
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL );
if ( NULL == file )
return NULL;
if ( ReadFile ( file, &bmpheader, sizeof ( BITMAPFILEHEADER ),&bytesread,
NULL ) == false )
{
CloseHandle ( file );
return NULL;
}
.
.
.
return appropriate value;
}
Now the ReadFile API function is declared as follows in WinBase.h
WINBASEAPI BOOL WINAPI ReadFile(
In HANDLE hFile,
Out LPVOID lpBuffer,
In DWORD nNumberOfBytesToRead,
_Out_opt_ LPDWORD lpNumberOfBytesRead,
_Inout_opt_ LPOVERLAPPED lpOverlapped
);
And in MSDN examples...
They call this function like this.
ReadFile(hFile, chBuffer, BUFSIZE, &dwBytesRead, NULL)
Which expects that "bytesRead" is sort of out parameter. so it gives me number of bytes read.
But in my code ..it is giving error message.
'ReadFile' : cannot convert parameter 4 from 'LPDWORD *' to 'LPDWORD'
so i just initialized bytesRead to 0 and passed by value.( which is wrong..but just to check if it works ).
then it gives this exception
Unhandled exception at 0x774406ae in ImProc.exe: 0xC0000005: Access violation
writing location 0x00000000.
Kindly suggest .
Kindly tell if any code i missed out....including while forming the question itself.
Thanks.