- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
We're trying to push string array (String[]) of C# to a Fotran COM server but it doesn't work.
Do you have any samples to do that ? Which is the type to use in the Fortran .HIE file (Type(VARIANT), CHARACTER(256) (why 256?), PTR_KIND) ?
Thanks,
Pellea.
We're trying to push string array (String[]) of C# to a Fotran COM server but it doesn't work.
Do you have any samples to do that ? Which is the type to use in the Fortran .HIE file (Type(VARIANT), CHARACTER(256) (why 256?), PTR_KIND) ?
Thanks,
Pellea.
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Pellea,
No sample I know of though we do have some for Quickwin and calling a DLL in the directory (by default):
C:\Program Files (x86)\Intel\ComposerXE-2011\Samples\en_US\Fortran
In addition I think you might find this article of interest:
http://software.intel.com/en-us/articles/calling-fortran-function-or-subroutine-in-dll-from-c-code/
Hope these help you.
No sample I know of though we do have some for Quickwin and calling a DLL in the directory (by default):
C:\Program Files (x86)\Intel\ComposerXE-2011\Samples\en_US\Fortran
In addition I think you might find this article of interest:
http://software.intel.com/en-us/articles/calling-fortran-function-or-subroutine-in-dll-from-c-code/
Hope these help you.
------
Wendy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I dont know whether it differs from a COM Server, but when using a Fortran DLL for calculation in a C# GUI you have to use a StringBuilder variable instead of an string:
C# Code:
Maybe this helps.
Markus
C# Code:
[bash] [DllImport("kernel.dll")] private extern static void PUT_TEMPDIR(StringBuilder value, int lenOfString); [DllImport("kernel.dll")] private extern static void GET_TEMPDIR(StringBuilder value, int lenOfString); public static void puttempDir(string value) { StringBuilder stringBuilderValue = new StringBuilder(value.Substring(0, System.Math.Min(value.Length, 255))); PUT_TEMPDIR(stringBuilderValue, 255); } public static string gettempDir() { StringBuilder stringBuilderValue = new StringBuilder(255); GET_TEMPDIR(stringBuilderValue, 255); return stringBuilderValue.ToString(); }[/bash]Fortran Code:
[bash]subroutine PUT_TEMPDIR(value) !DEC$ ATTRIBUTES DLLEXPORT::PUT_TEMPDIR use variables !tempDir is declared here implicit none character*(*) value tempDir = value end subroutine PUT_TEMPDIR ! subroutine GET_TEMPDIR(value) !DEC$ ATTRIBUTES DLLEXPORT::GET_TEMPDIR use variables !tempDir is declared here character*(*) value value = tempDir end subroutine GET_TEMPDIR[/bash]
Maybe this helps.
Markus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do not use a DllExport and I have to pass to fortran an array of string and not only one.
I succeeded to pass to fortran only one string.
- 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
In this example they convert the string array to a byte array and pass this last one to the fortran. Is it possible to pass directly a string array?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would think yes, probably, as a SafeArray. You will have to use Marshalling (don't ask!). The same problem (passing string arrays) but for VB .NET to Fortran is dealt with in one of the IVF examples, so I would guess the treatment for C# should be very similar.
You will still finish up with a SafeArray on the Fortran side, which is not so easily dealt with as a standard Fortran array. You will have to use special routines such as SafeArrayGetDim, SafeArrayGetLBound,SafeArrayGetUBound,SafeArrayGetElement, etc. in order to get at the strings. The strings will also be 'wide' strings, using 2-bytes per character and so they also will require conversion before you finish up with a standard Fortran character string which uses 1 byte per character..
You will still finish up with a SafeArray on the Fortran side, which is not so easily dealt with as a standard Fortran array. You will have to use special routines such as SafeArrayGetDim, SafeArrayGetLBound,SafeArrayGetUBound,SafeArrayGetElement, etc. in order to get at the strings. The strings will also be 'wide' strings, using 2-bytes per character and so they also will require conversion before you finish up with a standard Fortran character string which uses 1 byte per character..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I saw that solution too but it was too complicated for what I want to do.
Thanks for answer,I think I'll stay with the array of byte. It's easy to set up and it requires only a little conversion.
Thanks for answer,I think I'll stay with the array of byte. It's easy to set up and it requires only a little conversion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
you see the code above, is the place where I do not understand

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