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

Showing output from DLL in console

Jamal_S_
Beginner
1,137 Views

Hello,

I am working on a program where I am using Visual Basic for the interface and a Fortran dll for computations.  When I call the DLL using an event in the Visual Basic interface, I would like to print a message to the user through the console using the write() function in Fortran, while also having the VB interface open as well.  

If it is helpful for you to know, my previous attempts to do this have so far failed:  when I do not include the pause statement, nothing seems to happen (the console possibly opens then closes before I can even see it). However, when I do include a pause statement, the console flickers on and off endlessly.

How do I go about getting this to work?

Thanks,

Jamal

0 Kudos
5 Replies
JVanB
Valued Contributor II
1,137 Views

It looks like AllocConsole is the thing to do, but I've never tried it. https://software.intel.com/en-us/forums/topic/276059

0 Kudos
Steven_L_Intel1
Employee
1,137 Views

I have used AllocConsole. You'll want to call that before doing any I/O. However, let me point out that the console window might get hidden behind the VB window so that may not be a good solution. If you are displaying a message, I prefer using the Windows API MessageBox for this.

0 Kudos
FortranFan
Honored Contributor II
1,137 Views

Take a look at this thread: https://software.intel.com/en-us/forums/topic/509148

I would suggest you consider a callback facility where Fortran invokes a VB function to pass messages and the VB function (that would be part of your VB interface), will then redirect wherever, to a console, a database, text file, etc.  It's rather straightforward, especially if your VB interface is in .NET in which case you can totally stick to standard C interoperability features from Fortran 2003 onward.

 

0 Kudos
Greg_T_
Valued Contributor I
1,137 Views

Do you want to display a message in the GUI after the Fortran DLL has completed its task, or write progress messages while the DLL is working?  For our VB or C# GUI we pass a message with the status/warning/error text and an integer flag to indicate the status from the Fortran DLL back to the GUI, and then display the message somewhere in the GUI using a text box or message box, which seems to work very well and is pretty easy to implement.  Perhaps this would be adequate for your program.

Regards,

Greg

0 Kudos
Jamal_S_
Beginner
1,137 Views

Hello everyone,

Thank you for your replies to my question.  Until now, I have only used the AllocConsole method that Repeat Offender directed me to, and it has worked to an extent.  I will certainly try out everyone else's suggestions, but right now I am determined to make the console method work properly now that it is nearly complete.  Also, I did not have the problem of the console appearing behind the VB form.

According to my tests, the read function for the console is working, but oddly, the write function isn't.  Here is the code I have for the console:

 

    use ISO_FORTRAN_ENV
    use Variables
    use kernel32
    use ifwin

    implicit none

!DEC$ ATTRIBUTES STDCALL,DLLEXPORT::Test  
    
    Integer(INT16), value :: D1
    Integer(INT16), value :: D2
    Integer(INT16), value :: D3
    
    real i, j,k
    integer kk,jj,ii   
    
    integer lines,length
    logical status 
    integer fhandle    
    Type(T_COORD) wpos 
   
    ***Body of DLL omitted***

    status= AllocConsole()
    fhandle = GetStdHandle(STD_OUTPUT_HANDLE)
    wpos.x = length
    wpos.y = lines
    status = SetConsoleScreenBufferSize(fhandle, wpos)    
    write(*,*) h1, h2, h3
    write(*,*) ii, jj, k
    write(*,*) "Press any key when done viewing."
    read(*,*) lines
    write(*,*) lines
    wpos.y = lines
    status = SetConsoleScreenBufferSize(fhandle, wpos)
    read(*,*)
    status = FreeConsole()

I know it is reading because if I feed it a character for the lines variable, I get an error.  However, it is not writing any of the lines it is supposed to, nor does it update the y-position of the form after I update the lines variable.  Why is it that not all the functions of the console are working?

Thanks,

Jamal

 

0 Kudos
Reply