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

📄 ccompile.cpp

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

#include "stdafx.h"
#include "CCompile.h"
#include "Extended.h"

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

    HMODULE	cm_hDllHandle=NULL;

    cm_Handle (_stdcall *cm_CreateTCompile)()=NULL;
    bool      (_stdcall *cm_CloseTCmHandle)(cm_Handle hcm)=NULL;
    void      (_stdcall *cm_GetFunctionValue)(cm_Handle hcm,Extended* PList,Extended* PResult)=NULL;
    void      (_stdcall *cm_GetValue)(cm_Handle hcm ,Extended* PResult)=NULL;
    void      (_stdcall *cm_SetFunctionParameter)(cm_Handle hcm,Extended* PList)=NULL;
    bool      (_stdcall *cm_SetText)(cm_Handle hcm,LPCSTR TextValue,LPCSTR ParameterList,bool IfCompile)=NULL;
    bool      (_stdcall *cm_Compile)(cm_Handle hcm)=NULL;
    bool      (_stdcall *cm_IfHaveUnDefineParameter)(cm_Handle hcm)=NULL;
    bool      (_stdcall *cm_SetExteriorParameter)(cm_Handle hcm,LPCSTR PName,Extended* PAddress)=NULL;
    bool      (_stdcall *cm_SetExteriorArrayParameter)(cm_Handle hcm,LPCSTR ArrayPName,Extended* ArrayPAddress)=NULL;
    void      (_stdcall *cm_RefreshExeAddressCodeInPointer)(cm_Handle hcm)=NULL;
    bool      (_stdcall *cm_Define)(cm_Handle hcm,LPCSTR Key,LPCSTR Value)=NULL;
    bool      (_stdcall *cm_DefineConst)(cm_Handle hcm,LPCSTR Key,LPCSTR Value)=NULL;
    Extended* (_stdcall *cm_GetParameterAddress)(cm_Handle hcm,LPCSTR PName)=NULL;
    bool      (_stdcall *cm_SetParameterN)(cm_Handle hcm,LPCSTR PName,Extended dValue)=NULL;
    void      (_stdcall *cm_SetParameterA)(cm_Handle hcm,Extended* PAddress,Extended dValue)=NULL;
    void      (_stdcall *cm_GetParameterValue)(cm_Handle hcm,LPCSTR PName,Extended* PResult)=NULL;
    DWORD     (_stdcall *cm_GetUserParameterCount)(cm_Handle hcm)=NULL;
    void      (_stdcall *cm_GetUserParameterList)(cm_Handle hcm,cm_TUserParameterList* PList)=NULL;
    bool      (_stdcall *cm_IfHaveParameter)(cm_Handle hcm,LPCSTR PName)=NULL;
    void      (_stdcall *cm_SetRandomizeT)(cm_Handle hcm)=NULL;
    void      (_stdcall *cm_SetRandomizeI)(cm_Handle hcm,int RandomSeed)=NULL;

    void      (_stdcall *cm_SetEnabledNote)(cm_Handle hcm,bool  Value)=NULL;
    void      (_stdcall *cm_SetEnabledOptimizeDiv)(cm_Handle hcm,bool  Value)=NULL;
    void      (_stdcall *cm_SetEnabledOptimizeStack)(cm_Handle hcm,bool  Value)=NULL;
    void      (_stdcall *cm_SetEnabledOptimizeConst)(cm_Handle hcm,bool  Value) =NULL;
    double    (_stdcall *cm_GetVersion)() =NULL;
    int       (_stdcall *cm_GetErrorCode)(cm_Handle hcm)=NULL;
    int       (_stdcall *cm_GetExeCodeLength)(cm_Handle hcm) =NULL;
    int       (_stdcall *cm_GetExeParameterLength)(cm_Handle hcm)=NULL;

    void      (_stdcall *cm_ExtendedToStr)(Extended* x,LPCSTR strBuffer,int nBufLen)=NULL;
    void      (_stdcall *cm_StrToExtended)(LPCSTR strValue,Extended* x)=NULL;
    //void      (_stdcall *cmcx_ComplexToStr)(ComplexEx* x , LPCSTR strBuffer,int nBufLen)=NULL;
    //bool      (_stdcall *cmcx_StrToComplex)(LPCSTR strValue ,ComplexEx* x )=NULL;


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

bool CCompile::LoadCompileDll()
{
	if (cm_hDllHandle!=NULL)
	{
		return true;
	}
	else
	{
		cm_hDllHandle=::LoadLibrary(cm_DllName);
		if (cm_hDllHandle==NULL)
		{
			return false;
		}
		else
		{
			*(DWORD*)(&cm_CreateTCompile)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_CreateTCompile");
			*(DWORD*)(&cm_CloseTCmHandle)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_CloseTCmHandle");
			*(DWORD*)(&cm_GetFunctionValue)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_GetFunctionValue");
			*(DWORD*)(&cm_GetValue)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_GetValue");
			*(DWORD*)(&cm_SetText)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_SetText");
			*(DWORD*)(&cm_SetFunctionParameter)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_SetFunctionParameter");
			*(DWORD*)(&cm_Compile)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_Compile");
			*(DWORD*)(&cm_IfHaveUnDefineParameter)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_IfHaveUnDefineParameter");
			*(DWORD*)(&cm_SetExteriorParameter)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_SetExteriorParameter");
			*(DWORD*)(&cm_SetExteriorArrayParameter)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_SetExteriorArrayParameter");
			*(DWORD*)(&cm_RefreshExeAddressCodeInPointer)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_RefreshExeAddressCodeInPointer");
			*(DWORD*)(&cm_Define)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_Define");
			*(DWORD*)(&cm_DefineConst)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_DefineConst");
			*(DWORD*)(&cm_GetParameterAddress)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_GetParameterAddress");
			*(DWORD*)(&cm_SetParameterN)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_SetParameterN");
			*(DWORD*)(&cm_SetParameterA)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_SetParameterA");
			*(DWORD*)(&cm_GetParameterValue)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_GetParameterValue");
			*(DWORD*)(&cm_GetUserParameterCount)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_GetUserParameterCount");
			*(DWORD*)(&cm_GetUserParameterList)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_GetUserParameterList");
			*(DWORD*)(&cm_IfHaveParameter)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_IfHaveParameter");
			*(DWORD*)(&cm_SetRandomizeT)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_SetRandomizeT");
			*(DWORD*)(&cm_SetRandomizeI)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_SetRandomizeI");

			*(DWORD*)(&cm_SetEnabledNote)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_SetEnabledNote");
			*(DWORD*)(&cm_SetEnabledOptimizeDiv)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_SetEnabledOptimizeDiv");
			*(DWORD*)(&cm_SetEnabledOptimizeStack)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_SetEnabledOptimizeStack");
			*(DWORD*)(&cm_SetEnabledOptimizeConst)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_SetEnabledOptimizeConst");
			*(DWORD*)(&cm_GetVersion)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_GetVersion");
			*(DWORD*)(&cm_GetErrorCode)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_GetErrorCode");
			*(DWORD*)(&cm_GetExeCodeLength)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_GetExeCodeLength");
			*(DWORD*)(&cm_GetExeParameterLength)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_GetExeParameterLength");

			*(DWORD*)(&cm_ExtendedToStr)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_ExtendedToStr");
			*(DWORD*)(&cm_StrToExtended)=(DWORD)::GetProcAddress(cm_hDllHandle,"cm_StrToExtended");
			//*(DWORD*)(&cmcx_ComplexToStr)=(DWORD)::GetProcAddress(cm_hDllHandle,"cmcx_ComplexToStr");
			//*(DWORD*)(&cmcx_StrToComplex)=(DWORD)::GetProcAddress(cm_hDllHandle,"cmcx_StrToComplex");

			return true;
		}
	}
}

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

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

CCompile::CCompile()
{
    if (LoadCompileDll())
        this->m_cmHandle=cm_CreateTCompile();
    else
        this->m_cmHandle=NULL;
}

CCompile::~CCompile()
{
    if (this->m_cmHandle!=NULL)
	    cm_CloseTCmHandle(this->m_cmHandle);
}

Extended  CCompile::GetFunctionValue(Extended* PList)
{
  Extended result;
  cm_GetFunctionValue(this->m_cmHandle,PList,&result);
  return result; 
}

Extended  CCompile::GetValue()
{
  Extended result;
  cm_GetValue(this->m_cmHandle,&result);
  return result;
}
void CCompile::GetValue(Extended* Result)
{
  cm_GetValue(this->m_cmHandle,Result);
}

void      CCompile::SetFunctionParameter(Extended* PList)
{
  cm_SetFunctionParameter(this->m_cmHandle,PList);
}

bool      CCompile::SetText(LPCSTR TextValue,LPCSTR ParameterList,bool IfCompile)
{
  return  cm_SetText(this->m_cmHandle,TextValue,ParameterList,IfCompile);
}

bool      CCompile::Compile()
{
  return  cm_Compile(this->m_cmHandle);
}

bool      CCompile::IfHaveUnDefineParameter()
{
  return  cm_IfHaveUnDefineParameter(this->m_cmHandle);
}

bool      CCompile::SetExteriorParameter(LPCSTR PName,Extended* PAddress)
{
  return  cm_SetExteriorParameter(this->m_cmHandle,PName,PAddress);
}

bool      CCompile::SetExteriorArrayParameter(LPCSTR ArrayPName,Extended* ArrayPAddress)
{
  return  cm_SetExteriorArrayParameter(this->m_cmHandle,ArrayPName,ArrayPAddress);
}

void      CCompile::RefreshExeAddressCodeInPointer()
{
  cm_RefreshExeAddressCodeInPointer(this->m_cmHandle);
}

bool      CCompile::Define(LPCSTR Key,LPCSTR Value)
{
  return  cm_Define(this->m_cmHandle,Key,Value);
}

bool      CCompile::DefineConst(LPCSTR Key,LPCSTR Value)
{
  return  cm_DefineConst(this->m_cmHandle,Key,Value);
}
Extended* CCompile::GetParameterAddress(LPCSTR PName)
{
  return  cm_GetParameterAddress(this->m_cmHandle,PName);
}

bool      CCompile::SetParameter(LPCSTR PName,const Extended& dValue)
{
  return  cm_SetParameterN(this->m_cmHandle,PName,dValue);
}

void      CCompile::SetParameter(Extended* PAddress,const Extended& dValue)
{
  //cm_SetParameterA(this->m_cmHandle,PAddress,dValue);
  *PAddress=dValue;
}

Extended  CCompile::GetParameterValue(LPCSTR PName)
{
  Extended result;
  cm_GetParameterValue(this->m_cmHandle,PName,&result);
  return result;
}

DWORD     CCompile::GetUserParameterCount()
{
  return  cm_GetUserParameterCount(this->m_cmHandle);
}
void      CCompile::GetUserParameterList(cm_TUserParameterList* PList)
{
  cm_GetUserParameterList(this->m_cmHandle,PList);
}

bool      CCompile::IfHaveParameter(LPCSTR PName)
{
  return  cm_IfHaveParameter(this->m_cmHandle,PName);
}
void      CCompile::SetRandomize()
{
  cm_SetRandomizeT(this->m_cmHandle);
}

void      CCompile::SetRandomize(int RandomSeed)
{
  cm_SetRandomizeI(this->m_cmHandle,RandomSeed);
}

void      CCompile::SetEnabledNote(bool  Value)
{
  cm_SetEnabledNote(this->m_cmHandle,Value);
}

void      CCompile::SetEnabledOptimizeDiv(bool  Value)
{
  cm_SetEnabledOptimizeDiv(this->m_cmHandle,Value);
}
void      CCompile::SetEnabledOptimizeStack(bool  Value)
{
  cm_SetEnabledOptimizeStack(this->m_cmHandle,Value);
}
void      CCompile::SetEnabledOptimizeConst(bool  Value)
{
  cm_SetEnabledOptimizeConst(this->m_cmHandle,Value);
}
double  CCompile::GetVersion()
{
    return cm_GetVersion();
}
int       CCompile::GetErrorCode()
{
    return cm_GetErrorCode(this->m_cmHandle);
}
int       CCompile::GetExeCodeLength()
{
    return cm_GetExeCodeLength(this->m_cmHandle);
}
int       CCompile::GetExeParameterLength()
{
    return cm_GetExeParameterLength(this->m_cmHandle);
}

⌨️ 快捷键说明

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