none
PInvokeStackImbalance calling unmanaged function RRS feed

  • General discussion

  • Hi all!
     
    This is the unmanaged function
    MODEL lad (const int *list, DATASET *dset);
    

    This is the MODEL structure returned by the function
     
    typedef struct {
        int ID;                      /* ID number for model */
        int refcount;                /* for saving/deleting */
        int ci;                      /* "command index" -- estimation method */
        gretlopt opt;                /* record of options */
        int t1, t2, nobs;            /* starting observation, ending
                                        observation, and number of obs */
        char *submask;               /* keep track of sub-sample in force
                                        when model was estimated */
        char *missmask;              /* missing observations mask */
        SAMPLE smpl;                 /* numeric start and end of current sample
                                        when model was estimated */
        int full_n;                  /* full length of dataset on estimation */
        int ncoeff, dfn, dfd;        /* number of coefficents; degrees of
                                        freedom in numerator and denominator */
        int *list;                   /* list of variables by ID number */
        int ifc;                     /* = 1 if the equation includes a constant,
    				    else = 0 */
        int nwt;                     /* ID number of the weight variable (WLS) */
        int aux;                     /* code representing the sort of
    				    auxiliary regression this is (or not) */
        double *coeff;               /* array of coefficient estimates */
        double *sderr;               /* array of estimated std. errors */
        double *uhat;                /* regression residuals */
        double *yhat;                /* fitted values from regression */
        double *xpx;                 /* X'X matrix, in packed form */
        double *vcv;                 /* VCV matrix for coefficient estimates */
        double ess, tss;             /* Error and Total Sums of Squares */
        double sigma;                /* Standard error of regression */
        double rsq, adjrsq;          /* Unadjusted and adjusted R^2 */     
        double fstt;                 /* overall F-statistic */
        double chisq;                /* overall chi-square statistic */
        double lnL;                  /* log-likelihood */
        double ybar, sdy;            /* mean and std. dev. of dependent var. */
        double criterion[3];     /* array of model selection statistics */
        double dw, rho;              /* Durbin-Watson stat. and estimated 1st
    				    order autocorrelation coefficient */
        ARINFO *arinfo;              /* pointer to struct to hold special info for 
    				    autoregressive model */ 
        int errcode;                 /* Error code in case of failure */
        char *name;                  /* for use in GUI */
        char *depvar;                /* name of dependent var in special cases */
        int nparams;                 /* number of named model parameters */
        char **params;               /* for named model parameters */
        int ntests;                  /* number of attached test results */
        ModelTest *tests;            /* attached hypothesis test results */
        DATASET *dataset;            /* for handling models estimated on a
    				    sub-sampled portion of the dataset */
        int n_data_items;            /* number of extra data items */
        model_data_item **data_items; /* pointer to additional data */
    } MODEL;
    
    
    

    This is the C# method declaration
     
            [DllImport(@"C:\Program Files (x86)\gretl\libgretl.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern MODEL lad(IntPtr list, IntPtr dset);
    
    

    This is the C# structure declaration
     
        [StructLayout(LayoutKind.Sequential)]
        struct SAMPLE
        {
            int t1;
            int t2;
        }
    
    
        [StructLayout(LayoutKind.Sequential)]
        struct MODEL
        {
            int ID;                      /* ID number for model */
            int refcount;                /* for saving/deleting */
            int ci;                      /* "command index" -- estimation method */
            int opt;                     /* record of options */
            int t1, t2, nobs;            /* starting observation, ending observation, and number of obs */
            IntPtr submask;               /* keep track of sub-sample in force when model was estimated */
            IntPtr missmask;              /* missing observations mask */
            SAMPLE smpl;                 /* numeric start and end of current sample when model was estimated */
            int full_n;                  /* full length of dataset on estimation */
            int ncoeff, dfn, dfd;        /* number of coefficents; degrees of freedom in numerator and denominator */
            IntPtr list;                   /* list of variables by ID number */
            int ifc;                     /* = 1 if the equation includes a constant, else = 0 */
            int nwt;                     /* ID number of the weight variable (WLS) */
            int aux;                     /* code representing the sort of auxiliary regression this is (or not) */
            IntPtr coeff;               /* array of coefficient estimates */
            IntPtr sderr;               /* array of estimated std. errors */
            IntPtr uhat;                /* regression residuals */
            IntPtr yhat;                /* fitted values from regression */
            IntPtr xpx;                 /* X'X matrix, in packed form */
            IntPtr vcv;                 /* VCV matrix for coefficient estimates */
            double ess, tss;             /* Error and Total Sums of Squares */
            double sigma;                /* Standard error of regression */
            double rsq, adjrsq;          /* Unadjusted and adjusted R^2 */
            double fstt;                 /* overall F-statistic */
            double chisq;                /* overall chi-square statistic */
            double lnL;                  /* log-likelihood */
            double ybar, sdy;            /* mean and std. dev. of dependent var. */
            //[MarshalAs (UnmanagedType.ByValArray, SizeConst=3)]
            double criterion_1, criterion_2, criterion_3;     /* array of model selection statistics */
            double dw, rho;              /* Durbin-Watson stat. and estimated 1st order autocorrelation coefficient */
            IntPtr arinfo;              /* pointer to struct to hold special info for autoregressive model */
            int errcode;                 /* Error code in case of failure */
            IntPtr name;                  /* for use in GUI */
            IntPtr depvar;                /* name of dependent var in special cases */
            int nparams;                 /* number of named model parameters */
            IntPtr pparams;               /* for named model parameters */
            int ntests;                  /* number of attached test results */
            IntPtr tests;            /* attached hypothesis test results */
            IntPtr dataset;            /* for handling models estimated on a sub-sampled portion of the dataset */
            int n_data_items;            /* number of extra data items */
            IntPtr data_items; /* pointer to additional data */
        }
    
    

    calling C# lad function produces PInvokeStackImbalance.
    I checked so many times my structure .... unsuccessfully: I know, I'm wrong but it seems ok :-)
    Thanks for any help!
    Filippo

    Tuesday, January 10, 2012 10:42 AM

All replies