Enumerating Symbols
The following code displays the name, address, and size of each loaded symbol in the specified module. The SymEnumSymbols function requires a callback function, which is called once for each module loaded. In this example, EnumSymProc is an implementation of the callback function.
#include <windows.h>
#include <stdio.h>
#include <dbghelp.h>
BOOL CALLBACK EnumSymProc(
PSYMBOL_INFO pSymInfo,
ULONG SymbolSize,
PVOID UserContext)
{
UNREFERENCED_PARAMETER(UserContext);
printf("%08X %4u %s\n",
pSymInfo->Address, SymbolSize, pSymInfo->Name);
return TRUE;
}
void main()
{
HANDLE hProcess = GetCurrentProcess();
DWORD64 BaseOfDll;
char *Mask = "*";
BOOL status;
status = SymInitialize(hProcess, NULL, FALSE);
if (status == FALSE)
{
return;
}
BaseOfDll = SymLoadModuleEx(hProcess,
NULL,
"foo.dll",
NULL,
0,
0,
NULL,
0);
if (BaseOfDll == 0)
{
SymCleanup(hProcess);
return;
}
if (SymEnumSymbols(hProcess, // Process handle from SymInitialize.
BaseOfDll, // Base address of module.
Mask, // Name of symbols to match.
EnumSymProc, // Symbol handler procedure.
NULL)) // User context.
{
// SymEnumSymbols succeeded
}
else
{
// SymEnumSymbols failed
printf("SymEnumSymbols failed: %d\n", GetLastError());
}
SymCleanup(hProcess);
}