Strange problem with pointers
- From: "roko1076" <r.kuchar@xxxxxxxxxxx>
- Date: 27 Jan 2006 07:49:25 -0800
Hello everybody,
I´m new in this group and also new to Fortran90 - so I´m asking you
for help in a case, that might sound a little funny to you...
In my program I´m dealing with the import/export of data in a dll. I
wrote a fine interface (putting things like DLLIMPORT, .. in it - and
it even work's nicely) to the dll - because of the ALIAS problem with
dll´s written in C... So far so good - but trouble started with the
need of handing over a pointer in a function call to the dll - this
very pointer problem starts getting me crazy...
Let me show you some of the code concerned with the problem:
_________________________________________________________________
PROGRAM epsilon
USE MSFLIB
REAL eps, oneeps
INTEGER*4, DIMENSION(3:256), TARGET::tCalcData
INTEGER*4, POINTER::pData
....
! defining an interface to Calc.dll
INTERFACE
INTEGER*2 FUNCTION CalcReadData(iUserCode, pData, iCount)
!MS$ATTRIBUTES DLLIMPORT,STDCALL,ALIAS:
'_Calc_ReadData@20'::CalcReadData
!MS$ATTRIBUTES VALUE::iSegment
!MS$ATTRIBUTES REFERENCE::pData
!MS$ATTRIBUTES VALUE::iCount
INTEGER*4 iUserCode
INTEGER*4, POINTER:: pData
INTEGER*2 iCount
END FUNCTION
END INTERFACE
....
pData => tCalcData(0)
outData = CalcReadData(14, pData, 10)
WRITE(*,*) ' Wert aus der Berechnung: ', tCalcData(1)
WRITE(*,*) ' Wert aus der Berechnung: ', tCalcData(2)
WRITE(*,*) ' Wert aus der Berechnung: ', tCalcData(3)
WRITE(*,*) ' Wert aus der Berechnung: ', tCalcData(4)
WRITE(*,*) ' Wert aus der Berechnung: ', tCalcData(5)
_________________________________________________________________
The result is now interesting:
***
Calculation.dll geladen!
....
Wert aus der Berechnung: 1
Wert aus der Berechnung: 2
Wert aus der Berechnung: 3
Wert aus der Berechnung: 4
Wert aus der Berechnung: 0
....
Calculation.dll entladen!
_____________________________________________________________________
The values of tCalcData are correct only if the spectrum of tCalcData
is set with the borders of --!!3!!-- to 256 - see code:
INTEGER*4, DIMENSION(3:256), TARGET::tCalcData
if set to (1:256) I get the following results:
Wert aus der Berechnung: 3
Wert aus der Berechnung: 4
Wert aus der Berechnung: 0
Wert aus der Berechnung: 0
Wert aus der Berechnung: 0
The values are for shure set in correct order in the dll 1,2,3,...!
My ultimative question: Why is this behaviour happening? What could be
done to fix this misbehaviour? Is it the pointer
definition/implementation? I very greatful for all help - this problem
is literally burning under my nails...;-))
I hope that I could also add my xperiences to this forum as soon as
I´m a little more expirienced with this complex language!
Thanx in advane to all of you and a nice weekend,
Richard
.
- Follow-Ups:
- Re: Strange problem with pointers
- From: Jugoslav Dujic
- Re: Strange problem with pointers
- Prev by Date: Re: Current status of F95 compilers for Mac/PowerPC
- Next by Date: Re: Bounds of Arrays
- Previous by thread: fortran
- Next by thread: Re: Strange problem with pointers
- Index(es):