Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Passing Struct Parameters to Dll
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Problèmes
Divers
Thread ID:
00763728
Message ID:
00763798
Vues:
19
Thank You for your response. I am very appreciate. So basically the buffer size in fox needs to be greater than or equal to the number of bytes the structure takes up, Correct?
the following is a C++ sample of the structures that I need to be able to represent in Fox. Some of the structures need to be preinitialized with values before the call. I will put the .cpp code after the header code.
NOTE: lpResult= BfsForecast(&_fcpSeries, &_fcpStdstat, &_fcpSettings, &_fcpExsm, &_fcpBoxj, &_fcpSmav, &_fcpDscd, &_fcpCroston);
Is the actual exorted dll function its call is at the very bottom of this message.
**********************************************
//Header Code :
**********************************************

#ifndef IMPORT
#define IMPORT extern "C" __declspec(dllimport)
#endif

#ifndef MOD_UNKN
#define MOD_UNKN -1 // Used internally only
#define MOD_EXPT 0 // Expert selection
#define MOD_EXSM 1 // Exponential smoothing
#define MOD_BOXJ 2 // Box-Jenkins
#define MOD_SIMP 4 // Simple moving average
#define MOD_DCRT 5 // Discrete
#define MOD_CRST 6 // Intermittent data
#define MOD_FXSM 11 // Fixed smoothing model
#endif

// short 2 byte integer
// int 4 byte integer
// double 8 byte floating point
// float* 4 byte pointer to 4 byte float (NULL = 4 byte 0)
// char[] Array of characters terminated with a 0
// enum 4 byte integer
// BOOL 4 byte integer

// The members of the following structs are ordered to avoid
// padding by the compiler. The ANSI standard alignment
// requirement for data objects is as follows.
// structs and arrays Largest alignment requirement for
//any member
// All others
//Size of the data object

struct _series
{
int nLen; // In: Length of historic data
int nHorizon; // In: Forecast horizon
int nPpc; // In: Periods per seasonal cycle
float* pfY; // In: Historic data (nLen)
float* pfEvents; // Out: NULL or event codes (nLen+nHorizon)
float* pfPoint; // Out: Fitted values and forecasts
//( nLen+nHorizon)
float* pfUpper; // Out: Upper confidence limits
//(nLen+nHorizon)
float* pfLower; // Out: Lower confidence limits
//(nLen+nHorizon)
float* pfStock; // Out: Safety stocks (nHorizon)
float* pfWeight; // Out: NULL or data weights (nLen + nHorizon)
float* pfIndex; // Out: NULL or seasonal indexes
//(nLen + nHorizon)
};

typedef struct _series SERIES;

struct _settings
{
double dPow; // In and out: Desired power transform
//(returns actual)

double dUpperPercentile; // In: Upper limit as a
//percent (e.g. 97.5)
double dLowerPercentile; // In: Lower limit as a percent
// (e.g. 2.5)
int iModelFamily; // In and out: Desired model
//family code (returns actual)

int bNegative; // In: 1 if forecasts can
//go negative, else 0

int bConst; // In: 1 to force a constant in BJ,
// else 0

int nSma; // In: Number of moving average terms
bool bQuick; // In: 1 skips out-of-sample testing
char szExsm[3]; // In: Smoothing model selection control
};

typedef struct _settings SETTINGS;

// szExsm contains two characters, followed by a zero, for a total of
// three bytes. The first character controls the trend, and
//must be N, L, D, E
// or *, standing for No trend, Linear trend, Decaying trend, Exponential
//trend and "Let
// the program decide," respectively. The second character controls the
// seasonality, and must be N, A, M or *, standing for No seasonality,
// Additive seasonality, Multiplicative seasonality or "Let the program
//decide,"
// respectively.
// We recommend that you set this string to "**" for completely
// automatic operation.

#ifndef ROLLSTAT_DEFINED
#define ROLLSTAT_DEFINED
// Must be identical to definition in FpwLib.h
struct _rollstat
{
double dMape;
double dMad;
double dGmrae;
double dNaiveMape;
int nMape;
int nMad;
int nGmrae;
int nUnder;
int nOver;
int nBetterThanNaive;
};

typedef struct _rollstat ROLLSTAT;
#endif

#ifndef STDSTAT_DEFINED
// These definitions must match those in stdstat.h

#define MXACF 48 /* Number of lags in ACF graph */

struct stdstat /* Standard statistics */
{
double ymean; /* Series mean */
double ysdev; /* Standard deviation */
double sigma; /* Historical forecast error */
double rmserr; /* Historica RMS error */
double tss; /* Total sum of squares */
double ess; /* Error sum of squares */
double rsq; /* R square */
double adjrsq; /* Adjusted R square */
double fstat; /* F statistic */
double dw; /* Durbin Watson statistic */
double lbox; /* Ljung-Box statistic */
double complexity; /* Model complexity */
double aic; /* Akaike criterion */
double bic; /* Schwarz criterion */
double mape; /* Mean absolute percent error */
double rawerr; /* Raw forecast error */
double mad; /* Mean absolute deviation */
double eacf[MXACF+1]; /* Error ACF */
int n; /* Number of observations */
int lbdf; /* Ljung-Box dgrees of freedom */
int neacf; /* Number of lags in eacf */
};

typedef struct stdstat STDSTAT;

/*--------------------------------------------------------------------*/
/* Simple Moving Average */
/*--------------------------------------------------------------------*/

struct _sma
{
int nTerms;
};

typedef struct _sma SMAV;

/*--------------------------------------------------------------------*/
/* Box-Jenkins Structure */
/*--------------------------------------------------------------------*/

#define MXPQ 9

struct boxj
{
double constant; /* Constant term */
double econstant; /* Constant std error */
double a[MXPQ]; /* AR parameters */
double b[MXPQ]; /* MA parameters */
double ea[MXPQ]; /* AR std errors */
double eb[MXPQ]; /* MA std errors */
double sa[MXPQ]; /* Seasonal AR parameters */
double sb[MXPQ]; /* Seasonal MA parameters */
double esa[MXPQ]; /* Seasonal AR std errors */
double esb[MXPQ]; /* Seasonal MA std errors */
short bConst; /* Constant? (0,1) */
short p; /* AR order */
short d; /* Degree of differencing */
short q; /* MA order */
short sp; /* Seasonal AR order */
short sd; /* Seasonal degree of differencing */
short sq; /* Seasonal MA order */
};

typedef struct boxj BOXJ;

/*--------------------------------------------------------------------*/
/* Exponential smoothing */
/*--------------------------------------------------------------------*/

/* Smoothing model structure */

enum trends {untrended, linear, decaying, exponential};
enum seasonals {nonseasonal, additive, multiplicative};
enum types {standard, extended};

struct exsm
{
double a; /* Level parameter */
double b; /* Trend parameter */
double c; /* Seasonal parameter */
double cx; /* Extended seasonal parameter */
double d; /* Decay parameter */
enum trends trend; /* Trend model */
enum seasonals seasonal; /* Seasonality model */
enum seasonals xseasonal; /* Extended seasonality model */
int iVariance; /* Chatfield variance model */
};

typedef struct exsm EXSM;

// Chatfield) variance models
#define CONSTANT_VAR 0
#define MULTIPLICATIVE_VAR 1
#define FULLY_MULTIPLICATIVE_VAR 2

/*--------------------------------------------------------------------*/
/* Discrete Distributions */
/*--------------------------------------------------------------------*/

enum discrete_dists {negative_binomial, poisson, binomial};

typedef enum discrete_dists DSCDIST;

struct _dscr
{
double dVarToMean;
EXSM sm;
DSCDIST dist;
};

typedef struct _dscr DSCD;

/*--------------------------------------------------------------------*/
/* Croston Model */
/*--------------------------------------------------------------------*/

struct croston
{
double dWgtX; /* Smoothing weights */
double dWgtT;
double dMeanX; /* Final state */
double dMeanT;
double dSigmaLogX; /* Static value */
double dSigmaX; /* Static value */
int tLast; /* Time of last positive value */
};

typedef struct croston CROSTON;

// BfsForecast returns one of the following error codes
#define STAT_BASE 2048
#define STAT_OK 0+STAT_BASE /* No problem */
#define STAT_SAMPLE 1+STAT_BASE /* Sample size too small */
#define STAT_STACK 2+STAT_BASE /* Stack overflow */
#define STAT_MEMORY 3+STAT_BASE /* No memory */
#define STAT_FLOAT 4+STAT_BASE /* Floating point error */
#define STAT_NEGATIVE 5+STAT_BASE /* Negative forecast range */
#define STAT_COLLINEAR 6+STAT_BASE /* Colinearity */
#define STAT_INVERSION 7+STAT_BASE /* Cholesky inversion error */
#define STAT_NONSTATIONARY 8+STAT_BASE /* Nonstationary model */
#define STAT_NONINVERTIBLE 9+STAT_BASE /* Noninvertible model */
#define STAT_SOFT_MEMORY 10+STAT_BASE /* Recoverable memory problem */
#define STAT_BOXCOX 11+STAT_BASE /* Attempt to transform nonpositive */
#define STAT_NONPOSMULT 12+STAT_BASE /* Multiplicative seasonal of nonpositive */
#define STAT_POWNEG 13+STAT_BASE /* Power transform of nonpositive number */
#define STAT_EXPBIG 14+STAT_BASE /* Exponential is too big */
#define STAT_SQRTNEG 15+STAT_BASE /* Square root of negative */
#define STAT_LOGNEG 16+STAT_BASE /* Log of nonpositive */
#define STAT_POWBIG 17+STAT_BASE /* Power operation yields overflow */
#define STAT_DIVIDE 18+STAT_BASE /* Division by zero */
#define STAT_DOMAIN 19+STAT_BASE /* Argument domain error */
#define STAT_SING 20+STAT_BASE /* Argument singularity */
#define STAT_OVERFLOW 21+STAT_BASE /* Overflow range error */
#define STAT_UNDERFLOW 22+STAT_BASE /* Overflow range error */
#define STAT_PLOSS 23+STAT_BASE /* Partial loss of significance */
#define STAT_TLOSS 24+STAT_BASE /* Total loss of significance */
#define STAT_ADDMLT 25+STAT_BASE /* Mixed seasonal model */
#define STAT_CROSTON 26+STAT_BASE /* Bad data for CROSTON */
#define STAT_BADINDEX 27+STAT_BASE /* Bad multiplicative index */
#define STAT_NODATA 28+STAT_BASE /* Sample size is zero */
#define STAT_NOMODEL 29+STAT_BASE /* No model was selected */

#define MISSING_VALUE -9999
#define STDSTAT_DEFINED
#endif

#ifndef DLL_EXPORT
IMPORT int __stdcall BfsForecast(SERIES* pData, STDSTAT* pStdstat,
SETTINGS* pSettings, EXSM* pExSm, BOXJ* pBj, SMAV* pSma,
DSCD* pDsc, CROSTON* pCroston);
IMPORT int __stdcall BfsForecastExtension(ROLLSTAT* prStat, int nHold);
IMPORT int __stdcall GetFpwLibMajor();
IMPORT int __stdcall GetFpwLibMinor();
IMPORT float* __stdcall AddressOfFloat(float* pf);
#endif

*********************************
End Header

*********************************



***********************************************************
Example C++ Source Code That needs to be represented in Fox

***********************************************************


class dllTest2
{
public:
int testThis( );
dllTest2();

//ForecastPro Specific
protected: //Declaring variables

SERIES _fcpSeries ; //Required input structure
SETTINGS _fcpSettings ; //Required input structure
STDSTAT _fcpStdstat; //Required input structure
SMAV _fcpSmav; //Optional input/output structure
BOXJ _fcpBoxj; //Optional input/output structure
EXSM _fcpExsm; //Optional input/output structure
DSCD _fcpDscd; //Optional input/output structure
CROSTON _fcpCroston; //Optional input/output structure
//End ForecastPro Specific



};




dllTest2::dllTest2()
{

}

int dllTest2::testThis( )
{

//ForeCastPro Specific
int lpResult=0; //return result code from Fpwlib.dll
float historyArray[12]={0}; //Array of actual historical values.
//Dimensions of array = fcpSeries.nLen

float forecastArray[24]={0}; //Array of returned fitted and
// forecasted values. Dimensions of
// array = fcpSeries.nLen +
// fcpSeries.nHorizon

float upConf[24]; //Array of returned values for upper
// confidence limit. Dimensions of
// array = fcpSeries.nLen +
// fcpSeries.nHorizon

float lowConf[24]; //Array of returned values for lower
// confidence limit. Dimensions of array =
//fcpSeries.nLen + fcpSeries.nHorizon

float safetyStock[12];



historyArray[0] = 100;
historyArray[1] = 200;
historyArray[2] = 300;
historyArray[3] = 400;
historyArray[4] = 500;
historyArray[5] = 600;
historyArray[6] = 700;
historyArray[7] = 800;
historyArray[8] = 900;
historyArray[9] =1000;
historyArray[10]=1100;
historyArray[11]=1200;


//*************************************************
// Set the Settings Structure values
//*************************************************

_fcpSettings.dPow = 1.0 ; //Box-Cox power transform. Normally, set
// dPow=1.0 for no transform

_fcpSettings.dUpperPercentile = 97.5 ; //Percentile for Upper Confidence
//limit

_fcpSettings.dLowerPercentile = 2.5 ; //Percentile for Lower Confidence
// limit

_fcpSettings.iModelFamily = 0; //Model selection code. Set to 0 for
//automatic.

_fcpSettings.bNegative = 1 ; //Control to allow negative forecasts (set to 1 to enable)

_fcpSettings.bConst = 0 ; //Control to force a constant term in Box Jenkins (normally set to
//0 = do not force term)

_fcpSettings.nSma = 0 ; //Number of periods to use in moving averages (set to 0 for
//automatic)

_fcpSettings.bQuick = 0 ; //Control to omit out-of-sample testing in expert selection.
//(normally set to 0 = allow out-of-sample testing)

_fcpSettings.szExsm[0] = '*' ;
//Control for trend component of Exponential Smoothing models
//(set to * for automatic)

_fcpSettings.szExsm[1] = '*' ;
//Control for seasonality component of Exponential Smoothing
//models (set to * for automatic)

_fcpSettings.szExsm[2] = 0 ;
//Always set to 0



//*************************************************
// Set the Series Structure values
//*************************************************

_fcpSeries.nLen = 12 ; //Length of historic data array

_fcpSeries.nHorizon = 12 ; //Forecast horizon

_fcpSeries.nPpc = 12 ; //Number of periods per seasonal cycle

_fcpSeries.pfY = &(historyArray[0]) ;
//Pointer to historyArray array

_fcpSeries.pfEvents= 0; //Pointer to events array

_fcpSeries.pfPoint = &(forecastArray[0]) ;
//Pointer to forecastArray
//array

_fcpSeries.pfUpper = &(upConf[0]) ;
//Pointer to upConf array

_fcpSeries.pfLower = &(lowConf[0]) ;
//Pointer to lowConf array

_fcpSeries.pfStock = &(safetyStock[0]) ;
//Pointer to safetyStock array

_fcpSeries.pfWeight= 0; //Pointer to weight array

_fcpSeries.pfIndex = 0; //Pointer to index array


//*************************************************
// Make the call to Fpw.dll
//*************************************************

//Passing addresses of structures to BfsForecast.
//Passing Nulls for optional input structures.
lpResult= BfsForecast(&_fcpSeries, &_fcpStdstat, &_fcpSettings, &_fcpExsm, &_fcpBoxj, &_fcpSmav, &_fcpDscd, &_fcpCroston);
//End ForeCastPro Specific



return( lpResult );

}
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform