Visual C++

Borland C++ Builder

 

Adding uCalc to your C++ application

 

uCalc Fast Math Parser includes direct support for Visual C++, and Borland C++ Builder.  To implement uCalc FMP with C++, use the following steps:

 

  1. Copy uCalcCPP.h and uCalcCPP.cpp to your project directory, or an appropriate include directory.
  2. Place ucFMP296.dll and uCalc296.dll either in the Windows directory, your application directory, or an appropriate directory in the path.
  3. In your application code, place the following line with the other include statements at the beginning:

#include "uCalcCPP.cpp"

 

Now you're all set to go.

 

Note: Visual C++ files are found in the ucFMP296\VC\ directory, while Borland C++ Builder files are found in ucFMP296\BCB\.

 

 

Console programs in VC++

 

In addition to the steps mentioned above, if you want to create a console program in Visual C++ that uses uCalc, then from the menu go to File / New / Projects  and select Win32 Console Application.  After choosing the location for your project directory, select a name for the project and click OK.  Then select the option that says:  An application that supports MFC.  uCalc routines that return a string will need to be preceded by (LPCTSTR) when used with cout.  For example:

 

printf(ucEvalStr("3*5"));

cout << endl;

cout << ucEval("1+3") << endl;

cout << (LPCTSTR)ucEvalStr("6*3") << endl;

 

If you have already created a console program in VC++ and it does not use MFC, you will need to add MFC for it to work.   To do this, select this from the menu: Project / Settings / General.  Then under Microsoft Foundation Classes choose: Use MFC in a Shared DLL.  Your include section will need to look something like this (where afx.h is added after stdafx.h if it wasn't already there; and iostream is added if you want to use cout):

 

#include "stdafx.h"

#include "afx.h"

#include <iostream>

#include "uCalcCPP.cpp"

 

using namespace std;

 

 

Unicode in VC++

 

By default uCalc is configured to compile in Multi-byte mode.  If you need to compile your VC++ program with the Unicode setting, then add the following line either at that top of uCalcCPP.cpp, or on a line that comes before the #include statement for uCalcCPP.cpp:

 

#define uc_Unicode

 

 

Demo program

 

Separate form-based demos are included for Visual C++, and for Borland C++ Builder.  The source code in these files demonstrates the essential features, especially as they relate to C++.  The uCalc demo project file that you should load into Visual C++ is named DemoVC.dsw.  Actual uCalc-related code that you should browse through is found in DemoVCDlg.cpp.  For Borland C++ Builder, the project file to load is DemoBCB.dpr, and the actual uCalc-related code to browse through is DemoBCBf.cpp.

 

 

Data type considerations

 

There are differences between some of Borland C++ Builder's data types and Visual C++'s equivalent types that are supported by uCalc.

   String

You generally do not need to worry much about which kind of string type to use, unless you are defining callbacks without the Native declarative.  uCalc's default String type is a dynamic multi-byte string.  This corresponds with Borland C++ Builder's AnsiString, and Visual C++'s CString.  One uCalc string type that works the same in both editions of C++ for non-Native callbacks is LPCSTR.  Your callbacks can receive LPCSTR arguments as char*.

 

   long double

In Visual C++, long double is synonymous with double, which corresponds with uCalc's Double type.  However, in Borland C++ Builder, long double is not the same as double.  C++ Builder's long double type corresponds with uCalc's Extended type.

 

In VC++, arithmetic operators and trig functions, as well as ucParse and ucEvaluate operate using the Double precision type by default, whereas Borland C++ Builder uses Extended precision instead.

 

 

Standard Call convention

 

It is very important to remember to always use the _stdcall directive in your callback functions.  Or, you may configure StdCall as the default setting for your compiler.  Here are some examples:

 

DWORD _stdcall MyErrorHandler(long t) // Error handling routine

void _stdcall MyArea(DWORD Expr) // Native callback routine

long double _stdcall MyEasyCallback(double a, long& b, byte c) // Non-native callback

 

 

ucDefine() with more than one argument

 

In the uCalc header file for Visual C++ and Borland C++ Builder, ucDefine is overloaded with two slightly different routines.  If ucDefine will have more than two arguments, and the second argument is 0, then you should pass (DWORD)0, otherwise it won't compile.   So for instance in VC++ or BC++B, assuming tHandle is defined already, you should use the second line below instead of the first:

 

ucDefine("Syntax: a ::= b", 0, 0, 0, tHandle); // This line won't compile in C++

ucDefine("Syntax: a ::= b", (DWORD)0, 0, 0, tHandle); // This line will compile in C++

 

Or, depending on the uCalc header, the second argument may need to be "" (empty quotes).

 

 

Examples:

 

The following examples are for key features that may have some peculiarities in C++.  There are many more examples in Visual Basic that are general enough that a C++ counter-part was not included.  C++ Builder examples that are close enough to Visual C++ are done only in C++ Builder.

 

Visual C++

Example 1:  Simple evaluation using ucEvalStr

Example 2:  Fast evaluation millions of times in a loop

Example 3:  A native string callback function

Example 4:  A non-native callback

Example 5:  Strings in non-native functions

Example 6:  Attached variables

 

C++ Builder

Example 1:  Simple evaluation using ucEvalStr

Example 2:  Fast evaluation millions of times in a loop

Example 3:  Defining a centralized error handler

Example 4:  Raising an error with ucRaiseErrorMessage

Example 5:  A native callback function with two numeric arguments

Example 6:  A native callback function with any number of arguments

Example 7:  A native string callback function

Example 8:  A non-native callback

Example 9:  Strings in non-native functions

Example 10:  Attached variables

 

See More Examples

 

 

New or enhanced in version 2.96

 

New or enhanced in version 2.9+

 

Issues for users migrating from version 2.0