Please enable JavaScript to view this site.

Memory Validator Help

Navigation: Extending Memory Validator

Example user interface extension DLL

Scroll Prev Top Next More

 

The user interface extension DLL functionality lets you provide additional descriptive messaging for displaying with user defined allocations.

 

seeAlsoSee also the mvUserCustomAlloc family of functions used for custom heap tracking using the Memory Validator API.

 

 

Example UI extension project files

 

The example extension project can be found in the uiExtDLL 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:

 

uiExtDLL.dsp instructionStep for Microsoft® Developer Studio® 6.0  
 

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

 

UI extension DLL functions

 

A user interface extension DLL needs to provide just two functions:

 

getDllID instructionStep uniquely identifies the user interface extension DLL  
 

DWORD getDllID();

 

Each ui extension DLL must return a different value than any of the other user interface extension DLLs.

 

A value of -1 returned means that the DLL should not be used as an extension DLL.
 

getDescription instructionStep allocates a buffer to return the description of an object
 

int getDescription(DWORD   userData1,

                  DWORD   userData2,

                  DWORD   address,

                  DWORD   size,

                  DWORD   refCount,

                  wchar_t **description);

 

The function is passed the userData1 and userData2 values that were passed into the API function that reported the object e.g. mvUserCustomAlloc().

 

The address, size and reference count are also passed in.

 

The function must allocate a buffer using HeapAlloc() and use it to return the description of the object.

 

The buffer should be on the program's default Heap as returned by GetProcessHeap().

 

 

Defining the functions for export and import

 

In the uiExtDLL example, the functions are defined as extern "C" functions which are exported from the DLL.

 

See the header file uiExtDLL.h for an example 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.

 

 

Example ui extension DLL code

 

The code snippet below is taken directly from the uiExtDLL.cpp implementation file in the uiExtDLL project

 

Although userData1 and userData2 are not interpreted here, an example use might be to pass indices into a known array of strings or enumerated values used to generate a message.

 

 

doc-expand-iconShow the C++ example ui extension functions

 

//-NAME---------------------------------
// getDllID
//.DESCRIPTION..........................
// Provide ID for Memory Validator Extension DLL
//.PARAMETERS...........................
//.RETURN.CODES.........................
// -1 means don't use
// Otherwise return a unique ID to identify this DLL.
//--------------------------------------
 
UIEXTDLL_API DWORD getDllID()
{
   return 1;   // make this ID unique amongst all the UI extension DLLs you have
}
 
//-NAME---------------------------------
// getDescription
//.DESCRIPTION..........................
// Generate a description for the data provided.
//.PARAMETERS...........................
// userData1         -in-  Supplied to mvUserCustomAlloc
// userData2         -in-  Supplied to mvUserCustomAlloc
// address           -in-  Address/Handle/ID to track
// size              -in-  Size for the address
// refCount          -in-  Reference count for the address
// **description     -out- Returned string allocated with HeapAlloc(GetProcessHeap(), 0, sizeOfData)
//.RETURN.CODES.........................
// TRUE for got a description.
// FALSE for failed.
//--------------------------------------
 
UIEXTDLL_API int getDescription(DWORD   userData1,
                         DWORD   userData2,
                         DWORD   address,
                         DWORD   size,
                         DWORD   refCount,
                         wchar_t   **description)
{
   TCHAR   text[200];
   int      len;
 
   _stprintf(text, _T(" UI-Ext-DLL UserObject: address:0x%08x size:0x%08x ref:%d 0x%08x 0x%08x"),
            address, size, refCount, userData1, userData2);
   len = _tcslen(text);
 
   *description = (TCHAR *)HeapAlloc(GetProcessHeap(), 0, sizeof(TCHAR) * (len + 1));
   if (*description != NULL)
   {
      _tcscpy(*description, text);
      return TRUE;
   }
 
   return FALSE;
}