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

I wish to open a window from a .dll

sbenati
Beginner
641 Views
Hi Hi-Tech Gurus!
I have a VBA application that from Excel calls mysource.dll.
It performs heavy computations: they could last several hours. So I wish that during the computation (that is, while mysource.dll is executed), a (console)window appears and says:
"Iteration 1"
and after a while
"Iteration 2", and so on.
If I wrote a Console application, itcan beobtained through:
print *, "Iteration", it ;
where "it" is a counter.
The last instruction is not executed by the .dll, so I wonder wheter there is a way to code the instruction: "Open a window and print there all the fortran messages that are required during the execution of mysource.dll".
I read the manual and the forum, but I was not able to find any idea, so any suggestions is really welcome! (By the way, I work with CVF 6.6)
All the best, Stefano
0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
641 Views

AllocConsole() and FreeConsole() APIs create and destroy a console window if there isn't any (as there's only one console per process allowed). Subsequent Fortran WRITEs should be able to operate on that console; I'm not sure, however, ifthey wouldin your setup (dll called from a non-Fortran app). If it doesn't, WriteConsole API should work.

Jugoslav

0 Kudos
sbenati
Beginner
641 Views
Many thanks! At least I know which pages of the programmer's guide I have to read!
I do not want to bother you with simple questions, (I do not know anything on Window programming), but the API functions AllocConsole() and FreeConsole() are described in a C++ (or similar) semantyc (in the guide).
Moreover,if I write in the source code of mydll.f90:
.....
LOGICAL result
.....
result = AllocConsole()
.....
the linker answers "unresolved external _ALLOCCONSOLE@0".
The only suggestion in the guide is that "kernel32.lib" must be available to the project (as it is).
Now my problem is, how can I put AllocConsole() and FreeConsole() in my fortran source code?
Thank you for the collaboration, Stefano
0 Kudos
Jugoslav_Dujic
Valued Contributor II
641 Views

AllocConsole etc. are native Windows APIs. CVF includes (almost) full translation of API functions & structures. However, the documentation (under "Platform SDK" branch) is still in C (as it's original Microsoft documentation); so you have to do some mental translation.

The modules are named KERNEL32, USER32, (the same as .lib mentioned in CVF docs); also, USE DFWINpulls in all the Win32 API modules. If in doubt, you canfind the searched function/structin appropriate module(or do a "Find in Files" in ...Visual StudioDF98Include) and see the Fortran INTERFACE/TYPE to it. For example, having seen the interface to above-mentioned WriteConsole (it's a tricky one due to lot of pointers (LPxxxx types)), a correct call to outputan integeron the console would be:

USE KERNEL32
CHARACTER(10):: sOut
INTEGER:: i, nOut
i = 42
WRITE(sOut, *) i !You have to write to a string first
result = WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), &
LOC(sOut), LEN_TRIM(sOut), LOC(nOut), 0)

So, you have to USE KERNEL32 or USE DFWIN to be able tobuild AllocConsole etc.

Jugoslav

0 Kudos
sbenati
Beginner
641 Views

OK Yugoslav! I forgot the USE statement!:smileyvery-happy:

The correct code is:

......

USE kernel32

logical s

s = AllocConsole()

print *, "Hallo world!"

pause

s = FreeConsole()

....

and then, during the execution of the Excel macro, a window appears!
I tried to use the WriteConsole technique, but Excel always crashed with message errors that are hard to understand (to me, of course).
In any case, the previous piece code is all that I need.
Thanks again, Stefano
0 Kudos
Reply