Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I have a problem with the allocVector () function. I wrote a code (DLL) in C that can be called in R. I would like to call a method of that DLL into my application in C#. The DLL code works fine but when the compiler reaches the next line SEXP Rout = PROTECT (RclustOut = allocVector (INTSXP, 2 * 3));
It gives following exception:
Unhandled exception: System.AccessViolationException: Attempted to read or write protected memory.
The code is as follow:
C++
#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>

void dividetwo(int a, int b, int *result)
{
*result = a/b;
}
void Rdividetwo(int *a, int *b, int *result)
{
dividetwo(*a, *b, result);
}
#ifdef __cplusplus
extern "C" {
#endif
    void castType(int result, int *sortie)
    {
        SEXP RclustOut, ROut;
        SEXP Rout = PROTECT(RclustOut = allocVector(INTSXP, 2*3));
        PROTECT(ROut = allocVector(VECSXP, 2));
        int *clustOut = INTEGER(RclustOut);

        *sortie = result;

    }

#ifdef __cplusplus
}
#endif
Posted
Updated 6-Jun-15 5:06am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900