Silverfrost Forums

Welcome to our forums

Create Fortran Dll to be used in .NET under Window7 X64

31 Jan 2011 4:36 #7660

I write an UI with Visual Studio 2010 Express and Fortran subroutines with Plato 3 I want to call one of these routine from my .NET application Inside this application I define :

Public Class Unmnaged Declare Auto Sub RESOLVE Lib 'D:\RESOLUTION.dll' (<In, Out()> ByRef kont As Integer, <In, Out()> ByRef mat As Integer) End Class

Dim kont, mat(80) As Integer

and I call the routine by the following way :

Call Unmnaged.RESOLVE(kont, mat(0))

To create the RESOLUTION.Dll file I compile and link whith :

FTN95 'D:\RESOLUTION.f95' slink RESOLUTION.opt RESOLUTION.dll

'D:\RESOLUTION.f95' is my source code written with Plato . Its begining is : subroutine RESOLVE (kont,mat1)

INTEGER,INTENT(INOUT):: kont INTEGER,INTENT(INOUT):: mat1( : )

The file RESOLUTION.opt contains : dll load RESOLUTION exportall archive RESOLUTION.lib file RESOLUTION.dll

When I run the application from whithin Visual Studio 2010 Express I get the message : (originaly the message is in French ! That's my translation !)

Message: runtime met an irremediable error. The address of the error was 0x6df57e06 on the thread 0xa1c. The code of error is 0xc0000005. It is maybe about a bug in the CLR or in the portions unsafe or not verifiable of the user code. The common causes of this bug include errors of marshaling user for COM-Interop or PInvoke, errors susceptible to damage the stack.

Have somebody an idea about that ?

Thanks

31 Jan 2011 6:33 #7661

Jeanot

You need to target the .NET framework when compiling the ftn95. You are targeting native win32 code.

if using plato this in the drop down window that says DEBUG.

on command line

something like

FTN95 <filename> /CLR

then need to use

DB_LNK (not slink ) for final compilation.

if you want to use native code for the fortran then you need to use p/invoke in the vb.net

Carl

31 Jan 2011 10:58 #7663

Thank you for your fast answer. I tried your proposal with some 'modifications'. As I have .NET Framework V4, I compiled and link with the following coimmands : FTN95 'D:\RESOLUTION.f95' /ALT_KINDS /DEFINT_KIND 4 /CLR /CLR_VER 4

dbk_link4 'D:\RESOLUTION.dll' 'D:\RESOLUTION.dbk'

I get a RESOLUTION.dll file but when I run The application I get The message : 'Entry Point RESOLVE not found in 'D:\RESOLUTION.dll'

I opened it with 'Dependency Walker' and I found no 'Export' It seems to have no entry point inside !

So My previous problem was replaced by a new one !!

PS : In my VB application I have the instruction : Imports System.Runtime.InteropServices

Is it necessary ?

1 Feb 2011 9:14 #7671

The InteropServices is only required if you are interfacing with native code via com somewhere, so you probably don't need it (though you might...)

When making FTN95.net dlls you need to do one of two things set a flag in the linker from memory I think this it is /NS

This should make all the subroutines visible from VB.NET. (i.e. all subroutines are public in object orientated speak)

Which may be what you want. if you want to restrict which interfaces are visible to .net. then add a line to the subroutines that you want to be visible

eg

subroutine test
	ASSEMBLY_INTERFACE (NAME='HelloFromFTN95')

	write(*,*) 'hello from ftn95'

end subroutine 

then use the flags

dbk_link4 'D:\RESOLUTION.dll' 'D:\RESOLUTION.dbk' /NS /INTERFACE_ONLY

then add your dll to your VB project. In my example the following call from VB

RESOLUTION.HelloFromFTN95()

is visible (well I have tested it with C# but it will be the same)

there is no need for the pinvoke calls you were using originally.

Carl

ps the reason that dependancywalker has no entry points is because we are making a .net library. (not a win32 app)

if you really want to do pinvoke i.e. make a win32 dll then I will think some more later.

2 Feb 2011 9:58 #7677

I have deleted the call to the InteropServices and I built my RESOLUTION.dll file as you explained. This file is added as reference in my VB application but i get the following message : 'RESOLVE is not a member of RESOLUTION' I thing I miss something HUGE ! But what ?

2 Feb 2011 12:36 #7687

have you commented out the

Public Class Unmnaged 
Declare Auto Sub RESOLVE Lib 'D:\\RESOLUTION.dll' (<[In](), Out()> ByRef kont As Integer, <[In](), Out()> ByRef mat As Integer) 
End Class  

statement? from the VB?

[/code]

2 Feb 2011 1:26 #7688

Yes I have. I have deleted every thing regarding my previous way of calling my external routine. Currently I have just define my RESOLUTION.dll file as a reference for my VB application and call the routine by : RESOLUTION.RESOLVE(kont, mat(0))

2 Feb 2011 5:01 #7693

are there any methods visible from VB? Do they appear in intellisensi? in vb express or what ever?

you should have three methods two default .net methods (from memory Equals is one) and the name you put in the string

ASSEMBLY_INTERFACE (NAME='HelloFromFTN95') 

in my code this was visible as

RESOLUTION.HelloFromFTN95()

from c# express as I said.

you can send me a zipped up version of your projects and I can try and get them to compile if you like.

carl

Please login to reply.