Please enable JavaScript to view this site.

Memory Validator Help

Navigation: » No topics above this level «

API

Scroll Prev Top Next More

 

The Memory Validator API

 

There are some features of Memory Validator that are useful to call directly from your program, including tracking of memory in custom heap managers.

 

Memory Validator has an API that makes this possible; just include stublib.h and link to these two libraries provided:

 

svlMemoryValidatorStub.lib instructionStep The interface to the Memory Validator DLL
 

svlMemoryValidatorStubLib.lib instructionStep        An API library that calls the Memory Validator library

 

_x64.lib versions are available for the 64bit version of Memory Validator (when the executable is 64 bits).

 

 

Starting the Profiler

 

To start the profiler from your API code you need to call the function "startProfiler" from your code before you call any API functions. Ideally you should call this function as early in your program as possible.

 

Function Definition:

 

 extern "C" void startProfiler();

 

If you prefer to start the profiler from the user interface or command line you can omit the startProfiler() call. You can leave it present if you wish to start Memory Validator from your program.

 

All the API functions are exported as extern "C", so C as well as  C++ users can use them.

 

noteLinking with these libraries is only necessary in order to use the API from your program and is not needed if use Memory Validator 'normally'.

 

noteIf you're using stublib.h (see below) a convenience function void mvStartProfiler() exists that calls startProfiler() for you.

 

 

Including stublib.h

 

The header stublib.h has all the appropriate function and enumeration definitions to use the API.

 

Ensure that you include <windows.h> prior to including stublib.h.

 

There are workarounds if you can't include <windows.h>.

 

seeAlsoTroubleshooting errors that may occur when including stublib.h.

 

 

Linking to the API libraries - 32 bit, x86

 

You'll need to link to both of the following files:

 

svlMemoryValidatorStub.lib is found in the following directories in the Memory Validator install directory:

 

stub\debug

stub\release

 

svlMemoryValidatorStubLib.lib is in the following directories where nnnn identifies the visual studio release, e.g. VS6, 2008, 2012, etc.

 

stublib\debug_nnnn

stublib\release_nnnn

 

 

Linking to the API - 64 bit, x64

 

Similar to 32 bit, but add _x64 to the library and the debug/release folder.

 

For example, svlMemoryValidatorStub_x64.lib is found in stub\debug_x64 and stub\release_x64.

 

 

Calling API functions using GetProcAddress

 

If you don't want to link to the API you can use GetProcAddress to find the interface functions in the Memory Validator DLL svlMemoryValidatorStub.dll.

 

The interface functions have different names and use C++ name mangling, but have identical parameters to the API functions.

 

To determine function names use a tool such as depends.exeexternalLink to examine the exports from Memory Validator.

 

Here is an example (with the 32 bit API):

 

   HMODULE   hMod;
 
   // get module, will only succeed if Memory Validator launched this app or is injected into this app
 
   hMod = GetModuleHandleA("svlMemoryValidatorStub.dll");
   if (hMod != NULL)
   {
      // MV is present, lookup the function and call it to set a watermark for this location in the code
 
      mvSetWatermark_FUNC   pFunc;
 
      // "?apiSetWatermark@@YAXPAD@Z" is equivalent to linking against "mvSetWatermark"
 
      pFunc = (mvSetWatermark_FUNC)GetProcAddress(hMod, "?apiSetWatermark@@YAXPAD@Z");   // 32 bit example, not for x64!
      if (pFunc != NULL)
      {
         (*pFunc)(watermarkName);
      }
   }

 

 

API functions and their GetProcAddress names

 

For any API functions not listed, try looking up the name in svlMemoryValidatorStub.dll using depends.exe

 

 

 

 

Other exported functions

 

You may see some other functions exported from svlMemoryValidatorStub.dll(_x64).dll.

 

warningnote These other functions are for Memory Validator's use. Using them may damage memory locations and/or crash your code. Best not to use them!