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

Problem calling fortran dll from C#

nightfall
Beginner
1,377 Views

Hi

I have a big problem. I am writing a program in fortran-90, and now I need to make a GUI in C#. My problem is that I am not able to make the connection between the two languages. For the record, I am using Visual Studio 2003.

Earlier I have been using the Salford Fortran compiler, and I had no problem connecting to and from C#. I just had to make a dll out of my fortran files, and add a reference to this dll in my C# project. Now I have been forced to change to Intel Fortran Compiler, and I am no longer able to add the reference to the fortran dll. When I try to add the reference to the dll in my C# project, I get this error: A reference to could not be added. This is not a valid assembly or COM component. Only assemblies with extension dll and COM components can be referenced. Please make sure the file is accessible, and that it is a valid assembly or COM component. (If anyone wonder, my file HAS the extension dll, so I really dont understand the error message)

If anyone know anything, please contact me. I really need some help here

Sverre

0 Kudos
5 Replies
Steven_L_Intel1
Employee
1,377 Views
The Salford compiler generates managed code .NET assemblies - Intel Fortran does not. See here for tips on calling unmanaged DLLs from C#.
0 Kudos
nightfall
Beginner
1,377 Views
Thanks, that helped me a lot, but I still have some trubles.
This is a project where I got about 10.000 lines of pregenerated source code, witch was set up as a .exe-project. I now have problems converting this to an unmanaged dll. My solution now has 2 projects; one Console Application, and one Static Library. I have tried to make a Dynamic-link Library out of the Console Application, but this doesn't seem to work. When I try to call the dll from C#, I just get some error telling me the file doesn'e exists. (I have tried with just a small test project, and that worked fine from C#, but when I do the same thing with my existing console-app, I can't make it work.)
Is it possible to keep the console application (.exe file), and make it run on a command from C#? I don't have to send input or get output data from the fortan-project, it just have to run. (Input and output are through .txt files anyway...) Or does anyone have any other ideas?
(My problems are solved if some nice person could paste someC# code that launches an other .exe-file)
0 Kudos
Steven_L_Intel1
Employee
1,377 Views
I don't know C#, sorry.
0 Kudos
sabalan
New Contributor I
1,377 Views
Sverre, follow this thread. You may search this forum for C# and find several other threads. But I think that all of them deal with calling a DLL and not an EXE. I don't know C# but I think that you may need some system function in C# for calling an EXE.
Further, I would suggest that you try to debug your fortran code and see which file is missing. I would guess that there is a problem in a call to static library from your DLL.
Sabalan.
0 Kudos
g_f_thomas
Beginner
1,377 Views
Make a default c# console app (ConsoleApplication1) and change the default Class1 to read:

using System;

namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
System.Diagnostics.Process p=new System.Diagnostics.Process();
p.StartInfo.FileName = "Sine2D.exe";
p.Start();
}
}
}

Build and transfer ConsoleApplication1.exe to

C:Program FilesIntelFortranArrayVisualizersamplesFortranSine2DDebug

after you've built the Sine2D sample.

Now 2-click ConsoleApplication1.exe and see Sine2D.exe run.

HTH,
Gerry T.
0 Kudos
Reply