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. Need help calling fortran dll from VC

Need help calling fortran dll from VC

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialc++testingdebugging
3 Posts 2 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.
  • P Offline
    P Offline
    Pecan204
    wrote on last edited by
    #1

    Hello, Does anyone know how to call a fortran dll in MS VC? I need some help calling one.I compiled the file below. Added the .lib file to the link tab. But I get this error. Linking... debug/DLL_ROUT.lib : fatal error LNK1106: invalid file or disk full: cannot seek to 0x3e218d3c Error executing link.exe. DLL_ROUT_EXE.exe - 1 error(s), 0 warning(s) Fortram file is below. ! Fortran part of a C-Fortran DLL example. This ! routine DLL_ROUT is called from a C executable program. SUBROUTINE DLL_ROUT (INT_ARG, STR_IN, STR_OUT) IMPLICIT NONE ! Specify that DLL_ROUT is exported to a DLL !DEC$ ATTRIBUTES DLLEXPORT :: DLL_ROUT INTEGER INT_ARG CHARACTER*(*) STR_IN, STR_OUT ! This routine converts INT_ARG to a decimal string. ! appends the string value to STR_IN and stores it ! in STR_OUT. A trailing NUL is added to keep C ! happy. ! ! Note that there are implicit length arguments following ! the addresses of each CHARACTER argument. CHARACTER*5 INT_STR WRITE (INT_STR,'(I5.5)')INT_ARG STR_OUT = STR_IN // INT_STR // CHAR(0) RETURN END The main c file is below. /* Main program written in C++ that calls a Fortran DLL */ #include #include /* Declare the Fortran routine. The following items are of note: - The "C" attribute prevents C++ name mangling Remove it if the file type is .c - The dllimport specification is required - Fortran routines use the _stdcall interface by default - Fortran character arguments have a hidden length argument following the address - Routine name must be in uppercase to match Fortran. */ //extern "C" __declspec(dllimport) void _stdcall DLL_ROUT ( extern "C" void _stdcall DLL_ROUT ( int *INT_ARG, char *STR_IN, int STR_IN_LEN, char *STR_OUT, int STR_OUT_LEN); void main (int argc, char *argv[]) { char instring[40]; char outstring[40]; int intarg; strcpy(instring,"Testing..."); intarg = 123; /* Call Fortran routine - pass intarg by reference, pass length of outstring explicitly */ DLL_ROUT(&intarg,instring,strlen(instring),outstring,40); printf("%s\n",outstring); } T

    J 1 Reply Last reply
    0
    • P Pecan204

      Hello, Does anyone know how to call a fortran dll in MS VC? I need some help calling one.I compiled the file below. Added the .lib file to the link tab. But I get this error. Linking... debug/DLL_ROUT.lib : fatal error LNK1106: invalid file or disk full: cannot seek to 0x3e218d3c Error executing link.exe. DLL_ROUT_EXE.exe - 1 error(s), 0 warning(s) Fortram file is below. ! Fortran part of a C-Fortran DLL example. This ! routine DLL_ROUT is called from a C executable program. SUBROUTINE DLL_ROUT (INT_ARG, STR_IN, STR_OUT) IMPLICIT NONE ! Specify that DLL_ROUT is exported to a DLL !DEC$ ATTRIBUTES DLLEXPORT :: DLL_ROUT INTEGER INT_ARG CHARACTER*(*) STR_IN, STR_OUT ! This routine converts INT_ARG to a decimal string. ! appends the string value to STR_IN and stores it ! in STR_OUT. A trailing NUL is added to keep C ! happy. ! ! Note that there are implicit length arguments following ! the addresses of each CHARACTER argument. CHARACTER*5 INT_STR WRITE (INT_STR,'(I5.5)')INT_ARG STR_OUT = STR_IN // INT_STR // CHAR(0) RETURN END The main c file is below. /* Main program written in C++ that calls a Fortran DLL */ #include #include /* Declare the Fortran routine. The following items are of note: - The "C" attribute prevents C++ name mangling Remove it if the file type is .c - The dllimport specification is required - Fortran routines use the _stdcall interface by default - Fortran character arguments have a hidden length argument following the address - Routine name must be in uppercase to match Fortran. */ //extern "C" __declspec(dllimport) void _stdcall DLL_ROUT ( extern "C" void _stdcall DLL_ROUT ( int *INT_ARG, char *STR_IN, int STR_IN_LEN, char *STR_OUT, int STR_OUT_LEN); void main (int argc, char *argv[]) { char instring[40]; char outstring[40]; int intarg; strcpy(instring,"Testing..."); intarg = 123; /* Call Fortran routine - pass intarg by reference, pass length of outstring explicitly */ DLL_ROUT(&intarg,instring,strlen(instring),outstring,40); printf("%s\n",outstring); } T

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      Are you using MSVC++ 5.0? There's a compatibility problem that prevents 5.0 from using import libraries built for 6.0. The latest SP for MSVC++ 5.0 seems to fix this. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      P 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        Are you using MSVC++ 5.0? There's a compatibility problem that prevents 5.0 from using import libraries built for 6.0. The latest SP for MSVC++ 5.0 seems to fix this. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        P Offline
        P Offline
        Pecan204
        wrote on last edited by
        #3

        Yes Joaquin. I am using MS VC 5.0. The library was built using Compaq Visual Fortran 6.0 Not sure what is the SP? Are there any work arounds? Thanks

        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