OC Systems

Home | Contact | Advanced Search 

Technology

Can I call a function in my program from within a probe?

Yes, there are several ways:

If the function is in a DLL you can use the NT routines GetProcAddress and GetModuleHandle to find the routine. For example:

/* call Beep to sound a 2kHz tone for a second */ 
GetProcAddress(GetModuleHandle("KERNEL32"),"Beep")(2000, 1000); 

In the above example, you could use the name of your DLL instead of KERNEL32.

Another way to call a routine is to use the Aprobe ap_SymbolToAddress function. This will allow you to call a routine regardless of where it is. For example:

typedef void MyBeep(int Msec, int Hz);
probe thread 
{    
  probe "main"    
  {       
    on_entry       
    {          
      (*(MyBeep *)ap_SymbolToAddress               
        (ap_SymbolNameToId                  
          (ap_ModuleNameToId("KERNEL32"),                   
          "Beep()",                   
          NULL)))(4000, 1000);       
    }    
  } 
}

If your program is compiled with debugging enabled, you can precede its name with a '$'. This is often useful for using a probe to call debugging-support routines, e.g.,

probe thread    
{       
  probe "ReadSymbolTable"       
  {          
    on_exit          
      $DumpSymbolTable($0);          
  }    
}

Calling C++ methods is more complex (they require a "this" pointer, and the naming can be tricky). Contact us at if you wish to do this.

Aprobe Technology Overview

Schedule a web demo

Contact us