5

I am trying to ascertain weather I can use rebol for a few programming tasks. I have written a small program which loads an external library and calls a function which returns pointers in some of the arguments. When I run the program it crashes rebol.exe. I am hoping somebody can help me out. The dll function is as follows:

void xxx swe_utc_time_zone(int32 iyear, int32 imonth, int32 iday, 
int32 ihour, int32 imin, double dsec, double dtimezone, 
int32 *iyear_utc, int32 *imonth_utc, int32 *iday_utc, 
int32 *ihour_utc, int32 *imin_utc, double *dsec_utc)

and this is my small test program:

rebol []
astrology-lib: load/library %/c/sweph/bin/swedll32.dll
swe-utc-time-zone: make routine! [
   iyear [integer!]
   imonth [integer!]
   iday [integer!]
   ihour [integer!]
   iminute [integer!]
   dsec [decimal!]
   dtimezone [decimal!]
   iyear-utc [char*]
   imonth-utc [char*]
   iday-utc [char*]
   ihour-utc [char*]
   iminute-utc [char*]
   dsec-utc [char*]
] astrology-lib "_swe_utc_time_zone@60"
swe-utc-time-zone 2015 6 20 0 19 0 -4.5 none none none none none none

The program crashes on the last line where I attempt to call the function. The error message is "REBOL/View system has stopped working"

user1897830
  • 443
  • 1
  • 3
  • 10
  • There are a few more examples of calling out to libraries over here http://www.re-bol.com/rebol.html#section-9.8 – johnk Jun 20 '15 at 01:30
  • @johnk There's nothing there that uses pointer parameters and I feel that is where the error is. – user1897830 Jun 20 '15 at 02:18
  • The stars predict more interesting luck with the FFI implementation ([foreign function interface](https://en.wikipedia.org/wiki/Foreign_function_interface)) for ROUTINE! that is in Atronix's fork of Rebol3. *(Also rebol3 is open source, and has a more likely future.)* I don't know much about it, but [test file here](https://github.com/zsx/r3/blob/atronix/make/tests/test-ffi.r) and you might ask them if you have problems. [Download page](http://atronixengineering.com/downloads.html) See also: [Red](http://stackoverflow.com/questions/30087380/) – HostileFork says dont trust SE Jun 20 '15 at 07:14

1 Answers1

2

You have to provide memory with at least the same size as the pointer you want to get back from your call.

So instead of none you should use words initialized with something along the line of

iyear-utc: make struct! [
    point [integer!]
] none

Maybe these links will give you more help adress, conversions, more conversions

sqlab
  • 6,412
  • 1
  • 14
  • 29