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

Fortran+Visual basic (windows application)

ali_z_
Beginner
539 Views

Hi,

I'm developing a windows application that uses fortran DLL. I'm asking your help in two things:

1- I want the fortran to write on a console during the execution of the fortran code. I used the AllocConsole, the console appears when running the program but it's always empty.

2- I want the same message printed on a console window to be printed at the same time on a Listbox in the windows application. For this one i will be thankful if you can provide me with steps to do it. I don't even know if it's possible. 

I attached the program so you can check it.

Thanks in advance,

Li

0 Kudos
1 Solution
Steven_L_Intel1
Employee
539 Views

You need to say:

!DEC$ ATTRIBUTES STDCALL :: Fort1

You ignored the compiler's warning message telling you the syntax was wrong.

I clicked the button multiple times and it worked fine (once I added STDCALL).

View solution in original post

0 Kudos
7 Replies
Lorri_M_Intel
Employee
539 Views

I don't see a sample program attached.

             --Lorri

0 Kudos
ali_z_
Beginner
539 Views

It should appear now. 

Sorry about that !

0 Kudos
Steven_L_Intel1
Employee
539 Views

Ok, a few things.

First, you need to add STDCALL to the ATTRIBUTES line for the subroutine, or else you'll corrupt the stack.

Second, the reason you don't see the console window output is because the VB debugger captures and hides it. If you "Start without debugging" you will see the output. There's nothing we can do about this.

Third, there is no way to have the output automatically sent to both the console and a list box. You certainly can add code to the Fortran routine to do both, creating a MessageBox or some other form control to which you write output, but you can't use Fortran I/O directly to do these writes.

0 Kudos
ali_z_
Beginner
539 Views

Thank you Steve,

May i ask two more questions please. 

1) To add the STDCALL i simply added the following line to the fortran code:

!DEC$ ATTRIBUTES:: STDCALL

i added nothing to the VB Form. Is there anything else that i need to add ?

2) If i double click the windowsapplication.exe i can now see the output on the console when i click the button, however 

if i click the button 2 or three times i get the following message (see attached) how can i solve this ?

Thanks

0 Kudos
Steven_L_Intel1
Employee
540 Views

You need to say:

!DEC$ ATTRIBUTES STDCALL :: Fort1

You ignored the compiler's warning message telling you the syntax was wrong.

I clicked the button multiple times and it worked fine (once I added STDCALL).

0 Kudos
ali_z_
Beginner
539 Views

Thanks a lot Steve,

You helped me a lot.

Now it's working fine, the only problem left is if i added 

b=freeconsole() after the loop

and i click several times the button on windowsapplication.exe i get the same message i attached in my previous comment, even

if i added the STDCALL. I don't know if this could be solved. But thanks a lot for your help !

 

0 Kudos
Steven_L_Intel1
Employee
539 Views

Don't do the freeconsole - it will just cause problems.

0 Kudos
Reply