- HANDLE CompletionPort = NULL;
- NTSTATUS errCode;
- FILE_COMPLETION_INFORMATION CompletionInformation;
- IO_STATUS_BLOCK IoStatusBlock;
-
- if ( ExistingCompletionPort == NULL && FileHandle == INVALID_HANDLE_VALUE ) {
- SetLastErrorByStatus (STATUS_INVALID_PARAMETER);
- return FALSE;
- }
-
- if ( ExistingCompletionPort != NULL ) {
- CompletionPort = ExistingCompletionPort;
- }
- else {
- errCode = NtCreateIoCompletion(&CompletionPort,GENERIC_ALL,&IoStatusBlock,NumberOfConcurrentThreads);
- if (!NT_SUCCESS(errCode) ) {
- SetLastErrorByStatus (errCode);
- return FALSE;
- }
-
- }
- if ( FileHandle != INVALID_HANDLE_VALUE ) {
-
- CompletionInformation.CompletionPort = CompletionPort;
- CompletionInformation.CompletionKey = CompletionKey;
-
- errCode = NtSetInformationFile(FileHandle, &IoStatusBlock,&CompletionInformation,sizeof(FILE_COMPLETION_INFORMATION),FileCompletionInformation);
- if ( !NT_SUCCESS(errCode) ) {
- if ( ExistingCompletionPort == NULL )
- NtClose(CompletionPort);
- SetLastErrorByStatus (errCode);
- return FALSE;
- }
- }
-
- return CompletionPort;
+ HANDLE CompletionPort = NULL;
+ NTSTATUS errCode;
+ FILE_COMPLETION_INFORMATION CompletionInformation;
+ IO_STATUS_BLOCK IoStatusBlock;
+
+ if ( ExistingCompletionPort == NULL && FileHandle == INVALID_HANDLE_VALUE )
+ {
+ SetLastErrorByStatus (STATUS_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ if ( ExistingCompletionPort != NULL )
+ {
+ CompletionPort = ExistingCompletionPort;
+ }
+ else
+ {
+
+ errCode = NtCreateIoCompletion(&CompletionPort,
+ IO_COMPLETION_ALL_ACCESS,
+ NULL,//ObjectAttributes
+ NumberOfConcurrentThreads);
+
+ if (!NT_SUCCESS(errCode) )
+ {
+ SetLastErrorByStatus (errCode);
+ return FALSE;
+ }
+
+ }
+
+ if ( FileHandle != INVALID_HANDLE_VALUE )
+ {
+ CompletionInformation.IoCompletionHandle = CompletionPort;
+ CompletionInformation.CompletionKey = CompletionKey;
+
+ errCode = NtSetInformationFile(FileHandle,
+ &IoStatusBlock,
+ &CompletionInformation,
+ sizeof(FILE_COMPLETION_INFORMATION),
+ FileCompletionInformation);
+
+ if ( !NT_SUCCESS(errCode) )
+ {
+ if ( ExistingCompletionPort == NULL )
+ {
+ NtClose(CompletionPort);
+ }
+
+ SetLastErrorByStatus (errCode);
+ return FALSE;
+ }
+ }
+
+ return CompletionPort;