Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLL function not passing arguments

Status
Not open for further replies.

CalvinL

Programmer
May 24, 2011
2
CA
Hi Tek-tips,
I am having a very wierd problem that I can't seem to figure out!
I need to call a fortran 77 function from IDL. To do this, I must export these functions in a DLL and also add a wrapper function (IDL uses argc,argv convention).

So first I am testing my dll in fortran (Visual Studio 2008). I have my main program which imports the dll and calls f2c_w (the wrapper function). This function then calls the actual working function that converts fahrenheit to celsius, however it does not return the value to the wrapper function, and hence to my main program!

At first my functions were not even passing arguments into the function, but I found that by making all scalar arguments an array of dimension(1), it works. --- why is this!?

Now my problem is that the function f2c is not passing arguments back.

Does anyone know what is going on?

---------------------------------------------
! Main program
program testf2c
!DEC$ ATTRIBUTES DLLIMPORT :: f2c_w
implicit none

integer :: a , f2c_w
integer,parameter :: argc=2
real(4), dimension(argc) :: argv


argv(1) = 98.6
argv(2) = 0.0

a = f2c_w(argc,argv)

print*, argv(1), argv(2)

end program testf2c
---------------------------------------------
! DLL PROGRAM
integer function f2c_w(argc, argv)
implicit none
!DEC$ ATTRIBUTES DLLEXPORT::f2c_w
integer :: argc
real(4), dimension(argc) :: argv


call f2c((argv(1)), (argv(2)))
f2c_w = 5
return
end

!This subroutine is called by f2c_w and has no IDL-specific code.

subroutine f2c(f, c)
implicit none
real(4), dimension(1) :: f, c
c = (f - 32.0) * (5.0/9.0)

return
end


Thanks for your help!
 
I found that by removing the extra brackets around
call f2c((argv(1)), (argv(2)))

that it made the function return values. WEIRD!

But I would still like to know why scalar values are required to be declared as dimension(1).

If I do not declare them as dimension(1), they are not passed.
 
Answer to the 1st (implicit) question:

There is a difference between X and (X) in Fortran call argument list. The first case: associate X with a dummy argument. You can redefine X value. The 2nd case: (X) is an expression, associate a temporary var (initialized by this expression value) with a dummy argument. It's impossible to redefine X via this association.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top