FormulaCalculatorLib usage in C/C++
FormulaCalculatorLib.dll is a library with 5 exported functions:
| Function name |
No. |
| FormulaCalculatorLib_SetFormula |
1 |
| FormulaCalculatorLib_Calculate |
2 |
| FormulaCalculatorLib_Reset |
3 |
| FormulaCalculatorLib_AddStatement |
4 |
| FormulaCalculatorLib_AddArgument |
5 |
You may call the functions from your C/C++ program in two ways:
1. Run-time dynamic linking:
- Load "FormulaCalculatorLib.dll" library using LoadLibrary Windows API function.
- Get function address by name or number using GetProcAddress Windows API function
- Call the function.
For example...
typedef BOOL (__stdcall* funct_1)(char* formula);
typedef BOOL (__stdcall* funct_2)();
typedef BOOL (__stdcall* funct_3)(long* num);
typedef BOOL (__stdcall* funct_4)(long num,char* arg1,char* arg2,char* oper,char* funct,char* res);
typedef BOOL (__stdcall* funct_5)(double* double_res,char* arg_list);
typedef BOOL (__stdcall* funct_6)(char* arg1,char* arg2,char* oper,char* funct,char* res);
typedef BOOL (__stdcall* funct_7)(char* name,char* str_val);
funct_1 FC_SetFormula;
funct_5 FC_Calculate;
funct_2 FC_Reset;
funct_6 FC_AddStatement;
funct_7 FC_AddArgument;
HMODULE hFormulaParser;
HMODULE hFormulaCalculator;
//somewhere in creation
if(!(hFormulaCalculator=LoadLibrary("FormulaCalculatorLib.dll")))
{
MessageBox("Cannot load FormulaCalculatorLib.dll","Error");
return;
}
FC_SetFormula=(funct_1)GetProcAddress(hFormulaCalculator,"FormulaCalculatorLib_SetFormula");
FC_Calculate=(funct_5)GetProcAddress(hFormulaCalculator,"FormulaCalculatorLib_Calculate");
FC_Reset=(funct_2)GetProcAddress(hFormulaCalculator,"FormulaCalculatorLib_Reset");
FC_AddStatement=(funct_6)GetProcAddress(hFormulaCalculator,"FormulaCalculatorLib_AddStatement");
FC_AddArgument=(funct_7)GetProcAddress(hFormulaCalculator,"FormulaCalculatorLib_AddArgument");
//somewhere in destruction
if(hFormulaCalculator)
FreeLibrary(hFormulaCalculator);
//use the functions
if(!FC_SetFormula(formula_str.GetBuffer(1000)))
{
MessageBox("Cannot set formula","Error");
return false;
}
if(!FC_Calculate(&m_dResult,arg_str))
{
MessageBox("Cannot calculate formula",Error");
return false;
}
See VCTest_RunTime project source code
2. Load-time dynamicLinking:
- Add "FormulaCalculatorLib.lib" to the Link settings of your project. You must build the your project with the file.
- Include "FormulaCalculatorLib.h" header file in your implementation files where
you are using functions from the library.
See VCTest_LoadTime project source code.
FormulaCalculatorLib usage in VisualBasic
www.maxdz.com