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

Phil Wilson phil.wilson at mvps.org
Sun May 29 16:58:41 PDT 2016


If this an uninstall, that APPLICATIONROOTDIRECTORY property value won't be
preserved anywhere unless you used something the like the WiX "remember
property" pattern.

Phil W 

-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of
Lewie Fitz
Sent: Sunday, May 29, 2016 6:21 AM
To: WiX Toolset Users Mailing List
Subject: Re: [wix-users] Pass install directory to function in DLL for use
at end of uninstall

Thank you very much for your response. What you say might be true. The
problem is, however, that pchValueBuf (size) always contains 0 after the
first call to MsiGetProperty. If I can ever get something other than 0 to
come out of the first call, I can make sure that the second call works .:)


On 5/29/2016 5:05 AM, Michael Urman wrote:
> If you debug, I bet you'll see you sill receive ERROR_MORE_DATA from 
> your second call to MsiGetProperty. So reviewing the documentation of
> *pchValueBuf* more closely, you are required to pass in a value that 
> represents space for a trailing null character, but the output value 
> from MsiGetProperty never includes this. So your vector length of 
> (size + 1) is good, but that also needs to be the value of size in your
second call.
>
> On Sun, May 29, 2016 at 12:01 AM, Lewie Fitz <lewfitz at gmail.com> wrote:
>
>> 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
>>
>>
>> ____________________________________________________________________
>> WiX Toolset Users Mailing List provided by FireGiant 
>> http://www.firegiant.com/
>>
> ____________________________________________________________________
> WiX Toolset Users Mailing List provided by FireGiant 
> http://www.firegiant.com/


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


____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant
http://www.firegiant.com/




More information about the wix-users mailing list