David Meeker
October 25, 2004
One way of tapping into the functionality of FEMM from an external program is to communicate with FEMM via ActiveX. Using ActiveX, external programs can send FEMM strings to be processed by its internal Lua parser. A string returned to the calling program which contains results, error messages, etc.
This note describes an example program that uses ActiveX to talk to FEMM. FEMM runs as an out-of-process ActiveX server. The example program connects to the FEMM server as a client. The source from the example program is available here.
The following steps allow you to connect to the FEMM ActiveX server in MSVC++ 6.
The above steps were used to build ActiveX support into the xclient example considered in this note.
Example Program xclient
The xclient example is a dialog-based application that acts as an ActiveX client talking to the FEMM out-of-process ActiveX server. The program takes a line of input in one edit box in the dialog. When <RETURN> is pressed, the application sends the contents of the input edit box to the call2femm() function. The Lua scripting language embedded in FEMM parses the input, and the results are returned in a string with each results separated by a \n character.
The results returned by FEMM are then reported in the read-only edit box, also on the dialog. In other applications, one might want to obtain numerical values from the results, rather than simply printing the results. Typically, the number of results expected from the call is known, so that sscanf could be employed to most easily parse the results. For example, if four results were expected from FEMM, the line that took the four resulting numerical values and put them into the previously defined doubles x1 through x4 would be:
sscanf(u,"%lf\n%lf\n%lf\n%lf",&x1,&x2,&x3,&x4);
It is, of course, possible that commands sent to FEMM could result in an error. If this is the case, the FEMM error message will be returned from the call2femm function. All error messages start with the word error, with the text describing the error following.
Communicating with FEMM as an ActiveX client is actually fairly straightforward. Hopefully, this simple example has given you the knowledge necessary to access the FEMM ActiveX server from your programs.