PDA

View Full Version : Passing Strings from .Net


kturok
10-10-2003, 07:21 PM
I have a fortran dll compiled with the -ml lf95 switch. I have declared my exported subroutines in VB.Net as described in the documentation as such:

<DllImport("dll-name.dll", CallingConvention:=CallingConvention.Cdecl)>
Shared Function proc-name_ (arg-list) as return-type

All except one of my calls work, and I think it has to do with the way I am passing strings. The samples provided in the Win32\Examples\Mix_Lang directory do not include Strings, so I was wondering if someone could provide the correct method. Thanks.

tzeis
10-20-2003, 08:05 PM
Hmmm.
There is a hard way and an easy way to do this. The easy way is to get Fortran for .NET and use it to create an object oriented wrapper for your Win32 DLL. The wrapper could get the String variable from VB.NET and convert it to the Fortran CHARACTER type using the utility functions supplied with .NET. Of course, the easy way costs more.
The harder (but cheaper) way to do it would be to act like the Fortran characters are a byte array in VB.NET. This is unexplored, and it is unknown what difficulties might arise trying to do this. Also consider trying Marshalling on the VB.NET side to tell the Framework how to convert the character data.