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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Mixed Language Programming

Mixed Language Programming

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
9 Posts 5 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.
  • B Offline
    B Offline
    BubbaGee
    wrote on last edited by
    #1

    In my line of work I have times when I have to included existing code modules in with my new code. So happens this time I have an existing set of subroutines in a Fortran DLL that I need to access from my C++ Code. I can't get it to work following Microsoft's recommendations. Does anyone out there have any ideas the may work? For those of you who thing I should rewrite the Fortran in C++ it would take entirely too long to do that. I figure there are a few thousand lines of Fortran code. Thanks, George :confused:

    D N 2 Replies Last reply
    0
    • B BubbaGee

      In my line of work I have times when I have to included existing code modules in with my new code. So happens this time I have an existing set of subroutines in a Fortran DLL that I need to access from my C++ Code. I can't get it to work following Microsoft's recommendations. Does anyone out there have any ideas the may work? For those of you who thing I should rewrite the Fortran in C++ it would take entirely too long to do that. I figure there are a few thousand lines of Fortran code. Thanks, George :confused:

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

      BubbaGee wrote: I can't get it to work... Why not? What are the symptoms? Are the functions in the Fortran DLL exported? Are you importing them correctly in the C++ code?


      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

      B 1 Reply Last reply
      0
      • D David Crow

        BubbaGee wrote: I can't get it to work... Why not? What are the symptoms? Are the functions in the Fortran DLL exported? Are you importing them correctly in the C++ code?


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        B Offline
        B Offline
        BubbaGee
        wrote on last edited by
        #3

        The functions in the Fortran have the following: !DEC$ ATTRIBUTES DLLEXPORT :: INITIA and the C++ code has this: extern "C" {void INITIA(int,int,int,int);} There are a few of these since I'm trying to access eight routines in the DLL. Everything is compiling just fine I just get LNK2019 error messages for all the routines I'm trying to use in the C++ code. George

        D J R 3 Replies Last reply
        0
        • B BubbaGee

          The functions in the Fortran have the following: !DEC$ ATTRIBUTES DLLEXPORT :: INITIA and the C++ code has this: extern "C" {void INITIA(int,int,int,int);} There are a few of these since I'm trying to access eight routines in the DLL. Everything is compiling just fine I just get LNK2019 error messages for all the routines I'm trying to use in the C++ code. George

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

          BubbaGee wrote: I just get LNK2019 error messages... This must not be VS6. Correct? Are you sure you have the correct signature for the exported function?


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          B 1 Reply Last reply
          0
          • B BubbaGee

            The functions in the Fortran have the following: !DEC$ ATTRIBUTES DLLEXPORT :: INITIA and the C++ code has this: extern "C" {void INITIA(int,int,int,int);} There are a few of these since I'm trying to access eight routines in the DLL. Everything is compiling just fine I just get LNK2019 error messages for all the routines I'm trying to use in the C++ code. George

            J Offline
            J Offline
            jmkhael
            wrote on last edited by
            #5

            Why not trying a LoadLibrary GetProcAddress sequence. If you are able to get the function pointer, all you need afterward is to define it with the good calling convention. To get the name of the function, try dumpbin or dependency walker Papa while (TRUE) Papa.WillLove ( Bebe ) ;

            1 Reply Last reply
            0
            • D David Crow

              BubbaGee wrote: I just get LNK2019 error messages... This must not be VS6. Correct? Are you sure you have the correct signature for the exported function?


              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

              B Offline
              B Offline
              BubbaGee
              wrote on last edited by
              #6

              Correct. I'm running Visual Studio .NET 2003. I did some more searching on this site and came across an article by Shoalin Panda that may help me solve my problem. I'll let you know if it works. George

              1 Reply Last reply
              0
              • B BubbaGee

                In my line of work I have times when I have to included existing code modules in with my new code. So happens this time I have an existing set of subroutines in a Fortran DLL that I need to access from my C++ Code. I can't get it to work following Microsoft's recommendations. Does anyone out there have any ideas the may work? For those of you who thing I should rewrite the Fortran in C++ it would take entirely too long to do that. I figure there are a few thousand lines of Fortran code. Thanks, George :confused:

                N Offline
                N Offline
                Navin
                wrote on last edited by
                #7

                Note, you don't *have* to use a DLL for this to work. You can simply link all the stuff together. You do have to take into account different parameter passing mechanisms (e.g., C++ strings do not map to Fortran strings!) but that is the same as if you use a DLL. I don't remember all the details, though, so I'm useless. But I think if you have a Fortran compiler that links into Visual Studio (they exist), you can do this relatively painlessly. "Fish and guests stink in three days." - Benjamin Franlkin

                B 1 Reply Last reply
                0
                • N Navin

                  Note, you don't *have* to use a DLL for this to work. You can simply link all the stuff together. You do have to take into account different parameter passing mechanisms (e.g., C++ strings do not map to Fortran strings!) but that is the same as if you use a DLL. I don't remember all the details, though, so I'm useless. But I think if you have a Fortran compiler that links into Visual Studio (they exist), you can do this relatively painlessly. "Fish and guests stink in three days." - Benjamin Franlkin

                  B Offline
                  B Offline
                  BubbaGee
                  wrote on last edited by
                  #8

                  The group I'm working on the code for wants it as a DLL so I don't have much of a choice.

                  1 Reply Last reply
                  0
                  • B BubbaGee

                    The functions in the Fortran have the following: !DEC$ ATTRIBUTES DLLEXPORT :: INITIA and the C++ code has this: extern "C" {void INITIA(int,int,int,int);} There are a few of these since I'm trying to access eight routines in the DLL. Everything is compiling just fine I just get LNK2019 error messages for all the routines I'm trying to use in the C++ code. George

                    R Offline
                    R Offline
                    Rick York
                    wrote on last edited by
                    #9

                    I don't think you are following Micro$oft's recommendations. I just checked MSDN and it says to use __stdcall for FORTRAN functions. For more info search for mixed-language programming in the MSDN docs. __________________________________________ a two cent stamp short of going postal.

                    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