Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28435 Discussions

Console Window in DLL using Windows 10

Bruce_Barker
Beginner
477 Views

I have a FORTRAN DLL application that performs a prolonged series of calculations. To give feedback to the user, we opened a console screen and printed messages on the routines progress. This code has worked great under Windows 7 but now under Windows 10, we're having an issue with the data files remaining locked after the DLL routine finishes.

After the DLL routine finishes, data files that are accessed by the DLL remain locked and can't be opened by the program used to call the DLL. The parent program is an old VB6 application. If we get rid of the console calls in the DLL, then the files are not locked and the parent program can access them just fine.

The code we used to start the console, write data, and close it was adapted from your article: "Code Samples for Console Use", e.g.:

      USE IFWIN
! Allocate a console
      status = AllocConsole() ! get a console window of the currently set size
      fhandle = GetStdHandle(STD_OUTPUT_HANDLE)

! Executable code to set console window size
      sr.top    =   0 
    sr.left   =   0
      sr.bottom =   23 ! <= console buffer height -1
      sr.right  =   80 ! <= console buffer width  -1
      lstat = SetConsoleWindowInfo(fhandle, .TRUE., sr)

! Set a console buffer bigger than the console window. This provides
! scroll bars on the console window to scroll through the console buffer
! Set buffer size variables
      lengthCON = 80
    lines  = 25
      wpos.x = lengthCON   ! must be >= currently set console window line length
      wpos.y = lines       ! must be >= currently set console window number of lines
      lstat = SetConsoleScreenBufferSize(fhandle, wpos)

etc...

        CLOSE(11,ERR=9199,IOSTAT=IOstat11)  
          CALL SLEEPQQ(1500) 
          status = FreeConsole() 
          RETURN         !******* Normal Return for Quick Solution

 

0 Kudos
2 Replies
JohnNichols
Valued Contributor III
475 Views

I tried this type of stuff years ago and just got frustrated - why not just do a screen write every few seconds to let them know it is going

a good on is '.' and let it progress across the screen

 

0 Kudos
Steven_L_Intel1
Employee
477 Views

I can't reproduce this. I used the attached sources, and tested it first without the close so I could see the error. I then put the close back in. Runs fine on Win7 and Win10.

ifort /dll fdll.f90
ifort /winapp /libs:dll U611586.f90 fdll.lib
U611586.exe

Please provide a small but complete test case I can use.

0 Kudos
Reply