如何在R中的32位C DLL中调用函数 [英] how to call a function within 32-bit C DLL within R
问题描述
经过一些试验和反馈后,我得到了以下R代码,我希望这些代码可以为我提供32位C DLL(swedll32.dll)中的功能。
After some trials and feedback received, I have the following R code, which I had hoped would provide me the use of functions from a 32-bit C DLL (swedll32.dll).
swe_day_of_week函数如下(swedll.h):
The swe_day_of_week function is as follows (swedll.h):
/* monday = 0, ... sunday = 6 */
DllImport int CALL_CONV_IMP swe_day_of_week(double jd);
所以我的R代码(32位R)是:
So my R code (32-bit R) is:
> dyn.load("C:/Users/VRHome/Documents/R/DLLs/swedll32.dll")
> Week <- as.integer(0) #so a 32-bit signed variable (aka Long in VBA)
> JD <- as.double(1234567.5)
> Week <- .C("_swe_day_of_week@8",JD)
我认为上述R数据类型正确,我检查了_swe函数确实存在(getNativeSymbolInfo('_ swe_day_of_week @ 8'))。
但是R崩溃了(我认为在此.C调用中)。我必须做一些明显错误的事情。
I think the above R data types are correct and I checked that the _swe function indeed exists (getNativeSymbolInfo('_swe_day_of_week@8')). But R crashes (I think within this .C call). I must do something obviously wrong.
对我有什么提示吗?谢谢。
Any hints for me? Thanks.
祝一切顺利,
Victor
推荐答案
SODD 变得更好了我已经构建了一个非常粗软件包,该软件包可以编译Swiss Ephemeris代码并从中创建初始R软件包: https://github.com/rstub/SwissEphemeris
SODD got the better of me. I have build a very rough package that compiles the Swiss Ephemeris code and creates an initial R package from it: https://github.com/rstub/SwissEphemeris
现在唯一可用的功能是 day_of_week()
。在Linux和Windows(通过Appveyor)上进行了测试。
Right now the only available function is day_of_week()
. Tested on Linux and Windows (via Appveyor).
这篇关于如何在R中的32位C DLL中调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!