0
我有一個allocVector()函數的問題。我用C編寫了一個可以在R中調用的代碼(DLL)。我想在C#中將該DLL的一個方法調用到我的應用程序中。 DLL代碼工作正常,但編譯器到達下一行ROut = allocVector(INTSXP,2 * 3) 它給出以下例外: 未處理的異常:System.AccessViolationException:試圖讀取或寫入受保護的內存。 的代碼如下:C和System.AccessViolationException中的allocVector():試圖讀取或寫入受保護的內存?
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <R.h>
#include <Rinternals.h>
#include <Rmath.h>
#include <R_ext/Applic.h>
#include <R_ext/Lapack.h>
#include <Rdefines.h>
#ifdef __cplusplus
extern "C" {
#endif
void castType(int *result)
{
SEXP ROut;
ROut = allocVector(INTSXP, 2*3)
ROut = PROTECT(ROut);
int *clustOut = INTEGER(ROut);
result= clustOut ;
}
#ifdef __cplusplus
}
#endif
謝謝您的回答。我遵循在代碼中使用rClr的方法,但編譯時遇到以下錯誤: –
錯誤LNK1104:無法打開文件'Rdll.lib'\t C:\ Users \ Stephan \ Documents \ GitHub \ rdotnet-support \ wrapcppdll \ mycpp \ LINK \t mycpp –
我也跟着下面的步驟因爲他們是所謂的網站CodePlex上建立我的系統上RCLR: %R%CMD檢查RCLR %R%CMD REMOVE RCLR %R%CMD INSTALL RCLR 我收到消息構建成功。 –