www.pudn.com > myopenforcal.zip > OpenFCtestDlg.cpp
// OpenFCtestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "OpenFCtest.h"
#include "OpenFCtestDlg.h"
#include "math.h" //使用数学函数;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
HINSTANCE OpenForcalDll;
//得到初始化动态库函数的地址;
typedef bool (* pInitDll)(char *,char *);
pInitDll pInitDllp;
//得到释放动态库函数的地址;
typedef void (* pFreeDll)(void);
pFreeDll pFreeDllp;
//得到编译函数的地址;
typedef void (* pCOMPLEXfun) (_complex );
typedef void (* pDOUBLEfun) (double );
typedef void (* pLONGfun) (long );
void outl(long);
void outd(double);
void outc(_complex);
void DllMessage(char *);
typedef void (* pDllMessage) (char *);
pDllMessage pDllMessagep=NULL;
void GetDllMessage(pDllMessage );
typedef void (* pGetDllMessage) (void (*)(pDllMessage ));
pGetDllMessage pGetDllMessagep;
typedef int (* pComFor) (char *,char *&,pLONGfun ,pDOUBLEfun ,pCOMPLEXfun ,pDllMessage);
pComFor pComForp;
//得到计算函数的地址;
typedef int (* pExeFor) (long ,long ,int);
pExeFor pExeForp;
////////////////////////////////
typedef void (* pPreCom)(bool (*)(char *&));
pPreCom pPreComp;
bool PreCom(char *&);
////////////////////////////////
//定义几个可由FORCAL调用的实数外部函数;
double rfc_clear(int ,double *);
double rfc_out(int ,double *);
double rfc_str(int ,double *);
double rfc_endl(int ,double *);
double rfc_outarray(int ,double *);
double rfc_dllfile(int ,double *);
char *rFunName[]={"clear","out","str","endl","outarray","dllfile",""}; //外部函数名;
int rFunPara[]={-1,0,0,-1,0,-1}; //-2表示有不确定的多个自变量,-1表示有0个自变量,0表示有1个自变量,1表示有2个自变量;
double (*rFunCal[])(int ,double *)={rfc_clear,rfc_out,rfc_str,rfc_endl,rfc_outarray,rfc_dllfile}; //外部函数指针数组;
//定义几个可由FORCAL调用的复数外部函数;
_complex cfc_out(int ,_complex *);
char *cFunName[]={"out",""}; //外部函数名;
int cFunPara[]={0}; //-2表示有不确定的多个自变量,-1表示有0个自变量,0表示有1个自变量,1表示有2个自变量;
_complex (*cFunCal[])(int ,_complex *)={cfc_out}; //外部函数指针数组;
//定义几个可由FORCAL调用的整数外部函数;
long ifc_out(int ,long *);
char *iFunName[]={"out",""}; //外部函数名;
int iFunPara[]={0}; //-2表示有不确定的多个自变量,-1表示有0个自变量,0表示有1个自变量,1表示有2个自变量;
long (*iFunCal[])(int ,long *)={ifc_out}; //外部函数指针数组;
typedef void (* pRegIntFun)(char **,int *,long (**)(int ,long *));
pRegIntFun pRegIntFunp;
typedef void (* pRegRealFun)(char **,int *,double (**)(int ,double *));
pRegRealFun pRegRealFunp;
typedef void (* pRegComplexFun)(char **,int *,_complex (**)(int ,_complex *));
pRegComplexFun pRegComplexFunp;
typedef double (* pRCALS) (int );
typedef int (* pRFCERRNUM) (void);
typedef void (*pRSETFCERR) (int ,char *);
pRCALS pRCALSp;
pRFCERRNUM pRFCERRNUMp;
pRSETFCERR pRSETFCERRp;
bool *prForTrue;
double **pprAllIn;
int *prForPara;
int rForMax;
typedef void (* pGetRealFor)(pRCALS &,pRFCERRNUM &,pRSETFCERR &,bool *&,double **&,int *&,int &);
pGetRealFor pGetRealForp;
///////////////////////////////////////////
char **fc_str;
long *fc_strmax;
long fc_strsmax;
typedef void (* pGetFcStr)(char **&ppch,long *&pl,long &max);
pGetFcStr pGetFcStrp;
//////////////////////////////////////////
CEdit *pout;
/////////////////////////////////////////
typedef double **(* pGetFcDoubleArrayS) (long &,long *&);
pGetFcDoubleArrayS pGetFcDoubleArraySp;
long DoubleArraySMax,*pDoubleArrayMax;
double **ppDoubleArrayS;
typedef void (* pGetFcDoubleArray)(pGetFcDoubleArrayS &);
pGetFcDoubleArray pGetFcDoubleArrayp;
/////////////////////////////////////////
typedef void (* pGetOpenFcSet)(long &,int &,int &,int &,long &,char *&,char *&);
pGetOpenFcSet pGetOpenFcSetp;
char *pdllname,*pdllfile;
typedef int (* pSetOpenFcSet)(long ,int ,int ,int ,long ,char *);
pSetOpenFcSet pSetOpenFcSetp;
typedef bool (* pLoadDllFunFile)(char *);
pLoadDllFunFile pLoadDllFunFilep;
/////////////////////////////////////////
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 *);
};
DllFunFile *pDllFunFile,*pHead_DllFunFile;
typedef DllFunFile *(* pGetDllFunFile)();
pGetDllFunFile pGetDllFunFilep;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COpenFCtestDlg dialog
COpenFCtestDlg::COpenFCtestDlg(CWnd* pParent /*=NULL*/)
: CDialog(COpenFCtestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(COpenFCtestDlg)
m_filemax = 0;
m_intmax = 0;
m_complexmax = 0;
m_stringmax = 0;
m_realmax = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void COpenFCtestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COpenFCtestDlg)
DDX_Control(pDX, IDC_filename, m_filename);
DDX_Control(pDX, IDC_loaddllname, m_loaddllname);
DDX_Control(pDX, IDC_out, m_out);
DDX_Control(pDX, IDC_text, m_text);
DDX_Text(pDX, IDC_filemax, m_filemax);
DDV_MinMaxLong(pDX, m_filemax, 100, 10000000);
DDX_Text(pDX, IDC_intmax, m_intmax);
DDV_MinMaxInt(pDX, m_intmax, 5, 30000);
DDX_Text(pDX, IDC_complexmax, m_complexmax);
DDV_MinMaxInt(pDX, m_complexmax, 5, 30000);
DDX_Text(pDX, IDC_stringmax, m_stringmax);
DDV_MinMaxLong(pDX, m_stringmax, 5, 10000000);
DDX_Text(pDX, IDC_realmax, m_realmax);
DDV_MinMaxInt(pDX, m_realmax, 5, 30000);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COpenFCtestDlg, CDialog)
//{{AFX_MSG_MAP(COpenFCtestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_cal, Oncal)
ON_BN_CLICKED(IDC_set, Onset)
ON_BN_CLICKED(IDC_loadfile, Onloadfile)
ON_BN_CLICKED(IDC_com, Oncom)
ON_BN_CLICKED(IDC_run, Onrun)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COpenFCtestDlg message handlers
BOOL COpenFCtestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
OpenForcalDll=NULL;
OpenForcalDll=LoadLibrary("OpenForcal.dll");
if(OpenForcalDll)
{pRegIntFunp=(pRegIntFun) GetProcAddress(OpenForcalDll,"RegIntFun");
pRegIntFunp(iFunName,iFunPara,iFunCal);
pRegRealFunp=(pRegRealFun) GetProcAddress(OpenForcalDll,"RegRealFun");
pRegRealFunp(rFunName,rFunPara,rFunCal);
pRegComplexFunp=(pRegComplexFun) GetProcAddress(OpenForcalDll,"RegComplexFun");
pRegComplexFunp(cFunName,cFunPara,cFunCal);
pComForp=(pComFor) GetProcAddress(OpenForcalDll,"ComFor");
pExeForp=(pExeFor) GetProcAddress(OpenForcalDll,"ExeFor");
pGetDllMessagep=(pGetDllMessage) GetProcAddress(OpenForcalDll,"DllMessage");
pGetDllMessagep(GetDllMessage);
pPreComp=(pPreCom) GetProcAddress(OpenForcalDll,"PreCom");
pPreComp(PreCom);
pInitDllp=(pInitDll) GetProcAddress(OpenForcalDll,"InitDll");
pInitDllp("OpenFC.ini","OpenFChlp.ini");
pGetRealForp=(pGetRealFor) GetProcAddress(OpenForcalDll,"GetRealFor");
pGetRealForp(pRCALSp,pRFCERRNUMp,pRSETFCERRp,prForTrue,pprAllIn,prForPara,rForMax);
pGetFcStrp=(pGetFcStr) GetProcAddress(OpenForcalDll,"GetFcStr");
pGetFcStrp(fc_str,fc_strmax,fc_strsmax);
pGetFcDoubleArrayp=(pGetFcDoubleArray) GetProcAddress(OpenForcalDll,"GetFcDoubleArray");
pGetFcDoubleArrayp(pGetFcDoubleArraySp);
pFreeDllp=(pFreeDll) GetProcAddress(OpenForcalDll,"FreeDll");
pGetOpenFcSetp=(pGetOpenFcSet) GetProcAddress(OpenForcalDll,"GetOpenFcSet");
pGetOpenFcSetp(m_filemax,m_intmax,m_realmax,m_complexmax,m_stringmax,pdllname,pdllfile);
m_loaddllname.SetSel(0,-1); m_loaddllname.ReplaceSel(pdllname);
m_filename.SetSel(0,-1); m_filename.ReplaceSel(pdllfile);
this->UpdateData(false);
pSetOpenFcSetp=(pSetOpenFcSet) GetProcAddress(OpenForcalDll,"SetOpenFcSet");
pLoadDllFunFilep=(pLoadDllFunFile) GetProcAddress(OpenForcalDll,"LoadDllFunFile");
pGetDllFunFilep=(pGetDllFunFile) GetProcAddress(OpenForcalDll,"GetDllFunFile");
pHead_DllFunFile=pGetDllFunFilep();
}
else
{AfxMessageBox("找不到动态库OpenForcal.dll,请将OpenForcal.dll放到Windows的搜索路径内!",MB_OK,0);}
pout=&m_out;
return TRUE; // return TRUE unless you set the focus to a control
}
void COpenFCtestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void COpenFCtestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR COpenFCtestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void COpenFCtestDlg::Oncal()
{
// TODO: Add your control notification handler code here
CString textstr;
int n;
char *err_str="",ch[32];
m_text.GetWindowText(textstr);
if(OpenForcalDll)
{n=pComForp((char *)(LPCTSTR)textstr,err_str,outl,outd,outc,DllMessage);
if(n)
{m_out.ReplaceSel(err_str);
m_out.ReplaceSel("\r\n编译错误代码:");
m_out.ReplaceSel(itoa(n,ch,10));
}
pExeForp(0,-1,2);
}
}
/////////////////////////////////////////////
void outl(long ll)
{char ch[32];
pout->ReplaceSel("i:");
pout->ReplaceSel(ltoa(ll,ch,10));
pout->ReplaceSel("\r\n");
}
void outd(double dd)
{char ch[32];
pout->ReplaceSel(gcvt(dd,16,ch));
pout->ReplaceSel("\r\n");
}
void outc(_complex cc)
{char ch[32];
pout->ReplaceSel("c:");
pout->ReplaceSel(gcvt(cc.x,16,ch));
if(cc.y>=0.0) pout->ReplaceSel("+");
pout->ReplaceSel(gcvt(cc.y,16,ch));
pout->ReplaceSel("i\r\n");
}
///////////////////////////////
void DllMessage(char *ch) {pout->ReplaceSel(ch); pout->ReplaceSel("\r\n");}
void GetDllMessage(pDllMessage m) {pDllMessagep=m;}
bool PreCom(char *&pch)
{if(pDllMessagep) pDllMessagep("\r\nOpenFCtest预处理程序!!!\r\n"); return true;}
///////////////////////////////
double rfc_clear(int m,double *x)
{pout->SetSel(0,-1);
pout->ReplaceSel("");
return 0.0;
}
double rfc_out(int m,double *x)
{char name[32];
pout->ReplaceSel(gcvt(x[0],16,name));
return x[0];
}
_complex cfc_out(int m,_complex *x)
{char name[32];
pout->ReplaceSel(gcvt(x[0].x,16,name));
if(x[0].y>=0.0) pout->ReplaceSel("+");
pout->ReplaceSel(gcvt(x[0].y,16,name)); pout->ReplaceSel("i");
return x[0];
}
long ifc_out(int m,long *x)
{char name[12];
pout->ReplaceSel(ltoa(x[0],name,10));
return x[0];
}
double rfc_str(int m,double *x)
{long kk;
kk=(long)x[0];
if(kk>=0&&kkReplaceSel(fc_str[kk]); return 0.0;}}
if(pRFCERRNUMp()==0) pRSETFCERRp(1,"str");
return 0.0;
}
double rfc_endl(int m,double *x)
{pout->ReplaceSel("\r\n");
return 0.0;
}
double rfc_outarray(int m,double *x)
{char name[32];
long nowArray,i;
nowArray=(long)x[0];
ppDoubleArrayS=pGetFcDoubleArraySp(DoubleArraySMax,pDoubleArrayMax);
if(!ppDoubleArrayS||nowArray>=DoubleArraySMax||nowArray<0) {pRSETFCERRp(1,"outarray"); return 0.0;}
for(i=0;iReplaceSel(gcvt(ppDoubleArrayS[nowArray][i],16,name));
return 0.0;
}
double rfc_dllfile(int m,double *x)
{pDllFunFile=pHead_DllFunFile;
while(pDllFunFile->endDllFunFile)
{pDllFunFile=pDllFunFile->endDllFunFile;
pout->ReplaceSel("\r\n*****动态库说明文件:");
pout->ReplaceSel(pDllFunFile->DllFunFilename);
pout->ReplaceSel("\r\n");
pDllFunFile->pDllFunChar=&(pDllFunFile->head_DllFunChar);
while(pDllFunFile->pDllFunChar->endDllFunChar)
{pDllFunFile->pDllFunChar=pDllFunFile->pDllFunChar->endDllFunChar;
pout->ReplaceSel("**函数:");
pout->ReplaceSel(pDllFunFile->pDllFunChar->pstrname);
pout->ReplaceSel("\r\n");
pout->ReplaceSel("**函数说明:\r\n");
pout->ReplaceSel(pDllFunFile->pDllFunChar->pstr);
}
}
return 0.0;
}
///////////////////////////////
void COpenFCtestDlg::Onset()
{char *pstr;
int k;
// TODO: Add your control notification handler code here
this->UpdateData(true);
k=m_loaddllname.GetWindowTextLength()+1;
pstr=new char[k];
if(pstr)
{m_loaddllname.GetWindowText(pstr,k);
pSetOpenFcSetp(m_filemax,m_intmax,m_realmax,m_complexmax,m_stringmax,pstr);
pGetFcStrp(fc_str,fc_strmax,fc_strsmax);
delete[] pstr;
}
pGetOpenFcSetp(m_filemax,m_intmax,m_realmax,m_complexmax,m_stringmax,pdllname,pdllfile);
m_loaddllname.SetSel(0,-1); m_loaddllname.ReplaceSel(pdllname);
m_filename.SetSel(0,-1); m_filename.ReplaceSel(pdllfile);
this->UpdateData(false);
}
void COpenFCtestDlg::Onloadfile()
{char *pstr;
int k;
// TODO: Add your control notification handler code here
this->UpdateData(true);
k=m_filename.GetWindowTextLength()+1;
pstr=new char[k];
if(pstr)
{m_filename.GetWindowText(pstr,k);
pLoadDllFunFilep(pstr);
delete[] pstr;
}
}
BOOL COpenFCtestDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
if(OpenForcalDll)
{pFreeDllp();
FreeLibrary(OpenForcalDll);
}
return CDialog::DestroyWindow();
}
void COpenFCtestDlg::Oncom()
{
// TODO: Add your control notification handler code here
CString textstr;
int n;
char *err_str="",ch[32];
m_text.GetWindowText(textstr);
if(OpenForcalDll)
{n=pComForp((char *)(LPCTSTR)textstr,err_str,outl,outd,outc,DllMessage);
if(n)
{m_out.ReplaceSel(err_str);
m_out.ReplaceSel("\r\n编译错误代码:");
m_out.ReplaceSel(itoa(n,ch,10));
}
}
}
void COpenFCtestDlg::Onrun()
{
// TODO: Add your control notification handler code here
pExeForp(0,-1,2);
}