Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
45 Views

Example of C# WPF GUI calling FORTRAN DLL and callback

Jump to solution

Dear Friends:

I beginning a project to port a Fortran console app to Windows. I would like to allow the user the enter data via WPF (windows) GUI, submit the data for analysis and then receive the results back in the GUI to display them in graphical format.

I have noticed in other (closed) threads that other people has done this succesfuly. For example, Greg T. in this thread seems to have accomplished something like what I am trying to do:

https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/563649#comme...

under subject heading: "Reference Material for Visual Fortran Windowing Applications".

Could anyone please share sample code or segments to show or a reference on how to?

(1)  Call a Function in a Fortran DLL 

(2) Callback from Fortran a WPF window (class)

(3) How to set up such a project with VS 2013 Pro to create the C# program and Fortran DLL.

Thanks in advance for any help.

I. Konuk

0 Kudos

Accepted Solutions
Highlighted
Honored Contributor I
45 Views

Take a look at this thread: https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/509148

Even though the above link is for Visual Basic .NET example which makes use of regular Windows Form(s), the same exact concepts hold with C# and WPF.  You should be able to take this fully worked out example and adapt it for your needs.

 

View solution in original post

0 Kudos
6 Replies
Highlighted
Honored Contributor I
46 Views

Take a look at this thread: https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/509148

Even though the above link is for Visual Basic .NET example which makes use of regular Windows Form(s), the same exact concepts hold with C# and WPF.  You should be able to take this fully worked out example and adapt it for your needs.

 

View solution in original post

0 Kudos
Highlighted
New Contributor I
45 Views

Dear FortranFan:

Thank you indeed very much for the quick response. I have actually located your responses (after submitting my question - apologies for the order)  in other similar threads and trying to find my way around with your example.

I may find it myself during my experiments, nonetheless if you get a chance, would you let me know how you would start a brand new project? As a new WPF application or a Fortran application? I am working with Visual Studio 2013 and latest Intel Fortran compiler.

Thank you again very much for your help and your time to help people like me. (People like you make the community much richer.)

Best regards;

I. Konuk

0 Kudos
Highlighted
New Contributor I
45 Views

Dear FortranFan:

My problem may be my lack of VS knowledge. I did the following.

I copied HelloWorld folder.

Then I opened the solution under you folder HelloWorld_Basic. I can see under SolutionExplorer two projects. I can see an app.config (XML) and frmHelloWorld.vb source and window definition (resource). I changed the path to the Fortran.dll to “ …bin\x86\Debug\” in the VB source and changed DLL to dll. I build the solution. It indicated that two projects are built. I edited the Solution Properties to indicate a Single startup project with HelloWorld_Basic as the startup file. I changed the dependencies to include HelloWorld_Fortran. I saved the changes.

When I start from Start without debugging, the Form1 window opens. When I press [Run] button,

“From VB.NET: Starting Fortran”

then, I get the error shown on the attached image..

I am sorry to take your time for probably very simple issue. I would appreciate any help you can provide to progress to the next step.

Best regards;

I. Konuk

0 Kudos
Highlighted
Honored Contributor I
45 Views

Ibrahim K. wrote:

.. would you let me know how you would start a brand new project? As a new WPF application or a Fortran application? I am working with Visual Studio 2013 and latest Intel Fortran compiler. ..

@I. Konuk,

My approach will be as shown in the above-referenced thread with the VB.NET example where I would have a single Visual Studio solution (sln file) with multiple projects: Fortran project(s) (vfproj file) to create static library and/or dynamic library (DLL) files and .NET assembly projects (csproj for C# or vbproj for Visual Basic) to create class library (again DLLs) and/or Windows Form Application(s) and/or Console application(s) (usually these are useful as unit tests).

As you would know, for .NET projects using Visual Studio, there is a ton of information at MSDN.com and various other online forums that would be a lot more informative for you than this one.

This forum naturally can be useful for Fortran-related matters.  For Fortran projects in Visual Studio, I assume you are aware of online help: https://software.intel.com/en-us/intel-fortran-compiler-17.0-user-and-reference-guide

Note for debugging purposes, in your .NET projects that invoke Fortran procedures, you may want to "Enable Native Code Debugging" under Project Properties -> Debug.

0 Kudos
Highlighted
Honored Contributor I
45 Views

Ibrahim K. wrote:

.. I changed the path to the Fortran.dll to “ …bin\x86\Debug\” in the VB source and changed DLL to dll. I build the solution. It indicated that two projects are built. I edited the Solution Properties to indicate a Single startup project with HelloWorld_Basic as the startup file. I changed the dependencies to include HelloWorld_Fortran. I saved the changes... then, I get the error shown on the attached image.. ..

@I. Konuk,

If you are not familiar with Visual Studio, you can follow up on resources like this one or MSDN.com or many other online forums.

I prefer not to explicitly state the Fortran DLL path in Visual Basic code, rather simply provide the file name and have Windows search scheme find it based on my direction e.g., I create folders such as C:\bin\Win32 and/or C:\bin\x64 and add them to my PATH.  Then I have the Fortran project copy the built DLL to the appropriate path as a post-build event.

The error you show seems to due to the .NET executable being unable to locate the created Fortran DLL.  As a quick test, you can copy the Fortran DLL, most likely in HelloWorld_Fortran\Win32\Debug folder to HelloWorld_Basic\bin\x86\Debug folder and retry the test and to see how the code works.  Once you understand the details, you can decide how best to organize your files.

Immediately you can keep in mind invoking Fortran from .NET (WPF or otherwise) is the same as other consuming unmanaged code via P/Invoke layer.  

0 Kudos
Highlighted
New Contributor I
45 Views

Dear FortranFan:

I changed the Target Platform to x86 and it all worked.

Now that I get the main idea and have a working sample, with the detailed road map you provided, I should be OK for a while.

Thank you again very much.

I. Konuk

0 Kudos