Using unmanaged C#-DLL in C++/FORTRAN -


i working on master thesis , need help! btw studying mechanical enginneering... programming skills limited.

here problem:

i have dll, created in c# ( cannot post it, because part of unpublished research). gives me arrays ( 1d-array [], 2darray[,] ).

for simulation abaqus need import c#-dll in c++ and/or fortran.

i found solution robert giesecke create unmanaged dll. think easiest solution me. (of course if has solution me, wrapper or something, please post it)

here 1d array example unmanaged c#-dll created r.giesecke template:

using system; using system.text; using rgiesecke.dllexport; using system.runtime.interopservices;  namespace testme {     class test     {          [dllexport("get1darray", callingconvention = callingconvention.stdcall)]         public static double get1darray([marshalas(unmanagedtype.lparray, sizeparamindex = 1)]  double[] stress, int i)         {             return stress[i];         }      } } 

and here 2d array code:

using system; using system.text; using rgiesecke.dllexport; using system.runtime.interopservices;  namespace testme {     class test     {          public static int idx(int a, int b) { int cols = 2; return * cols + b; }          [dllexport("set2darray", callingconvention = callingconvention.stdcall)]         public static int set2darray([in, out, marshalas(unmanagedtype.lparray, sizeparamindex = 1)] int[] strain, int len)         {             strain[idx(0, 0)] = 0;             strain[idx(0, 1)] = 1;             strain[idx(1, 0)] = 2;             strain[idx(1, 1)] = 3;             strain[idx(2, 0)] = 4;             strain[idx(2, 1)] = 5;              return 0;         }      } } 

the build have succeeded @ both. how can import dlls in c++ and/or fortran?

thx in advance!

when compile c#-dll tool r. giesecke, should *.lib file it. need reference lib in fortran linker settings additional library dependency. contains code required load dll , make functions in dll available.

in fortran code need declare imported methods following statements:

!dec$ attributes dllimport, alias:'_methodename::methodname 

btw: com visibility not needed if using rgiesecke. access c# native , not via com (also making considerably faster).


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -