Initializing the Symbol Handler

The following code demonstrates how to initialize the symbol handler. The SymSetOptions function defers symbol loading until symbol information is requested. The code loads the symbols for each module in the specified process by passing a value of TRUE for the bInvade parameter of the SymInitialize function. (This function calls the SymLoadModule64 function for each module the process has mapped into its address space.)

If the specified process is not the process that called SymInitialize, the code passes a process identifier as the first parameter of SymInitialize.

Specifying NULL as the second parameter of SymInitialize indicates that the symbol handler should use the default search path to locate symbol files. For detailed information on how the symbol handler locates symbol files or how an application can specify a symbol search path, see Symbol Paths.

DWORD  error;
HANDLE hCurrentProcess;
HANDLE hProcess;

SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);

hCurrentProcess = GetCurrentProcess();

if (!DuplicateHandle(hCurrentProcess, hCurrentProcess, hCurrentProcess, &hProcess, 0, FALSE, DUPLICATE_SAME_ACCESS))
{
    // DuplicateHandle failed
    error = GetLastError();
    printf("DuplicateHandle returned error : %d\n", error);
    return FALSE;
}

if (!SymInitialize(hProcess, NULL, TRUE))
{
    // SymInitialize failed
    error = GetLastError();
    printf("SymInitialize returned error : %d\n", error);
    return FALSE;
}