Hi I have developed my own device driver. It works fine, but when I try to
obtain current file pointer position I recieve zero.
Below you can see my test application:
*****
char dataBuffer[65535];
HANDLE h = CreateFile(“\\.\MyDriver”,GENERIC_READ|GENERIC_WRITE,
NULL,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
if(h == INVALID_HANDLE_VALUE) {
int nRetCode = GetLastError();
printf(“Error opening Device. %d.\n”,nRetCode);
return nRetCode;
}
for(DWORD index = 0; index < 10; index++) {
DWORD bytesRead;
if(!ReadFile(h,&dataBuffer[0],512,&bytesRead,NULL)) {
int nRetCode = GetLastError();
CloseHandle(h);
printf(“Error Read Device. %d.\n”,nRetCode);
return nRetCode;
}
int pos = SetFilePointer(h,0,NULL,FILE_CURRENT);
printf(“Pos = %lu”, pos);
}
**************
The ReadFile function is OK. bytesRead is set to 512 and the data recieved
in the dataBuffer is correct. So far so good…
When I call SetFilePointer to obtain current position I recieve 0. I
expected to recieve 512…Hmmm
If I call SetFilePointer to move the file pointer it works fine, then the
file pointer is updated correctly.
Do I have to update the file pointer inside my driver?
**** Driver code
irp->IoStatus.Information = bytesRead
irp->IoStatus.Status = STATUS_SUCCESS
IoCompleteRequest(irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;