Thanks,
I tried almost what you suggested. Since I don't know how to pass pointers as subroutine parameters I created a subroutine that takes the minimum code required to run the OpenPicFile function
BTW In C the declaration for OpenPicFile for the filename parameter is the type LPCSTR
It still seems weird that the C dll is returning a success function and getting the error message, possible like fortran isn't allocating enough memory to open the file, I don't know..just guessing.
And weird that this works if it is not in a subroutine, but just in the main program.
If I do the following
v = OpenPicFile(val(iFilHan),val(loc(TRIM(RefB200)//CHAR(0))))
I get a compile error:
The type of the actual argument, "Cray pointer", does not match "CHARACTER", the type of the dummy argument.
v = OpenPicFile(%val(iFilHan),%val(%loc(TRIM(RefB200)//CHAR(0))))
I get a compile error:
Unexpected syntax: "operand" was expected but found "%".
If I do the following
v = OpenPicFile(%val(iFilHan),%val(%loc(TRIM(RefB200)//CHAR(0))))
So I am using the following
v = OpenPicFile(%val(iFilHan),TRIM(RefB200)//CHAR(0))
The function still returns a success value but also still brings up the same popup error:
Application Error
The instruction at "0xfee27da0" referenced memory at "0xfee27da0". The memory could not be read"".
BUT now the memory address is now always "0X00000000" every time I run the app.
So now my trimmed down subroutine looks like this
subroutine Openthepicfile()
use windows
!---------------------------------------------------------------
interface;
stdcall function OpenPicFile(iFilHan,FileName) & !Q4_OpenPicFile@8
& RESULT (FUNCTION_RESULT)
integer*4 :: iFilHan
character :: FileName*200
integer*4 :: FUNCTION_RESULT
end function
end interface
!---------------------------------------------------------------
integer*4 iii, v, iFilHan
pointer (p,iii)
pointer (q4,OpenPicFile) !_OpenPicFile@8
character RefB200*256, cname*256
!-----------------------------------------------------------------
cname = "geotools.dll"C
p = LoadLibrary(carg(cname))
if (p==0) then
write(*, "(1x,'Error loading geotools = ', i9)") p; goto 1000 ; end if
!-----------------------------------------------------------------
cname = "_OpenPicFile@8"C
q4=GetProcAddress(p, carg(cname))
if (q4==0) then
write(*,"(1x, 'err OpenPicFile', i9)") ;goto 1000; end if
!-----------------------------------------------------------------
RefB200 = "D:\\fortranstuff\\project33\\8945.gvi"C
iFilHan = 0
write (*,*)
v = OpenPicFile(%val(iFilHan),TRIM(RefB200)//CHAR(0))
! v = OpenPicFile(val(iFilHan),val(loc(TRIM(RefB200)//CHAR(0))))
! v = OpenPicFile(%val(iFilHan),%val(%loc(TRIM(RefB200)//CHAR(0))))
write(*,"(1x, 'my sub res ', i9)") v ;
1000 continue
end subroutine
Application Error
The instruction at "0xfee27da0" referenced memory at "0xfee27da0". The memory could not be read"".
(of course the memory address ("0xfee27da0") changes every time I run the application)