Essentially, you have to reproduce in C# what is given below as the code for a C++ DLL (given the name mycdll for example) containing one function MyCDllRoutine. Note that given the calling convention used, this will export a symbol
_MyCDllRoutine@8 in the generated symbol table mycdll.lib (note the preservation of case, the added leading underscore and the decoration @8). The Fortran code to produce a Console application (so that you can write to the screen) that calls the DLL is given below the C++ code. In order for the Fortran program to work, the file mycdll.lib must be added to the Fortran project and the mycdll.dll code added to the folder containing the Fortran executable.
// mycdll.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
// myDLL.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "iostream.h"
#include "stdlib.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
extern "C" __declspec(dllexport) void __stdcall MyCDllRoutine(int a, int b) ;
// MAIN ENTRY FUNCTION
void __stdcall MyCDllRoutine (int a, int b)
{
char achar[10], bchar[10], str[80];
itoa(a,achar,10);
itoa(b,bchar,10);
strcpy(str," a = ");
strcat(str,achar);
strcat(str,", b = ");
strcat(str,bchar);
cout <<" Entered MyCDllRoutine in the C++ DLL"<
Fortran Code:
!****************************************************************************
!
! PROGRAM: testmycdll
!
! PURPOSE: Entry point for 'Hello World' sample console application to access
! a routine held in a Win32 Dynamic link library compiled from C++ code
!
!****************************************************************************
program testmycdll
implicit none
!
INTEGER I,J
INTERFACE
SUBROUTINE MYCDLLROUTINE (I,J)
!DEC$ ATTRIBUTES DLLIMPORT :: MYCDLLROUTINE
!DEC$ ATTRIBUTES STDCALL :: MYCDLLROUTINE
!DEC$ ATTRIBUTES ALIAS:'_MyCDllRoutine@8' :: MYCDLLROUTINE
INTEGER I,J
END SUBROUTINE MYCDLLROUTINE
END INTERFACE
print *, 'Hello World'
I=10
J=25
CALL MYCDLLROUTINE(I,J)
end program testmycdll