[wix-users] Pass install directory to function in DLL for use at end of uninstall

Lewie Fitz lewfitz at gmail.com
Sat May 28 22:01:40 PDT 2016


Hello,

I am trying to pass the install directory to a custom action function in 
my DLL written in C++, but I can't get it to work.

The calling of the function works properly. Every time I execute the 
uninstall, I get a messagebox at the end. The problem is, I only ever 
get the error messagebox.

To pass the install directory to the DLL function, I am using the method 
suggested by several articles online and by MSDN itself for deferred 
execution of a custom action. I am trying to set the install dir string 
to a property named after my deferred custom action.

The following is the important bits of what I have done:

WIX file

         <Directory Id="TARGETDIR" Name="SourceDir">
             <Directory Id="PublicDir">
                 <Directory Id="APPLICATIONROOTDIRECTORY" Name="AppName"/>
             </Directory>
         </Directory>

         <Binary Id="CustomUninstall" 
SourceFile="SourceFiles\CustomUninstall.dll"/>
         <CustomAction Id="SetCustomActionData" Return="check" 
Property="CustomUninstall" Value="[APPLICATIONROOTDIRECTORY]"/>
         <CustomAction Id="CustomUninstall" BinaryKey="CustomUninstall" 
DllEntry="_DLLFunction at 4" Execute="deferred" Impersonate="no" 
Return="ignore"/>

         <InstallExecuteSequence>
             <Custom Action="SetCustomActionData" After="CostFinalize"/>
             <Custom Action="CustomUninstall" 
Before="InstallFinalize">Installed AND NOT UPGRADINGPRODUCTCODE</Custom>
         </InstallExecuteSequence>


CPP File

extern "C" __declspec(dllexport) UINT __stdcall DLLFunction(MSIHANDLE 
session)
{
     DWORD size = 0;

     UINT result = MsiGetProperty(session, L"CustomActionData,", L"", 
&size);
     //size now contains the size of the property's string, without null 
termination

     std::vector<WCHAR> buffer(size + 1);

     if (result == ERROR_MORE_DATA)
     {
         result = MsiGetProperty(session, L"CustomActionData,", 
buffer.data(), &size);
     }

     if (result != ERROR_SUCCESS)
     {
         MessageBox(NULL, L"Error", L"", MB_OK);
     }
     else
     {
         std::wstring dir(buffer.data());
         MessageBox(NULL, dir.c_str(), L"", MB_OK);
     }

     return ERROR_SUCCESS;
}


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the wix-users mailing list