Please enable JavaScript to view this site.

Memory Validator Help

Navigation: Extending Memory Validator

Example stub extension DLL

Scroll Prev Top Next More

 

 

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.

 

Example stub extension project files

 

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 instructionStep for Microsoft® Developer Studio® 6.0  
 

stubExtDLL.vcproj instructionStep for Microsoft® Visual Studio / .net
 

 

UI extension DLL functions

 

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.

 

Constructor notification:

 

startConstructor instructionStep called at the start of the C++ object's constructor, before any member variables have been initialised  
 

int startConstructor(void *thisPtr,

                     void *functionAddress,

                     char *functionName);

 

finishConstructor instructionStep called at the end of the C++ object's constructor, after any member variables have been initialised
 

int finishConstructor(void *thisPtr,

                      void *functionAddress,

                      char *functionName);

 

Destructor notification:

 

startDestructor instructionStep called at the start of the C++ object's destructor  
 

int startDestructor(void *thisPtr,

                     void *functionAddress,

                     char *functionName);

 

finishDestructor instructionStep called at the end of the C++ object's destructor
 

int finishDestructor(void *thisPtr,

                      void *functionAddress,

                      char *functionName);

 

 

 

command instructionStep 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);

 

 

Derived classes

 

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 stub extension DLL code

 

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.