Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C#, Fortran and dll's

C#, Fortran and dll's

Scheduled Pinned Locked Moved C#
helpcsharptutorial
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kash
    wrote on last edited by
    #1

    Hi, I am trying to call a Fortran dll in my simple C# example. My Fortran bit looks like this: 'code' subroutine sumit(x,i,r) real , intent(in) :: x(i) integer , intent(in) :: i real , intent(out) :: r ! !DEC$ATTRIBUTES STDCALL, DECORATE dllexport :: sumit !DEC$ATTRIBUTES STDCALL, DECORATE, ALIAS:'sumit' :: sumit ! integer :: j r=0.0 do j=1,i r=r+x(j) end do end subroutine sumit 'code' and my C# bit looks like: 'code' using System; using System.Text; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class MyClass { [DllImport("Dll1.dll", EntryPoint="sumit")] public static extern double sumit(double x,int i,double r); public static void Main() { sumit(10.0,10,0.0); } } } 'code' But I get an exception error System.NullReferenceException. I also tried to add reference but I get an error saying that the extension must be of type .dll but it is already. Can anyone help. Kash

    L 1 Reply Last reply
    0
    • K Kash

      Hi, I am trying to call a Fortran dll in my simple C# example. My Fortran bit looks like this: 'code' subroutine sumit(x,i,r) real , intent(in) :: x(i) integer , intent(in) :: i real , intent(out) :: r ! !DEC$ATTRIBUTES STDCALL, DECORATE dllexport :: sumit !DEC$ATTRIBUTES STDCALL, DECORATE, ALIAS:'sumit' :: sumit ! integer :: j r=0.0 do j=1,i r=r+x(j) end do end subroutine sumit 'code' and my C# bit looks like: 'code' using System; using System.Text; using System.Runtime.InteropServices; namespace ConsoleApplication1 { class MyClass { [DllImport("Dll1.dll", EntryPoint="sumit")] public static extern double sumit(double x,int i,double r); public static void Main() { sumit(10.0,10,0.0); } } } 'code' But I get an exception error System.NullReferenceException. I also tried to add reference but I get an error saying that the extension must be of type .dll but it is already. Can anyone help. Kash

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Kash wrote: !DEC$ATTRIBUTES STDCALL, Thats should be CDECL or what ever they use in Fortran. xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups