Using WdbgExts Extension Callbacks

When you write a WdbgExts extension DLL, you can export certain functions:

  • You must export a function named WinDbgExtensionDllInit. When the debugger loads your extension DLL, it first calls WinDbgExtensionDllInit and passes it three arguments.

    • A pointer to a WINDBG_EXTENSION_APIS64 structure, which contains pointers to functions that are implemented by the debugger and declared in Wdbgexts.h. You must copy the entire structure to a global variable that you create in your DLL.
    • A major version number. You must copy the major version number to a global variable that you create in your DLL.
    • A minor version number. You must copy the minor version number to a global variable that you create in your DLL.

    For example, you could create global variables named ExtensionApis, SavedMajorVersion, and SavedMinorVersion as shown in the following example.

    WINDBG_EXTENSION_APIS64 ExtensionApis;
    USHORT SavedMajorVersion;
    USHORT SavedMinorVersion;
    
    VOID WinDbgExtensionDllInit(PWINDBG_EXTENSION_APIS64 lpExtensionApis,
        USHORT MajorVersion, USHORT MinorVersion)
    {
       ExtensionApis = *lpExtensionApis;
       SavedMajorVersion = MajorVersion;
       SavedMinorVersion = MinorVersion;
        ...
    }
    
  • You must export a function called ExtensionApiVersion. The debugger calls this function and expects back a pointer to an EXT_API_VERSION structure that contains the version number of the extension DLL. The debugger uses this version number when executing commands like .chain and version that display the extension version number.

  • You can optionally export a function called CheckVersion. The debugger calls this routine every time you use an extension command. You can use this to print out version mismatch warnings when your DLL is of a slightly different version than the debugger, but not different enough to prevent it from running.