Thank you all for oppinions, but hang on with
fuhrter discussion. I haven’t even expected such
amount of answers I also see that I forgot to specify
some things more exactly, so I’m doing it now
The question had nothing to do with drivers,
even with kernel mode at all. The phenomenon
I observed was all in a small usermode testprogram.
(see below). It also was all in one process.
I mistypped the handle, it should be even (0x000007F4).
I tested the NtCreateFile against ReadFile again,
and it really does not seem to work (even if the handle
retrieved by NtCreateFile has the same numeric value
like the one returned by CreateFile).
Here is the code I used for test. It’s just a testprogram,
don’t write me that I forgot to close the handle or
there are some unused variables :-))
The NtCreateFile (if uncommented), ends with STATUS_SUCCESS.
The if you try to pass the handle to the ReadFile, it does not read anything
and returns ERROR_INVALID_PARAMETER (0x57).
If you want to see the complete testprogram as Visual Studio
project, get it from http://www.zezula.net/download/test.zip
As you can see, the testprogram is nothing special, just open and read.
void main(void)
{
OBJECT_ATTRIBUTES ObjAttr;
UNICODE_STRING NtFileName;
IO_STATUS_BLOCK IoStatus;
NTSTATUS Status = 0;
HANDLE hFile = NULL;
DWORD dwTransferred = 0;
TCHAR szNtFileName[MAX_PATH] = L"\??\E:\TestPST1.pst";
BYTE Buffer[200];
INIT_UNICODE_STRING(NtFileName, szNtFileName);
InitializeObjectAttributes(&ObjAttr, &NtFileName, OBJ_CASE_INSENSITIVE,
NULL, NULL);
/*
NtCreateFile(&hFile,
FILE_READ_DATA,
&ObjAttr,
&IoStatus,
NULL,
0,
FILE_SHARE_READ,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE,
NULL,
0);
*/
hFile = CreateFile(_T(“E:\TestPST1.pst”), FILE_READ_DATA,
FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if(hFile != INVALID_HANDLE_VALUE && hFile != NULL)
{
ReadFile(hFile, Buffer, sizeof(Buffer), &dwTransferred, NULL);
if(dwTransferred == 0)
Status = GetLastError();
}
}