Hello!
I tried to use the WinAPI/ODBC function SQLBindCol whose second argument requires a short unsigned integer to be passed. And since I didn't get this to work with FTN95 for quite a while, I investigated somewhat more and finally came away with the opinion that something with passing 1-byte and 2-bytes integers is not properly working when using STDCALL convention. I have set up an example program which calls a .dll containing two subroutines which conform to STDCALL convention. Here is one of these subroutines.
SUBROUTINE PassIntegers( i1Arg, i2Arg, i4Arg )
!DEC$ ATTRIBUTES STDCALL, DLLEXPORT, ALIAS:'PassIntegers' :: PassIntegers
! STDCALL causes all parameters to be passed by value.
INTEGER*1, INTENT(IN) :: i1Arg
INTEGER*2, INTENT(IN) :: i2Arg
INTEGER*4, INTENT(IN) :: i4Arg
PRINT*, ' PassIntegers: Arguments'
PRINT*, ' 1-Byte Integer i1Arg = ', i1Arg
PRINT*, ' 2-Byte Integer i2Arg = ', i2Arg
PRINT*, ' 4-Byte Integer i4Arg = ', i4Arg
END SUBROUTINE PassIntegers
I used Compaq Visual Fortran to create the .DLL (the metacommand !DEC$ ATTRIBUTES STDCALL, ... causes that the routine has to be called using STDCALL convention which means all arguments are to be passed by value). I call this routine in a FTN95 program (v5.50 and v6.10 tested). Here is an excerpt from this:
USE PassIntModule ! defines BYTE, SHORT, LONG
! and also contains
! STDCALL PassIntegers 'PassIntegers' ( val, val, val )
INTEGER (BYTE) :: i1Int ! INTEGER*1
INTEGER (SHORT) :: i2Int ! INTEGER*2
INTEGER (LONG) i4Int ! INTEGER*4
SAVE
i2Int = 3
...
PRINT*, 'CALL PassIntegers( 1_1, 2_2, 3 )'
CALL PassIntegers( 1_1, 2_2, 3 ) ! -> display: 1, 2, 3 (OK)
i1Int = 7
i2Int = 45
i4Int = 19
CALL PassIntegers( i1Int, i2Int, i4Int ) ! -> display: 7, 3 (!!! should be 45), 19 (NOT OK)
For some unknown reason, the short integer argument (no. 2) is not passed correctly. Its value before the call is obviously 45, but the routine says its value is 3!
I am ready to send the complete source codes, PLATO and CVF projects for testing. Please let me know where to send this to.
Regards,
Jörg Kuthe QT software