Hello,
I try to pass an 1D-array from a C#-DLL to Fortran. For that I am using R. Giesecke DllExport. That makes my managed DLL to a unmanaged DLL with a .lib file. To pass a normal parameter works well. Please see here:
https://software.intel.com/en-us/forums/topic/517631
The 1D-Array has always the size of 6! The size of the array will never change only the assigned value.
Here my Code in C#:
using System;
using System.Text;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
namespace Testme
{
class Test
{
[DllExport("Get1DArray", CallingConvention = CallingConvention.Cdecl)]
public static int Get1DArray([MarshalAs(UnmanagedType.LPArray, SizeConst = 5)] int[] Stress)
{
Stress [0] = 0;
Stress [1] = 1;
Stress [2] = 2;
Stress [3] = 3;
Stress [4] = 4;
Stress [5] = 5;
return Stress[5];
}
}
}
And my Fortran Code:
MODULE MYEXTERNALS
USE iso_c_binding
INTERFACE
FUNCTION Get1DArray(Stress) RESULT(ret) bind(c, name="Get1DArray")
!DEC$ATTRIBUTES DLLIMPORT :: Get1DArray
USE, intrinsic :: iso_c_binding
INTEGER(c_int), intent(in) :: Stress(6)
INTEGER(c_int) :: ret
END FUNCTION
END INTERFACE
END MODULE MYEXTERNALS
PROGRAM CallArray
USE MYEXTERNALS
IMPLICIT NONE
INTEGER(c_int) :: Stress(6)
PRINT*, '1DArray =', Get1DArray(Stress)
PAUSE
END PROGRAM CallArray
After debugging I get following output:
'CallArrayDll.exe': Loaded '\\cifs\cluster\Home\ca416444\WinDocuments\Masterarbeit\C# Dllexport\to Fortran\1DArray2\CallArrayDll\Debug\CallArrayDll.exe', Symbols loaded.
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded '\\cifs\cluster\Home\ca416444\WinDocuments\Masterarbeit\C# Dllexport\to Fortran\1DArray2\CallArrayDll\Debug\ArrayDll.dll', No native symbols in symbol file.
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\mscoree.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\imagehlp.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\msvcr110_clr0400.dll', Cannot find or open the PDB file
First-chance exception at 0x75c8c42d in CallArrayDll.exe: 0x04242420: 0x4242420.
'CallArrayDll.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\ce5f61c5754789df97be8dc991c47d07\mscorlib.ni.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded '\ArrayDll.dll', No symbols loaded.
'CallArrayDll.exe': Unloaded '\ArrayDll.dll'
'CallArrayDll.exe': Loaded '\ArrayDll.dll', No symbols loaded.
'CallArrayDll.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clrjit.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\diasymreader.dll', Cannot find or open the PDB file
First-chance exception at 0x75c8c42d in CallArrayDll.exe: Microsoft C++ exception: EEException at memory location 0x0020f4fc..
First-chance exception at 0x75c8c42d in CallArrayDll.exe: 0xE0434352: 0xe0434352.
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\dbghelp.dll', Cannot find or open the PDB file
'CallArrayDll.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll', Cannot find or open the PDB file
The thread 'Win32 Thread' (0x5d4c) has exited with code 3 (0x3).
The thread 'Win32 Thread' (0x3944) has exited with code 3 (0x3).
The thread 'Win32 Thread' (0x59fc) has exited with code 3 (0x3).
The program '[24492] CallArrayDll.exe: Native' has exited with code 3 (0x3).
To Create a C Dll with this Code:
int Get1DArray(int Stress[]){
Stress[0]=0; Stress[1]=1; Stress[2]=2;
Stress[3]=3; Stress[4]=4; Stress[5]=5;
return Stress[5];
}
and call it with the Fortran Code above works fine!! So i guess the problem is on the C# side.
Please help me to fix the problem.