Search code examples
windows-installeruninstallation

Take input during MSI application uninstallation implemented using WIX


We have an application that is developed using WIX. When the user tries to uninstall the application on Windows, we need to prompt the user for a code to verify. If the user gives the correct code, then the uninstallation will proceed, otherwise the uninstallation might abort. How can I prompt the user for providing the code?

Currently, we have a custom step during uninstallation where we can show him some message using WTSSendMessage. If I try to receive the input from user using DialogBox, it never pops up. However, the same DialogBox works with other Windows applications, but doesn't work during uninstallation phase. How can I prompt the user for the code during uninstallation?


Solution

  • The issue was to find out proper HINSTANCE in DialogBox call. I was using GetModuleHandle(NULL) or NULL. It didn't work because it's not executable, rather it's DLL. When I used the proper HINSTANCE for DLL it started working. Here is the code snippet to find out the HINSTANCE for DLL:

    HMODULE GetCurrentModule()
    {
    HMODULE hModule = NULL;
    GetModuleHandleEx(
        GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
        (LPCTSTR)GetCurrentModule,
        &hModule);
    
    return hModule;
    }
    
    bool callingFunction()
    {
    
    INT32 retVal = DialogBox(GetCurrentModule(),
        MAKEINTRESOURCE(IDD_UNINST_CODE),
        NULL, //(HWND)hInstall,
        (DLGPROC)MsgProcessingProc);
      ...