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.
The main c file is below.
Thanks Ken
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.
Code:
! 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.
Code:
/* Main program written in C++ that calls a Fortran DLL */
#include <stdio.h>
#include <string.h>
/* 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);
}
Thanks Ken