www.pudn.com > myopenforcal.zip > NotUseFor.cpp
#include "windows.h"
#include "math.h"
//初始化动态库;
extern "C" __declspec(dllexport) void InitDll(void);
//自定义预编译处理程序,在编译前被调用;
extern "C" __declspec(dllexport) bool PreCom(char *&);
//释放动态库;
extern "C" __declspec(dllexport) void FreeDll(void);
//向OPenFC发送信息;
typedef void (* pDllMessage) (char *);
pDllMessage pDllMessagep;
extern "C" __declspec(dllexport) void DllMessage(pDllMessage );
//使用Forcal字符串;
char ** ppchFcStr;
long * plFcStrMax,StrsMax;
extern "C" __declspec(dllexport) void GetFcStr(char **,long *,long );
//定义可由OPenFC调用的实数函数;
extern "C" __declspec(dllexport) void RegRealFun(char **&,int *&,double (**&)(int ,double *));
double rfc_add(int ,double *);
double rfc_sub(int ,double *);
double rfc_nstr(int ,double *);
double rfc_outarray(int ,double *);
double rfc_notusefordllfile(int m,double *x);
char *ppchRealNameDll[]={"add","sub","nstr","outarray","notusefordllfile",""}; //外部函数名;
int piRealParaDll[]={1,1,1,0,-1}; //-2表示有不确定的多个自变量,-1表示有0个自变量,0表示有1个自变量,1表示有2个自变量;
double (*ppRealFunDll[])(int ,double *)={rfc_add,rfc_sub,rfc_nstr,rfc_outarray,rfc_notusefordllfile}; //外部函数指针数组;
//定义可由OPenFC调用的整数函数;
extern "C" __declspec(dllexport) void RegIntFun(char **&,int *&,long (**&)(int ,long *));
long ifc_add(int ,long *);
long ifc_sub(int ,long *);
char *ppchIntNameDll[]={"add","sub",""}; //外部函数名;
int piIntParaDll[]={1,1}; //-2表示有不确定的多个自变量,-1表示有0个自变量,0表示有1个自变量,1表示有2个自变量;
long (*ppIntFunDll[])(int ,long *)={ifc_add,ifc_sub}; //外部函数指针数组;
//定义可由OPenFC调用的复数函数;
extern "C" __declspec(dllexport) void RegComplexFun(char **&,int *&,_complex (**&)(int ,_complex *));
_complex cfc_add(int ,_complex *);
_complex cfc_sub(int ,_complex *);
char *ppchComplexNameDll[]={"add","sub",""}; //外部函数名;
int piComplexParaDll[]={1,1}; //-2表示有不确定的多个自变量,-1表示有0个自变量,0表示有1个自变量,1表示有2个自变量;
_complex (*ppComplexFunDll[])(int ,_complex *)={cfc_add,cfc_sub}; //外部函数指针数组;
//使用实数数组;
typedef double **(* pGETFCDOUBLEARRAY) (long &,long *&);
pGETFCDOUBLEARRAY pGETFCDOUBLEARRAYp;
extern "C" __declspec(dllexport) void GetFcDoubleArray(pGETFCDOUBLEARRAY); //输出函数;
double **ppfcdoublearray; //多维存储数组doublearray的指针;
long fcdoublearrayMax; //多维存储数组doublearray的大小;
long *pfcdoublearrayMax; //多维存储数组doublearray中各维数组长度的整数组的指针;
//使用复数数组;
typedef _complex **(* pCGETFCCOMPLEXARRAY) (long &,long *&);
pCGETFCCOMPLEXARRAY pCGETFCCOMPLEXARRAYp;
extern "C" __declspec(dllexport) void GetFcComplexArray(pCGETFCCOMPLEXARRAY); //输出函数;
_complex **ppfccomplexarray; //多维存储数组_complexarray的指针;
long fccomplexarrayMax; //多维存储数组_complexarray的大小;
long *pfccomplexarrayMax; //多维存储数组_complexarray中各维数组长度的整数组的指针;
//使用整数数组;
typedef long **(* pIGETFCLONGARRAY) (long &,long *&);
pIGETFCLONGARRAY pIGETFCLONGARRAYp;
extern "C" __declspec(dllexport) void GetFcLongArray(pIGETFCLONGARRAY); //输出函数;
long **ppfclongarray; //多维存储数组longarray的指针;
long fclongarrayMax; //多维存储数组longarray的大小;
long *pfclongarrayMax; //多维存储数组longarray中各维数组长度的整数组的指针;
//得到动态库的说明信息;
class DllFunChar
{public:
char *pstrname,*pstr;
DllFunChar *headDllFunChar,*endDllFunChar;
DllFunChar();
DllFunChar(DllFunChar *);
~DllFunChar();
bool setDllFunCharName(char *);
bool setDllFunChar(char *);
};
class DllFunFile
{public:
char *DllFunFilename;
DllFunChar *pDllFunChar,head_DllFunChar;
DllFunFile *headDllFunFile,*endDllFunFile;
DllFunFile();
DllFunFile(DllFunFile *);
~DllFunFile();
bool setDllFunFilename(char *);
};
typedef DllFunFile *(* pGetDllFunFile)();
extern "C" __declspec(dllexport) void GetDllFunFile(pGetDllFunFile );//在动态库被加载时,该函数被OpenForcal自动调用,因此扩展动态库要输出该函数;
pGetDllFunFile pGetDllFunFilep=NULL;//存放函数地址;
DllFunFile *pDllFunFile;//工作指针;
/////////////////////////////////////////////////////////////////////////////
// 动态库的输出函数;
extern "C" __declspec(dllexport) void InitDll(void)
{MessageBox(GetFocus(),"NotUseFor.dll初始化!","NotUseFor",MB_OK);}
extern "C" __declspec(dllexport) bool PreCom(char *&str) //NotUseFor.dll预处理程序,注意不能释放字符串str;
{if(pDllMessagep) pDllMessagep("\r\nNotUseFor.dll预处理程序!\r\n");
return true;
}
extern "C" __declspec(dllexport) void FreeDll(void)
{MessageBox(GetFocus(),"释放NotUseFor.dll!","NotUseFor",MB_OK);}
extern "C" __declspec(dllexport) void DllMessage(pDllMessage message)
{pDllMessagep=message;}
extern "C" __declspec(dllexport) void GetFcStr(char **ppCh,long *pm,long n)
{ppchFcStr=ppCh; plFcStrMax=pm; StrsMax=n;}
extern "C" __declspec(dllexport) void RegRealFun(char **&ppchRealName,int *&piRealPara,double (**&ppRealFun)(int ,double *))
{ppchRealName=ppchRealNameDll; piRealPara=piRealParaDll; ppRealFun=ppRealFunDll;
}
extern "C" __declspec(dllexport) void RegIntFun(char **&ppchIntName,int *&piIntPara,long (**&ppIntFun)(int ,long *))
{ppchIntName=ppchIntNameDll; piIntPara=piIntParaDll; ppIntFun=ppIntFunDll;
}
extern "C" __declspec(dllexport) void RegComplexFun(char **&ppchComplexName,int *&piComplexPara,_complex (**&ppComplexFun)(int ,_complex *))
{ppchComplexName=ppchComplexNameDll; piComplexPara=piComplexParaDll; ppComplexFun=ppComplexFunDll;
}
extern "C" __declspec(dllexport) void GetFcDoubleArray(pGETFCDOUBLEARRAY getda) {pGETFCDOUBLEARRAYp=getda;}
extern "C" __declspec(dllexport) void GetFcComplexArray(pCGETFCCOMPLEXARRAY getca) {pCGETFCCOMPLEXARRAYp=getca;}
extern "C" __declspec(dllexport) void GetFcLongArray(pIGETFCLONGARRAY getia) {pIGETFCLONGARRAYp=getia;}
extern "C" __declspec(dllexport) void GetDllFunFile(pGetDllFunFile pFunFile) {pGetDllFunFilep=pFunFile;}
// 定义一些简单的实数函数;
double rfc_add(int m,double *x) //计算两个数的和;
{return x[0]+x[1];}
double rfc_sub(int m,double *x) //计算两个数的差;
{return x[0]-x[1];}
double rfc_nstr(int m,double *x) //该函数将一个字符串复制了n次;
{long i,j,k;
i=(long)x[0]; j=(long)x[1];
if(i<0||i>=StrsMax)
{pDllMessagep("\r\nnstr( )错误:指定的字符串不存在!\r\n"); return 0.0;}
if(ppchFcStr[i])
{for(k=0;k=fcdoublearrayMax) {pDllMessagep("\r\noutarray( )错误:指定的数组不存在!\r\n"); return 0.0;}
for(j=0;jendDllFunFile)
{pDllFunFile=pDllFunFile->endDllFunFile;
pDllMessagep("\r\n*****动态库说明文件:");
pDllMessagep(pDllFunFile->DllFunFilename);
pDllMessagep("\r\n");
pDllFunFile->pDllFunChar=&(pDllFunFile->head_DllFunChar);
while(pDllFunFile->pDllFunChar->endDllFunChar)
{pDllFunFile->pDllFunChar=pDllFunFile->pDllFunChar->endDllFunChar;
pDllMessagep("**函数:");
pDllMessagep(pDllFunFile->pDllFunChar->pstrname);
pDllMessagep("\r\n");
pDllMessagep("**函数说明:\r\n");
pDllMessagep(pDllFunFile->pDllFunChar->pstr);
}
}
return 0.0;
}
// 定义一些简单的整数函数;
long ifc_add(int m,long *x)
{return x[0]+x[1];}
long ifc_sub(int m,long *x)
{return x[0]-x[1];}
// 定义一些简单的复数函数;
_complex cfc_add(int m,_complex *x)
{x[0].x=x[0].x+x[1].x; x[0].y=x[0].y+x[1].y; return x[0];}
_complex cfc_sub(int m,_complex *x)
{x[0].x=x[0].x-x[1].x; x[0].y=x[0].y-x[1].y; return x[0];}