- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to link lots of existing code into a DLL. I am getting the above message repeatedly and have isolated the issue into a simple set of source files.
E:ALLANALLANF~1>type fred.for
!DEC$ATTRIBUTES STDCALL:: fred
!DEC$ATTRIBUTES DLLEXPORT:: fred
!DEC$ATTRIBUTES ALIAS: 'fred'::fred
!DEC$ATTRIBUTES REFERENCE:: i
!DEC$ATTRIBUTES REFERENCE:: j
!DEC$ATTRIBUTES REFERENCE:: c
integer*4 function fred (i,j,c)
!DEC$ATTRIBUTES STDCALL:: fred
!DEC$ATTRIBUTES DLLEXPORT:: fred
!DEC$ATTRIBUTES ALIAS: 'fred'::fred
!DEC$ATTRIBUTES REFERENCE:: i
!DEC$ATTRIBUTES REFERENCE:: j
!DEC$ATTRIBUTES REFERENCE:: c
integer*4 function fred (i,j,c)
integer*4 i,j , status
character*100 c,cc
character*100 c,cc
fred = i * 100
j = i * 400
if (j .gt. 1000) then
status = fredc(cc)
c = cc
else
c = 'less than 1000'
endif
return
j = i * 400
if (j .gt. 1000) then
status = fredc(cc)
c = cc
else
c = 'less than 1000'
endif
return
end
and
E:ALLANALLANF~1>type fredc.for
!DEC$ATTRIBUTES STDCALL:: fredc
!DEC$ATTRIBUTES DLLEXPORT:: fredc
!DEC$ATTRIBUTES ALIAS: 'fredc'::fredc
!DEC$ATTRIBUTES REFERENCE:: c
!DEC$ATTRIBUTES DLLEXPORT:: fredc
!DEC$ATTRIBUTES ALIAS: 'fredc'::fredc
!DEC$ATTRIBUTES REFERENCE:: c
integer*4 function fredc (c)
character*100 c
character*100 c
c = 'gt 1000 '
fredc = 0
return
return
end
but when I link these into a dll I get the warning
fred.for(15) : Warning: Routine fredc called with different calling conventions
status = fredc(cc)
------------------------^
status = fredc(cc)
------------------------^
The routines work but I would really like to understand what is causing the warning - the code works with no warnings under VMS
I tried calling the fredc routine byref same result
E:ALLANALLANF~1>fred | more >t.txt
fred.for(15) : Warning: Routine fredc called with different calling conventions
status = byref(fredc(cc))
------------------------------^
Thanks Allan B
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't see how fred is supposed to know the prototype of fredc, i.e. how to produce a correct call? Namely, fredc expects one argument, address of stringc, but fred, in the absence of explicit interface, will supply the default two -- address of string cc and (hidden but present) length of string c.
Besides, I don't see how you don't get a LNK2001 if you don't have interface for fredc in fred.for -- I'd expect "Unresolved external symbol _FREDC@8"? Or did you perhaps alter the compiler settings (namely, calling convention: "C, by reference")?
You should be able to overcome the problem by supplying an INTERFACE block for fredc within body of function fred:
interface
integer function fredc(c)
!DEC$ATTRIBUTES STDCALL, ALIAS: 'fredc'::fredc
!DEC$ATTRIBUTES REFERENCE:: c
!DEC$ATTRIBUTES REFERENCE:: c
character(100):: c
end function
end interface
I sometimes use the following trick to check theconsistency of a call to an EXTERNAL routine (calling convention& number of arguments):
! EXCheckStack.f90 - returns the address of a local variable
! in order to verify that user-defined callback function did
! not screw the stack by argument number mismatch or calling
! convention mismatch. Must not be optimized.
RECURSIVE INTEGER FUNCTION EXCheckStack()
! in order to verify that user-defined callback function did
! not screw the stack by argument number mismatch or calling
! convention mismatch. Must not be optimized.
RECURSIVE INTEGER FUNCTION EXCheckStack()
INTEGER, AUTOMATIC:: i
EXCheckStack = LOC(i)
END FUNCTION EXCheckStack
...
iESP = EXCheckStack()
call ASuspiciousExternal(arg1, arg2, etc)
IF (EXCheckStack() .NE. iESP) THEN
!Error handling
IF (EXCheckStack() .NE. iESP) THEN
!Error handling
END IF
If values of EXCheckStack() before and after the call to another routine are not the same, you have a potentially serious problem...
Jugoslav

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page