Silverfrost Forums

Welcome to our forums

calling 32bit Dll from C# - string variables

23 Jul 2024 7:47 #31444

HI Everyone

Does anybody have any experience of calling a 32 fortran dll from C#. I have no knowledge of C# and the client has no knowledge of Fortran

I can successful transfer integer and Double precision data to/from the DLL but character strings become corrupt

I can successful transfer data to the DLL but the data in the common block becomes corrupt when i try to read the data back.

F_stdcall Subroutine mov_data_str (imode, cbuff80)

integer imode character *80 cbuff80

chactacter*80 string1 common/ saved_data\ string1

if(imode.eq.0) then string1 = cbuff80 else cbuff80 = string1 endif

end

im assuming that it has something to do with the way the C# call is defined (pass by reference using the 'out' qualifier) and/or how the actual character variable is define in the C#

All responses appreciated

steve

8 Aug 2024 2:31 #31463

Maybe the problem is that Fortran character type has not an exact equivalent in C# (.NET strings are different).

If you can recompile your Fortran dll with .NET, you can then consider the use of .NET string type in FTN95, as explained here.

12 Aug 2024 11:36 #31466

Thanks for the feedback

after much experimentation we found that we needed add an extra argument to the C# call to specify the length of the character buffer

STR_LEN = 80

C# MOV_DATA_STR32(ref IMODE, ref CBUFF, ref STR_LEN)

steve

Please login to reply.