- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have created a c# class library with which I can create/write etc to Access databases. Now I want to create a Fortran library that "translates" this dll, so it can be used by my collegues using Fortran only. Does anybody have a workaround? Should I do more in C# than simply creating a Class that is called Mdb which contains methods to e.g. open an access database? (The other way around I had to use dllimport statements to import a FortranDll in C#).
Cheers Arjen
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Steve,
Thank you for your answer, this helped a lot.I managed to get it working, after quite some trial and errors. I first had to add some interfaces to my c# code, andhave the"Generate code that uses Automation Interfaces" box checked. Otherwise functions are created witharguments of integer type only, whereas I also use floats/doubles/strings.
There seems to be one problem left. When I try to call a subroutine with arrays as arguments, the corresponding c# method is not called at all. If I change my c#-method to no arrays it works fine. I don't understand why it fails. The generated Fortran-code seems fine to me. Below follows an example which writes real(4) values to a column in a access database table. Do you see any problems in the code?
Thanks for helping me in advance!
Cheers Arjen
C#-interface:
void
WriteDataSP(string tableName, string columnName, float[] varValues);generated Fortran-code:
SUBROUTINE iMdb_WriteDataSP($OBJECT, tableName, columnName, varValues, $STATUS)IMPLICIT NONEINTEGER(INT_PTR_KIND()), INTENT(IN) :: $OBJECT ! Object Pointer!DEC$ ATTRIBUTES VALUE :: $OBJECTCHARACTER(LEN=*), INTENT(IN) :: tableName ! BSTRCHARACTER(LEN=*), INTENT(IN) :: columnName ! BSTRREAL(4), DIMENSI ON(:), INTENT(IN) :: varValues ! (SafeArray)!DEC$ ATTRIBUTES REFERENCE :: varValuesINTEGER(4), INTENT(OUT), OPTIONAL :: $STATUS ! Method status!DEC$ ATTRIBUTES REFERENCE :: $STATUSINTEGER(4) $$STATUSINTEGER(INT_PTR_KIND()) invokeargsinvokeargs
= AUTOALLOCATEINVOKEARGS()CALL AUTOADDARG(invokeargs, '$ARG1', tableName, AUTO_ARG_IN, VT_BSTR)CALL AUTOADDARG(invokeargs, '$ARG2', columnName, AUTO_ARG_IN, VT_BSTR)CALL AUTOADDARG(invokeargs, '$ARG3', varValues)$$STATUS
= AUTOINVOKE($OBJECT, 1610743813, invokeargs)IF (PRESENT($STATUS)) $STATUS = $$STATUSCALLAUTODEALLOCATEINVOKEARGS (invokeargs)END SUBROUTINE iMdb_WriteDataSP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I checked the $STATUS and it is a very negative number, indicating it didn't work. A workaround would be not to use arrays, but it should be possible somehow. Maybe my c#-class is not properly defined? It works fine in c# though...Do you oranybodyelse have an example of a dll in which arrays work using code from the Module Wizard?
Cheers Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
C# and Fortran arrays differ in that they are 0- and 1- basedand are the transposes of each other.
It is possible to export from a C# DLL so that its classes can be accessed by unmanaged clients (Fortran, VC++,...) via the Windows API's LoadLibrary and GetProcessAddress and the use of pointers. Basically you disassemble the managed DLL without exportsvia ILDASM, edit the IL code to apply VT fixups, specify names of exports and their order in the VT, and reassemble the edited IL via ILASM to produce a new copy of the DLLwith exports. This is trivial to do but tedious. I've attached a zip with the before and after DLL's. Open them up with the Depends utility to observe their difference. MathFunctions.Dll is the managed while MF.Dll is also managed but has unmanaged exports.
Gerry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Cheers Arjen

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page