| MATLAB Compiler | ![]() |
Library Initialization and Termination Functions
The library initialization and termination functions create and destroy, respectively, the MCR instance required by the shared library. You must call the initialization function before you invoke any of the other functions in the shared library, and you should call the termination function after you are finished making calls into the shared library (or you risk leaking memory).
There are two forms of the initialization function and one type of termination function. The simpler of the two initialization functions takes no arguments; most likely this is the version your application will call. In this example, this form of the initialization function is called libtriangleInitialize.
This function creates an MCR instance using the default print and error handlers, and other information generated during the compilation process.
However, if you want more control over how printed output and error messages are handled, you may call the second form of the function, which takes two arguments.
bool libtriangleInitializeWithHandlers( mclOutputHandlerFcn error_handler, mclOutputHandlerFcn print_handler )
By calling this function, you can provide your own versions of the print and error handling routines called by the MCR. Each of these routines has the same signature (for complete details, see Print and Error Handling Functions). By overriding the defaults, you can control how output is displayed and, for example, whether or not it goes into a log file.
Note
Before calling either form of the library initialization routine, you must first call mclInitializeApplication to set up the global MCR state. See Calling a Shared Library for more information.
|
On Microsoft Windows platforms, the Compiler generates an additional initialization function, the standard Microsoft DLL initialization function DllMain.
The generated DllMain performs a very important service; it locates the directory in which the shared library is stored on disk. This information is used to find the CTF archive, without which the application will not run. If you modify the generated DllMain (which we do not recommend you do), make sure you preserve this part of its functionality.
Library termination is simple.
Call this function (once for each library) before calling mclTerminateApplication.
| Structure of Programs That Call Shared Libraries | Print and Error Handling Functions | ![]() |
© 1994-2005 The MathWorks, Inc.