programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re Passing double floats to an external dll

From: Roland Smith <r.a.smith_at_imperial.ac.uk>
Date: Thu, 26 Oct 2006 16:56:48 +0100

Dear All

I am having trouble passing a double float value to an external dll
using SwiftForth 3.0.4. I am trying to use FreeImage.dll
<http://freeimage.sourceforge.net/sourcecode.html> to handle some image
load, save and processing routines. This "should" work as there is a
Win32For application 4FreeImage.f <http://home.planet.nl/~josv/> which
makes use of the same dll. There is also an old reference to an earlier
version of this dll in the SwiftForth message archive but the thread
seems to have expired taking all the details with it.

Calls to functions from imported from FreeImage.dll requiring one or
more integer arguments, eg

1 IMPORT: _FreeImage_GetWidth_at_4 ( addr -- n) work fine.

Calls to a function requiring a float argument. eg

2 Import: _FreeImage_RotateClassic_at_12 ( addr Dfloat -- bool )

fail with an access violation.

I have been trying to pass the float argument in a number of ways based
on what I can find in the SwiftForth message archive eg trying to use
the same method as an OpenGL demo discussed there by using things like :-

   CODE 1dfparms ( f: x -- ) ( s: -- xl xh )
>f \ make sure data on hardware stack
     8 # EBP SUB \ make room for double
     0 [EBP] QWORD FSTP \ convert
     4 [EBP] EBX XCHG \ swap xh and old tos
     RET END-CODE

to get a float onto the hardware fpu to pass to the dll. Any suggestions
gratefully received.

Cheers, Roland Smith

{ ------ Testing Calls to FreeImage.dll ---------- }

Requires fpmath
Library FreeImage.dll { Call the FreeImage dll }

variable image-address { Stores an image start address }

0 IMPORT: _FreeImage_GetVersion_at_0 ( -- ZString ) { Returns Zstring
address containing version info }

6 IMPORT: _FreeImage_Allocate_at_24 ( x y depth 0 0 0 -- addr ) { Make bmp
in memory and return start address }

2 Import: _FreeImage_RotateClassic_at_12 ( addr Dfloat -- bool )

   CODE 1dfparms ( f: x -- ) ( s: -- xl xh )
>f \ make sure data on hardware stack
     8 # EBP SUB \ make room for double
     0 [EBP] QWORD FSTP \ convert
     4 [EBP] EBX XCHG \ swap xh and old tos
     RET END-CODE

: FreeView-Version ( -- ) { Print version of FreeView.dll to console }
   cr cr s" FreeView Dll Version = " type
   _FreeImage_GetVersion_at_0
   Zcount Type cr cr
   ;

: make-new-bmp ( -- addr ) { Make bmp in memory - return address of
structure }
   200 100 24
   0 0 0
   _FreeImage_Allocate_at_24
   image-address !
   ;

: rot-90 image-address @ 90.0e0 1dfparms _FreeImage_RotateClassic_at_12 ;

: Testing
   cr
   FreeView-Version
   s" Make an image " type
   make-new-bmp
   dup image-address !
   ;

   \ EOF

   \ Testing
   \ FreeView Dll Version = 3.9.1
   \ Make an image ok

   \ rot-90 ACCESS_VIOLATION

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and
bug reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Thu Oct 26 2006 - 09:21:31 PDT

This archive was generated by hypermail 2.2.0 : Wed Nov 19 2008 - 03:04:28 PST