The stub extension DLL functionality allows a custom DLL to be notified at the start and end of each constructor and destructor visited in the target program.
One additional function can receive a command which may be sent to all stub extensions or a specific one.
The example extension project can be found in the stubExtDLL subdirectory in the directory where Memory Validator was installed.
If the directory is not present, reinstall your software and choose custom or full installation.
There are two project files in the directory:
•stubExtDLL.dsp for Microsoft® Developer Studio® 6.0
•stubExtDLL.vcproj for Microsoft® Visual Studio / .net
A stub extension DLL can provide all or none of the following functions. If a function isn't defined, the stub won't call it.
All of these functions return TRUE / FALSE for success or failure, but at the time of writing, the stub doesn't act on the return codes.
•startConstructor called at the start of the C++ object's constructor, before any member variables have been initialised
int startConstructor(void *thisPtr,
•finishConstructor called at the end of the C++ object's constructor, after any member variables have been initialised
int finishConstructor(void *thisPtr,
•startDestructor called at the start of the C++ object's destructor
int startDestructor(void *thisPtr,
•finishDestructor called at the end of the C++ object's destructor
int finishDestructor(void *thisPtr,
•command called when you use Memory Validator's send command to stub utility to send a custom message to a one or all stub DLLs
int command(char *command);
For class B derived from class A, the startConstructor() and finishDestructor() calls will be called for the constructor of class A and class B for the same object.
The same is true for destructors, but note that class B's destructor is called prior to that of class A for the same object.
Example code for all the above functions is provided in the stubExtDLL.cpp implementation file in the stubExtDLL project
Defining the functions for export and import
In the stubExtDLL example, the functions are defined as extern "C" functions which are exported from the DLL.
See the header file stubExtDLL.h demonstrating a way of declaring the functions so that when building the DLL, the functions are exported, but anyone including the header file sees the functions as imported.