Can anyone illuminate the error of my ways?
NTSTATUS OpenAFile( PHANDLE pFileHandle, PUNICODE_STRING wszName, BOOLEAN
bCreate )
{
OBJECT_ATTRIBUTES oa;
IO_STATUS_BLOCK iosb;
NTSTATUS ntStatus;
RtlZeroMemory( &oa, sizeof(OBJECT_ATTRIBUTES) );
RtlZeroMemory( &iosb, sizeof(IO_STATUS_BLOCK) );
oa.Length = sizeof(OBJECT_ATTRIBUTES);
oa.RootDirectory = NULL;
oa.ObjectName = wszName;
oa.Attributes = OBJ_CASE_INSENSITIVE;
oa.SecurityDescriptor = NULL;
oa.SecurityQualityOfService = NULL;
ntStatus = ZwCreateFile( pFileHandle,
GENERIC_READ | GENERIC_WRITE,
&oa,
&iosb,
0,
FILE_ATTRIBUTE_NORMAL,
0,
bCreate ? FILE_OPEN_IF : FILE_OPEN,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0 );
return( ntStatus );
}
Luc
"Rich Warner" <rwa...@aol.com> wrote in message
news:uLc5wHykAHA.1424@tkmsftngp03...
Thanks,
Rich
Luc Kumps <NOkum...@pandora.be> wrote in message
news:Zh7h6.5302$w_6.2...@afrodite.telenet-ops.be...
Carl
--
-
"Rich Warner" <rwa...@aol.com> wrote in message
news:uLc5wHykAHA.1424@tkmsftngp03...
Carl
--
-
"Luc Kumps" <NOkum...@pandora.be> wrote in message
news:Zh7h6.5302$w_6.2...@afrodite.telenet-ops.be...
Rich
Carl Woodward <djc2000...@btinternet.com> wrote in message
news:9646vk$7j3$1...@neptunium.btinternet.com...
You could add:
DbgPrint( "wszName = %wZ\n", wszName );
to sanity check the string.
KM
1. I kept getting error c000000d (invalid parameter).
I looked up ZwCreateFile in the docs
(see http://www.microsoft.com/ddk/ddkdocs/win2k/k111_9dte.htm)
It says:
"FILE_SYNCHRONOUS_IO_NONALERT All operations on the file are performed
synchronously. Waits in the system to synchronize I/O queueing and
completion are not subject to alerts. This flag also causes the I/O system
to maintain the file position context. If this flag is set, the
DesiredAccess SYNCHRONIZE flag also must be set."
I added SYNCHRONIZE, and it worked!
2. I'm not sure if the DesiredAccess parameter supports GENERIC_READ. The
value GENERIC_READ is defined as 0x8000000L. But the corresponding value in
the above doc is FILE_READ_DATA, which is defined as 0x0001. GENERIC_WRITE
is 0x40000000, and FILE_WRITE_DATA is 0x0002
Therefore, I would specify
FILE_READ_DATE | FILE_WRITE_DATA | SYNCHRONIZE,
instead of
> GENERIC_READ | GENERIC_WRITE,
Now, you say you get c000003a instead of c000000d...
If you correctly initialized your UNICODE_STRING like this:
NT::UNICODE_STRING us;
NT::RtlInitUnicodeString(&us, L"\\??\\C:\\Windows\\Temp\\AFile.txt");
(and you probably did, otherwise you would get c0000033)
then the only reason I can see is that either c:\Windows and/or
c:\windows\temp do(es) not exist...
Luc
"Rich Warner" <rwa...@aol.com> wrote in message
news:uLc5wHykAHA.1424@tkmsftngp03...
Luc
"Luc Kumps" <NOkum...@pandora.be> wrote in message
news:d%vh6.9271$w_6.6...@afrodite.telenet-ops.be...
The GENERIC_* access masks are "generic" in that they apply to all object
types. At the time the object is opened/created the generic masks are mapped
to the corresponding type-specific masks. So, ZwCreateFile() maps
GENERIC_READ to FILE_GENERIC_READ. Likewise, ZwCreateKey() maps GENERIC_READ
to KEY_READ.
KM
Luc
"keithmo" <kei...@earthlink.SPAM.FREE.net> wrote in message
news:t8e5qfg...@corp.supernews.com...
Thanks,
Rich
This works on my system (after creating a \Windows and a \Windows\Temp
directory)
NT::RtlInitUnicodeString(&us, L"\\??\\C:\\Windows\\Temp\\AFile.txt" );
printf("%x\n", OpenAFile(&hFile, &us, TRUE));
(prints a "0", and "AFile.txt" is created)
Full source code below...
Luc
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
namespace NT {
extern "C" {
#pragma warning(disable: 4005)
#include <ntddk.h>
#pragma warning(default: 4005)
}
};
using NT::NTSTATUS;
NTSTATUS OpenAFile( PHANDLE pFileHandle, NT::PUNICODE_STRING wszName,
BOOLEAN bCreate )
{
NT::OBJECT_ATTRIBUTES oa;
NT::IO_STATUS_BLOCK iosb;
NT::NTSTATUS ntStatus;
RtlZeroMemory( &oa, sizeof(oa) );
RtlZeroMemory( &iosb, sizeof(iosb) );
oa.Length = sizeof(NT::OBJECT_ATTRIBUTES);
oa.RootDirectory = NULL;
oa.ObjectName = wszName;
oa.Attributes = OBJ_CASE_INSENSITIVE;
oa.SecurityDescriptor = NULL;
oa.SecurityQualityOfService = NULL;
ntStatus = NT::ZwCreateFile( pFileHandle,
FILE_GENERIC_READ | FILE_GENERIC_WRITE |
SYNCHRONIZE,
&oa,
&iosb,
0,
FILE_ATTRIBUTE_NORMAL,
0,
bCreate ? FILE_OPEN_IF : FILE_OPEN,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0 );
return( ntStatus );
}
int main(void) {
HANDLE hFile;
NT::UNICODE_STRING us;
NT::RtlInitUnicodeString(&us, L"\\??\\C:\\Windows\\Temp\\AFile.txt" );
printf("%x\n", OpenAFile(&hFile, &us, TRUE));
return 0;
}
"Rich Warner" <rwa...@aol.com> wrote in message
news:#8aLz8PlAHA.1412@tkmsftngp02...
You need to use the proper name of the device
before that point, not the DOS-compatibility name.
The proper name will be something like
\Device\Harddisk0\Partition1.
dave
--
To reply by mail, replace 'z' by 's'
"Rich Warner" <rwa...@aol.com> wrote in message
news:uLc5wHykAHA.1424@tkmsftngp03...
What I'm up to is porting a Win16 quasi-realtime database server for a data
acquisition application (well logging). It could all be done in a DLL
before! The target OSes are 98 and 2kPro. So far I've only tried on 98.
Thanks... Any more ideas?
Doug Haigh <dha...@junk.com> wrote in message
news:eAeHBSRlAHA.1804@tkmsftngp04...
Doug
"Rich Warner" <rwa...@aol.com> wrote in message
news:e7ikKtTlAHA.1720@tkmsftngp02...
Luc
"Rich Warner" <rwa...@aol.com> wrote in message
news:e7ikKtTlAHA.1720@tkmsftngp02...
Thanks to the link to Mr. Oney's site. I already had the book on its way to
me.
Rich
Doug Haigh <dha...@junk.com> wrote in message
news:OJ1wjnWlAHA.1384@tkmsftngp04...
Rich
Luc Kumps <NOkum...@pandora.be> wrote in message
news:9q6i6.5942$Tu.2...@afrodite.telenet-ops.be...
"Rich Warner" <rwa...@aol.com> wrote in message
news:#bdrlq4kAHA.1324@tkmsftngp05...