从Rebol调用dll函数返回指针

5

我想确定我是否可以在几个编程任务中使用Rebol。我编写了一个小程序,它加载外部库并调用一个函数,该函数返回一些参数的指针。当我运行程序时,它会崩溃rebol.exe。我希望有人能帮助我解决这个问题。 dll函数如下:

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)

这是我的小测试程序:

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

程序在调用函数的最后一行崩溃。错误信息是“REBOL/View系统已停止工作”。

这里还有一些调用库的例子:http://www.re-bol.com/rebol.html#section-9.8 - johnk
@johnk 那里没有使用指针参数,我认为错误就在那里。 - user1897830
星星預測ROUTINE的FFI實現(外部函數接口)在Atronix的Rebol3分支中會帶來更有趣的運氣!(還有,Rebol3是開源的,且未來更有可能。)我對它不是很了解,但你可以通過test file here來瞭解,如果有問題,也可以詢問他們。Download page 另請參閱:Red - HostileFork says dont trust SE
1个回答

2

您需要提供与您从调用中获取的指针大小至少相同的内存。

因此,您应该使用初始化为类似以下内容的单词,而不是none

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

也许这些链接会给您更多帮助:地址转换更多转换

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接