Skip to content
Diamond Sierra

Samples

The following programs and examples illustrate all that is needed to start logging. Also feel free to visit the web site for additional ideas and samples as Diamond Sierra is constantly adding support…

Updated · By Diamond Sierra

On this page

The following programs and examples illustrate all that is needed to start logging. Also feel free to visit the web site for additional ideas and samples as Diamond Sierra is constantly adding support for new applications and environments. Current API extensions (available only through the web site) include SQL Server, Sybase, InstallShield, and more.

Using the C API

#include <PB.h>

VOID main(INT argc, CHAR* argv[])
{
PB_COMPONENT    cp = {L"My component", L"", TRUE, 0};
PB_CONTEXT    cx = {L"My context", TRUE, 0};

PBSetDefaultComponent(&cp, PB_MODULE_DEFAULT);    /* Set default 'component'.*/
PBSetDefaultContext(&cx, PB_THREAD_DEFAULT);        /* Set default 'context'.  */

/*
* Log a message using the default component and context set above.
* Note that PBLog() supports printf() formatting.
*/
PBLog(NULL, NULL, PB_WARNING, "This program (%s) does nothing.", argv[0]);
}

Using the C++ API

#include <PB.h>

VOID main(INT argc, CHAR* argv[])
{
CPBScopeLogger    slgr(PB_STATUS, "main()");    //Log entrance/exit of scope 'main()'.
CPBComponent    cp("My component");    //Set default 'component'.
CPBContext    cx("Some context");    //Set default 'context'.
CPBLogger    lgr;

//
// Log a message using the default component and context set above.
// Note that PBLog() supports printf () formatting.
//
lgr.Log(PB_WARNING, "This program (%s) does nothing.", argv[0]);
}

Using the COM interface from Visual Basic

(Note: Paul Bunyan’s type library must be registered with the Visual Basic IDE before it can be used.)

Private Sub Ok_Click()
'Declare logger object
Dim lgr As New PBLogger

'Log a message
lgr.Log "WARNING", "Some warning..."
End Sub

Using the command line interface

Remarks

  • The use of the components and contexts in the C and C++ samples above are not required and are only included for demonstration purposes. The same is true of the CPBScopeLogger object in the C++ sample. All that is required is the #include directive and a single PBLog statement.
  • The PB.h header file will flag the compiler to embed the name of the appropriate default PB***.lib so there is no need to manually add any libs to the linker arguments.
  • The PB.h and PB***.lib files must be on the INCLUDE and LIB paths. Remember that some IDEs (e.g. Microsoft’s MSDev) do not automatically keep their copies of the environment variables in sync with the system’s environment variables so this will need to be done manually. In Microsoft Development Studio this is done on the Directories tab of the Options dialog found under the Tools | Options menu.
  • When using Visual Basic (or VBA from Access, Excel, Word, etc.) remember that all type libraries must be registered before using them.