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 / C++ / MFC
  4. Mixed language dll

Mixed language dll

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++help
3 Posts 3 Posters 0 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

    I am trying to call a Fortran dll in my c++ code. The fortran bit is as follows: subroutine swap(x,y,z) real , intent(inout) :: x real , intent(inout) :: y real , intent(out) :: z real :: t ! !DEC$ATTRIBUTES dllexport :: swap !DEC$ATTRIBUTES DEFAULT, DECORATE, ALIAS: 'swap' :: swap ! t=x x=y y=t z=1.23 end subroutine swap <\code> The C++ calling code is: `#include using namespace std; extern "C" __declspec(dllimport)void swap(double &x, double &y,double &z); int main() { double x,y,z; x = 10; y = 999; swap(x,y,z); cout< There are some problems however. x and y are not swapped but they do display their original values on the console. And z has not been assigned a value. I think it's a problem with the C++ bit but I could be wrong. The good thing is that it compiles and executes. I will eventually try and do this in C# but one step at a time ;) Kash`

    D 1 Reply Last reply
    0
    • K Kash

      I am trying to call a Fortran dll in my c++ code. The fortran bit is as follows: subroutine swap(x,y,z) real , intent(inout) :: x real , intent(inout) :: y real , intent(out) :: z real :: t ! !DEC$ATTRIBUTES dllexport :: swap !DEC$ATTRIBUTES DEFAULT, DECORATE, ALIAS: 'swap' :: swap ! t=x x=y y=t z=1.23 end subroutine swap <\code> The C++ calling code is: `#include using namespace std; extern "C" __declspec(dllimport)void swap(double &x, double &y,double &z); int main() { double x,y,z; x = 10; y = 999; swap(x,y,z); cout< There are some problems however. x and y are not swapped but they do display their original values on the console. And z has not been assigned a value. I think it's a problem with the C++ bit but I could be wrong. The good thing is that it compiles and executes. I will eventually try and do this in C# but one step at a time ;) Kash`

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Kash wrote: extern "C" __declspec(dllimport)void swap(double &x, double &y,double &z); Does Fortran support references? What happens if you change this to:

      extern "C" __declspec(dllimport)void swap(double *x, double *y,double *z);
      ...
      swap(&x, &y, &z);


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      T 1 Reply Last reply
      0
      • D David Crow

        Kash wrote: extern "C" __declspec(dllimport)void swap(double &x, double &y,double &z); Does Fortran support references? What happens if you change this to:

        extern "C" __declspec(dllimport)void swap(double *x, double *y,double *z);
        ...
        swap(&x, &y, &z);


        "One must learn from the bite of the fire to leave it alone." - Native American Proverb

        T Offline
        T Offline
        Tim Smith
        wrote on last edited by
        #3

        If that version of Fortran supports pointers, then it probably can support references indirectly. After all, under the hood, a reference is just a pointer without the dereferencing symantics. Tim Smith I'm going to patent thought. I have yet to see any prior art.

        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