- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello all
I'm trying to pass an array of structs from C# to a Fortran DLL, alter its contents in the DLL and pass it back to C#. I managed to get it working, but I get an 'unbalanced stack' warning in C# debug mode. It keeps working however. In Fortran debug mode, I get no warning whatsoever.
I used some unconventional calling conventions to get it finally working however. Here is my Fortran header:
SUBROUTINE PassArrayOfStructs(pArray, Length)
cDEC$ ATTRIBUTES DLLEXPORT :: PassArrayOfStructs
cDEC$ ATTRIBUTES DECORATE, ALIAS: "PassArrayOfStructs"
& :: PassArrayOfStructs
USE ISO_C_BINDING, ONLY: C_INT, C_PTR
TYPE(C_PTR), INTENT(IN):: pArray [VALUE] !the external pointer to the external array - be sure to pass it by value!
INTEGER(C_INT), INTENT(IN):: Length [VALUE] !the length of the external array
My C# header:
[DllImport(Constants.DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void PassArrayOfStructs(IntPtr pArray, int length);
And its call:
- I have to pass the pointer by value to get it working, though this is against the standard calling conventions. How is this possible?
- If I pass the 'Length' argument (or the pointer 'pArray' for that matter) as 'INTEGER(C_INT), INTENT(IN), VALUE:: Length' instead of 'INTEGER(C_INT), INTENT(IN):: Length [VALUE]', I get a 'trying to write protected memory' error and the program crashes, though the first call is conform the standard calling conventions. What is happening here?
- What could be the cause of the 'imbalanced stack' warning?
Additional information:
- I use the Intel Fortran Classic (IFORT) compiler.
- I compile in 32-bit mode
Your help would be greatly appreciated!
Best regards, Jan
Link Copied

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