⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccompilecomplex.cpp

📁 编译类_Hss VC版_源代码支持表达式的编译执行,速度超快,支持实数和复数,并附带一个复数函数库你还可以同时找到VB和VC版和Delphi版
💻 CPP
字号:
// CCompileComplex.cpp: implementation of the CCompileComplex class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "CCompileComplex.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

    HMODULE	cmcx_hDllHandle=NULL;

    cmcx_Handle (_stdcall *cmcx_CreateTCompileComplex)()=NULL;
    bool      (_stdcall *cmcx_CloseTCmcxHandle)(cmcx_Handle hcmcx)=NULL;
    void      (_stdcall *cmcx_GetFunctionValue)(cmcx_Handle hcmcx,TComplex* PList,TComplex* PResult)=NULL;
    void      (_stdcall *cmcx_GetValue)(cmcx_Handle hcmcx ,TComplex* PResult)=NULL;
    void      (_stdcall *cmcx_SetFunctionParameter)(cmcx_Handle hcmcx,TComplex* PList)=NULL;
    bool      (_stdcall *cmcx_SetText)(cmcx_Handle hcmcx,LPCSTR TextValue,LPCSTR ParameterList,bool IfCompile)=NULL;
    bool      (_stdcall *cmcx_Compile)(cmcx_Handle hcmcx)=NULL;
    bool      (_stdcall *cmcx_IfHaveUnDefineParameter)(cmcx_Handle hcmcx)=NULL;
    bool      (_stdcall *cmcx_SetExteriorParameter)(cmcx_Handle hcmcx,LPCSTR PName,TComplex* PAddress)=NULL;
    bool      (_stdcall *cmcx_SetExteriorArrayParameter)(cmcx_Handle hcmcx,LPCSTR ArrayPName,TComplex* ArrayPAddress)=NULL;
    void      (_stdcall *cmcx_RefreshExeAddressCodeInPointer)(cmcx_Handle hcmcx)=NULL;
    bool      (_stdcall *cmcx_Define)(cmcx_Handle hcmcx,LPCSTR Key,LPCSTR Value)=NULL;
    bool      (_stdcall *cmcx_DefineConst)(cmcx_Handle hcmcx,LPCSTR Key,LPCSTR Value)=NULL;
    TComplex* (_stdcall *cmcx_GetParameterAddress)(cmcx_Handle hcmcx,LPCSTR PName)=NULL;
    bool      (_stdcall *cmcx_SetParameterN)(cmcx_Handle hcmcx,LPCSTR PName,TComplex dValue)=NULL;
    void      (_stdcall *cmcx_SetParameterA)(cmcx_Handle hcmcx,TComplex* PAddress,TComplex dValue)=NULL;
    void      (_stdcall *cmcx_GetParameterValue)(cmcx_Handle hcmcx,LPCSTR PName,TComplex* PResult)=NULL;
    DWORD     (_stdcall *cmcx_GetUserParameterCount)(cmcx_Handle hcmcx)=NULL;
    void      (_stdcall *cmcx_GetUserParameterList)(cmcx_Handle hcmcx,cmcx_TUserParameterList* PList)=NULL;
    bool      (_stdcall *cmcx_IfHaveParameter)(cmcx_Handle hcmcx,LPCSTR PName)=NULL;
    void      (_stdcall *cmcx_SetRandomizeT)(cmcx_Handle hcmcx)=NULL;
    void      (_stdcall *cmcx_SetRandomizeI)(cmcx_Handle hcmcx,int RandomSeed)=NULL;

    void      (_stdcall *cmcx_SetEnabledNote)(cmcx_Handle hcmcx,bool  Value)=NULL;
    void      (_stdcall *cmcx_SetEnabledOptimizeDiv)(cmcx_Handle hcmcx,bool  Value)=NULL;
    void      (_stdcall *cmcx_SetEnabledOptimizeStack)(cmcx_Handle hcmcx,bool  Value)=NULL;
    void      (_stdcall *cmcx_SetEnabledOptimizeConst)(cmcx_Handle hcmcx,bool  Value) =NULL;
    double    (_stdcall *cmcx_GetVersion)() =NULL;
    int       (_stdcall *cmcx_GetErrorCode)(cmcx_Handle hcmcx)=NULL;
    int       (_stdcall *cmcx_GetExeCodeLength)(cmcx_Handle hcmcx) =NULL;
    int       (_stdcall *cmcx_GetExeParameterLength)(cmcx_Handle hcmcx)=NULL;

    void      (_stdcall *cmcx_ExtendedToStr)(Extended* x,LPCSTR strBuffer,int nBufLen)=NULL;
    void      (_stdcall *cmcx_StrToExtended)(LPCSTR strValue,Extended* x)=NULL;
    void      (_stdcall *cmcx_ComplexToStr)(TComplex* x , LPCSTR strBuffer,int nBufLen)=NULL;
    bool      (_stdcall *cmcx_StrToComplex)(LPCSTR strValue ,TComplex* x )=NULL;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

 
bool CCompileComplex::LoadCompileDll()
{
	if (cmcx_hDllHandle!=NULL)
	{
		return true;
	}
	else
	{
		cmcx_hDllHandle=::LoadLibrary(cmcx_DllName);
		if (cmcx_hDllHandle==NULL)
		{
			return false;
		}
		else
		{
			*(DWORD*)(&cmcx_CreateTCompileComplex)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_CreateTCompileComplex");
			*(DWORD*)(&cmcx_CloseTCmcxHandle)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_CloseTCmcxHandle");
			*(DWORD*)(&cmcx_GetFunctionValue)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_GetFunctionValue");
			*(DWORD*)(&cmcx_GetValue)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_GetValue");
			*(DWORD*)(&cmcx_SetText)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_SetText");
			*(DWORD*)(&cmcx_SetFunctionParameter)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_SetFunctionParameter");
			*(DWORD*)(&cmcx_Compile)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_Compile");
			*(DWORD*)(&cmcx_IfHaveUnDefineParameter)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_IfHaveUnDefineParameter");
			*(DWORD*)(&cmcx_SetExteriorParameter)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_SetExteriorParameter");
			*(DWORD*)(&cmcx_SetExteriorArrayParameter)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_SetExteriorArrayParameter");
			*(DWORD*)(&cmcx_RefreshExeAddressCodeInPointer)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_RefreshExeAddressCodeInPointer");
			*(DWORD*)(&cmcx_Define)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_Define");
			*(DWORD*)(&cmcx_DefineConst)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_DefineConst");
			*(DWORD*)(&cmcx_GetParameterAddress)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_GetParameterAddress");
			*(DWORD*)(&cmcx_SetParameterN)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_SetParameterN");
			*(DWORD*)(&cmcx_SetParameterA)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_SetParameterA");
			*(DWORD*)(&cmcx_GetParameterValue)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_GetParameterValue");
			*(DWORD*)(&cmcx_GetUserParameterCount)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_GetUserParameterCount");
			*(DWORD*)(&cmcx_GetUserParameterList)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_GetUserParameterList");
			*(DWORD*)(&cmcx_IfHaveParameter)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_IfHaveParameter");
			*(DWORD*)(&cmcx_SetRandomizeT)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_SetRandomizeT");
			*(DWORD*)(&cmcx_SetRandomizeI)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_SetRandomizeI");

			*(DWORD*)(&cmcx_SetEnabledNote)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_SetEnabledNote");
			*(DWORD*)(&cmcx_SetEnabledOptimizeDiv)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_SetEnabledOptimizeDiv");
			*(DWORD*)(&cmcx_SetEnabledOptimizeStack)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_SetEnabledOptimizeStack");
			*(DWORD*)(&cmcx_SetEnabledOptimizeConst)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_SetEnabledOptimizeConst");
			*(DWORD*)(&cmcx_GetVersion)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_GetVersion");
			*(DWORD*)(&cmcx_GetErrorCode)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_GetErrorCode");
			*(DWORD*)(&cmcx_GetExeCodeLength)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_GetExeCodeLength");
			*(DWORD*)(&cmcx_GetExeParameterLength)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_GetExeParameterLength");

			*(DWORD*)(&cmcx_ExtendedToStr)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cm_ExtendedToStr");
			*(DWORD*)(&cmcx_StrToExtended)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cm_StrToExtended");
			*(DWORD*)(&cmcx_ComplexToStr)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_ComplexToStr");
			*(DWORD*)(&cmcx_StrToComplex)=(DWORD)::GetProcAddress(cmcx_hDllHandle,"cmcx_StrToComplex");

			return true;
		}
	}
}

CString		CCompileComplex::ExtendedToStr	(const  Extended & x)
{
	CString rs;
	if (LoadCompileDll())
	{
		rs.GetBufferSetLength(30);
		Extended temp(x);
		cmcx_ExtendedToStr(&temp,rs,30);
		rs.ReleaseBuffer();
	}
	else
	{
		rs.Format("%f",double(x));	
	}
	return rs;
}

Extended	CCompileComplex::StrToExtended	(LPCSTR s)
{
	Extended rs(0);
	if (LoadCompileDll())
	{
		cmcx_StrToExtended(s,&rs);
	}
	else
	{
		rs=::atof(s);
	}
	return rs;
}

CString		CCompileComplex::TComplexToStr	(const  TComplex & x)
{
	CString rs;
	if (LoadCompileDll())
	{
		rs.GetBufferSetLength(60);
		TComplex temp(x);
		cmcx_ComplexToStr(&temp,rs,60);
		rs.ReleaseBuffer();
	}
	else
	{
		rs.Format("%f",double(x));	
		CString im;
		
		double dx=x.imag();
		im.Format("%f",fabs(dx));
		if (dx<0.0)
		{
			rs=rs+"-"+im+"*i";
		}
		else if (dx>0.0)
		{
			rs=rs+"+"+im+"*i";
		}
	}
	return rs;
}

bool		CCompileComplex::StrToTComplex	(LPCSTR s,TComplex * x)
{
	if (LoadCompileDll())
	{
		return cmcx_StrToComplex(s,x);
	}
	else
	{
		return false;
	}
}

CCompileComplex::CCompileComplex()
{
	if (LoadCompileDll())
	  this->m_cmcxHandle=cmcx_CreateTCompileComplex();
  else
    this->m_cmcxHandle=NULL;
}

CCompileComplex::~CCompileComplex()
{
  if (this->m_cmcxHandle!=NULL)
	  cmcx_CloseTCmcxHandle(this->m_cmcxHandle);
}

TComplex  CCompileComplex::GetFunctionValue(TComplex* PList)
{
  TComplex result;
  cmcx_GetFunctionValue(this->m_cmcxHandle,PList,&result);
  return result; 
}

TComplex  CCompileComplex::GetValue()
{
  TComplex result;
  cmcx_GetValue(this->m_cmcxHandle,&result);
  return result;
}
void  CCompileComplex::GetValue(TComplex* Result)
{
  cmcx_GetValue(this->m_cmcxHandle,Result);
}

void  CCompileComplex::SetFunctionParameter(TComplex* PList)
{
  cmcx_SetFunctionParameter(this->m_cmcxHandle,PList);
}

bool  CCompileComplex::SetText(LPCSTR TextValue,LPCSTR ParameterList,bool IfCompile)
{
  return  cmcx_SetText(this->m_cmcxHandle,TextValue,ParameterList,IfCompile);
}

bool  CCompileComplex::Compile()
{
  return  cmcx_Compile(this->m_cmcxHandle);
}

bool  CCompileComplex::IfHaveUnDefineParameter()
{
  return  cmcx_IfHaveUnDefineParameter(this->m_cmcxHandle);
}

bool   CCompileComplex::SetExteriorParameter(LPCSTR PName,TComplex* PAddress)
{
  return  cmcx_SetExteriorParameter(this->m_cmcxHandle,PName,PAddress);
}

bool  CCompileComplex::SetExteriorArrayParameter(LPCSTR ArrayPName,TComplex* ArrayPAddress)
{
  return  cmcx_SetExteriorArrayParameter(this->m_cmcxHandle,ArrayPName,ArrayPAddress);
}

void   CCompileComplex::RefreshExeAddressCodeInPointer()
{
  cmcx_RefreshExeAddressCodeInPointer(this->m_cmcxHandle);
}

bool   CCompileComplex::Define(LPCSTR Key,LPCSTR Value)
{
  return  cmcx_Define(this->m_cmcxHandle,Key,Value);
}

bool    CCompileComplex::DefineConst(LPCSTR Key,LPCSTR Value)
{
  return  cmcx_DefineConst(this->m_cmcxHandle,Key,Value);
}
TComplex* CCompileComplex::GetParameterAddress(LPCSTR PName)
{
  return  cmcx_GetParameterAddress(this->m_cmcxHandle,PName);
}

bool   CCompileComplex::SetParameter(LPCSTR PName,const TComplex& dValue)
{
  return  cmcx_SetParameterN(this->m_cmcxHandle,PName,dValue);
}

void   CCompileComplex::SetParameter(TComplex* PAddress,const TComplex& dValue)
{
  //cmcx_SetParameterA(this->m_cmcxHandle,PAddress,dValue);
  *PAddress=dValue;
}

TComplex  CCompileComplex::GetParameterValue(LPCSTR PName)
{
  TComplex result;
  cmcx_GetParameterValue(this->m_cmcxHandle,PName,&result);
  return result; 
}

DWORD   CCompileComplex::GetUserParameterCount()
{
  return  cmcx_GetUserParameterCount(this->m_cmcxHandle);
}
void  CCompileComplex::GetUserParameterList(cmcx_TUserParameterList* PList)
{
  cmcx_GetUserParameterList(this->m_cmcxHandle,PList);
}

bool   CCompileComplex::IfHaveParameter(LPCSTR PName)
{
  return  cmcx_IfHaveParameter(this->m_cmcxHandle,PName);
}
void      CCompileComplex::SetRandomize()
{
  cmcx_SetRandomizeT(this->m_cmcxHandle);
}

void      CCompileComplex::SetRandomize(int RandomSeed)
{
  cmcx_SetRandomizeI(this->m_cmcxHandle,RandomSeed);
}

void      CCompileComplex::SetEnabledNote(bool  Value)
{
  cmcx_SetEnabledNote(this->m_cmcxHandle,Value);
}

void      CCompileComplex::SetEnabledOptimizeDiv(bool  Value)
{
  cmcx_SetEnabledOptimizeDiv(this->m_cmcxHandle,Value);
}
void      CCompileComplex::SetEnabledOptimizeStack(bool  Value)
{
  cmcx_SetEnabledOptimizeStack(this->m_cmcxHandle,Value);
}
void      CCompileComplex::SetEnabledOptimizeConst(bool  Value)
{
  cmcx_SetEnabledOptimizeConst(this->m_cmcxHandle,Value);
}
double  CCompileComplex::GetVersion()
{
    return cmcx_GetVersion();
}
int       CCompileComplex::GetErrorCode()
{
    return cmcx_GetErrorCode(this->m_cmcxHandle);
}
int       CCompileComplex::GetExeCodeLength()
{
    return cmcx_GetExeCodeLength(this->m_cmcxHandle);
}
int       CCompileComplex::GetExeParameterLength()
{
    return cmcx_GetExeParameterLength(this->m_cmcxHandle);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -