I have a subroutine that was written in fortran that I need to call from VB.NET where all of my other functions are written. I did not write the fortran, and hardly know fortran. I am getting the below exception on my dll function call and don't know how to fix it. I wonder if it is due to incongruent variable lengths?
I have the source for my fortran and compiled it using the g95 compiler. I have tried compiling it with a flag on which is supposed to force all of the reals to 32 bits (-r4). It weirds me out that you don't seem to be required to initialize variables before use in fortran. I thought it was supposed to be a ridged language.
Anyway, below is the exception I am getting:
System.AccessViolationException was unhandled Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Source=PTPWrapper
StackTrace: at PTPWrapper.Module1.pointtopoint(Single& IELEVAT, Single& IDIST, Single& FREQ, Single& HTAMSL, Single& DLOSS, Single& CLUTTER) at PTPWrapper.Module1.Main() in C:\Documents and Settings\SGoldman\my documents\visual studio 2010\Projects\PTPWrapper\PTPWrapper\Module1.vb:line 18 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:
here is my VB function declaration and function call:
Declare Sub pointtopoint Lib "diff5z11.dll" (ByRef IELEVAT As Single, ByRef IDIST As Single, ByRef FREQ As Single, ByRef HTAMSL As Single, ByRef DLOSS As Single, ByRef CLUTTER As Single)
pointtopoint(elevation(0), distance, freq, height, dlo, clut)
all of the variables are defined as 32-bit singles here in VB.
and here are the first few lines of the fortran code:
subroutine pointtopoint(IELEVAT, IDIST, FREQ, HTAMSL, DLOSS, CLUTTER)
real ielevat(*)
dimension oblim(2)
dd = 0.1
EK = 1.333 ! Earth curvature (4/3 earth)
HR = 9.1 ! Rcvr Ant ht (m), for 30 feet
HRAMSL = IELEVAT(IDIST) + HR
DIST = float(idist)*dd
FRESMIN = HR + 1.0
DLOSS = 0.0
TDLOSS = 0.0
RDLOSS = 0.0
ADJ = 0.0
any ideas how i can get the call to work and get my data back? Thanks!