- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
for some time now (thanks to this Forum) but have not been able to pass a simple class into a TYPE
I have found some examples on the forum which compile, but the values dont go through.
On the C# side I use the DLLIMPORT statement and pass the Class and object.
C#
public class StructureTester {
int a = 1;
float b = 2.0f;
}
[DllImport("K3F_Utils.dll", CharSet = CharSet.Auto)]
public static extern void PassClassToFortran(StructureTester st);
Fortran
! type defined at top of program file
TYPE :: SampleStruct
sequence
integer :: a
real :: b
END TYPE SampleStruct
subroutine PassClassToFortran ( InputDataStructure )
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'PassClassToFortran' ::PassClassToFortran
! !DEC$ ATTRIBUTES TYPE (SampleStruct) :: InputDataStructure
TYPE (SampleStruct) :: InputDataStructure
end subroutine
Notes: I've simplified the code to remove the WRITE statements which show the wrong values
Notice I commented out the DEC$ of the TYPE. THis is because it does not compile. I suspect that this
is why the structure values are not coming through, yet I can't find the proper format for DEC$ a structure.
Does anyone have an example of how to fornat this line for the "incoming" TYPE ?
I'm using MSVS 2010 for C# and MSVS 2008 for FORTRAN, both x64. Simple "intrinsic" data type work OK.
IVF is 11.1.038
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
It steps into the Fortran functionOK.
But the Fortran TYPE does not pick up the structvalues as I can see with the debug. Crashes if I try
to use the incoming 'object'.
When I use an intrinsic type, no problem
-------------- C --------
#include "stdafx.h"
struct StructureTester
{ int a ; float b ; } ;
void PassStructureToFortran(struct StructureTester st);
int _tmain(int argc, _TCHAR* argv[])
{
struct StructureTester st;
st.a = 1;
st.b = 2.0f;
PassStructureToFortran ( st );
return 0;
}
----------------------- Fortran ---------
subroutine PassStructureToFortran ( InputDataStructure )
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'PassStructureToFortran' ::PassStructureToFortran
TYPE (SampleStruct) :: InputDataStructure
end subroutine
--------------\
NOTES:
The debugger shows the following but not sure how to interpret, maybe it means the first value '1'
is considered the whole struct.
- INPUTDATASTRUCTURE 0x4000000000000001 {A=??? B=??? } SAMPLESTRUCT *
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Since I really need to do this from C#, I'll have to go C#->C->Fortran
------------------------------
#include "stdafx.h"
struct StructureTester
{
int a ;
float b ;
} ;
void PassStructureToFortran(struct StructureTester *st, int v);
int _tmain(int argc, _TCHAR* argv[])
{
struct StructureTester st;
int v ;
st.a = 1;
st.b = 2.0f;
v = 3;
PassStructureToFortran ( &st, v );
return 0;
}
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page