Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

Getting the Windows Handle (Fortran POSIX File Descriptor)

$
0
0

The user manual for ifort 2015 Update 4 subroutine PXFFILENO suggests that in the Windows OS, I can get the file descriptor (handle returned from CreateFile) associated with a Fortran File Unit number.  I tried the following code accordingly:

(Fortran:)

      EXTERNAL  UOPEN

      INTEGER(INT_PTR_KIND()) UOPEN

     

      CALL PXFPOSIXIO (1,iold,ierror)

      OPEN(UNIT=10,FILE='UOPEN.DAT',STATUS='NEW',USEROPEN=UOpen)

      write(10,*)"hi"

      flush(10)

      CALL PXFFILENO (10,fd,ierror)

(C++:)

extern "C" __declspec(dllexport) void* UOPEN(

                _In_     char*                 lpFileName,

                _In_     DWORD                 dwDesiredAccess,

                _In_     DWORD                 dwShareMode,

                _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,

                _In_     DWORD                 dwCreationDisposition,

                _In_     DWORD                 dwFlagsAndAttributes,

                _In_opt_ HANDLE                hTemplateFile,

                _In_     int&                  UNIT)//,

                //            _In_     int&                  FLEN)

{

                BOOL bResult1 = CreatePipe(&hReadPipe, &hWritePipe, 0, 100000000);//100e6

                DWORD err1 = GetLastError();

                //HANDLE hMapping = CreateMailslot(L"Some super cool mailslot for MAAP", 0, 1000000, 0);

                // PAGE_READWRITE | SEC_COMMIT

                char*Bytes = new char[100000000];//100e6

                DWORD bytesWritten;

                for (int i = 0; i < 99000000; ++i)

                                Bytes[i] = 'n';

 

                BOOL bResult = WriteFile(hWritePipe, Bytes, 99000000, &bytesWritten, 0);

                DWORD err = GetLastError();

 

                //HANDLE hProcess = GetCurrentProcess();

                //DuplicateHandle(hProcess, hResult, hProcess, &hFile, 0, FALSE, DUPLICATE_SAME_ACCESS);

                //hFile = hResult;

                delete[]Bytes;

                return hWritePipe;

}

 

I know that hWritePipe is 0x88, so I would expect fd to be 0x88.  However, fd comes back as 3.  That is not a valid handle.  So, what am I doing wrong?  Is the description in the user manual wrong?  I very desparately want that handle in the Fortran code to avoid writing spaghetti code.


Viewing all articles
Browse latest Browse all 3270

Trending Articles