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

shashank khadse shashank.s.khadse at gmail.com
Tue May 31 01:30:37 PDT 2016


I think you need to set the custom action "SetCustomActionData" just before
the "CustomUninstall" custom action.
try it once, I may solve ur problem.

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

Also in ur custom action cpp file add following function GetProperty() and
call it UINT __stdcall DLLFunction(MSIHANDLE session)   like this
GetProperty(session , "CustomActionData", strOutValue );

void GetProperty(MSIHANDLE hInstall, const std::string& strPropertyName,
std::string& strPropertValue)
{
    //***************************************************

    TCHAR* szValueBuf = NULL;
    DWORD cchValueBuf = 0;
    UINT uiStat = MsiGetProperty(hInstall, TEXT(strPropertyName.c_str()),
        TEXT(""),
        &cchValueBuf);

    if (ERROR_MORE_DATA == uiStat)
    {
        ++cchValueBuf; // on output does not include terminating null,
        szValueBuf = new TCHAR[cchValueBuf];
        if (szValueBuf)
        {
            uiStat = MsiGetProperty(hInstall, TEXT(strPropertyName.c_str()),
                szValueBuf, &cchValueBuf);

            if (ERROR_SUCCESS == uiStat)
            {
                strPropertValue = szValueBuf;
            }

            if (szValueBuf != NULL)
                delete[] szValueBuf;
        }
    }
    if (ERROR_SUCCESS != uiStat)
    {
        if (szValueBuf != NULL)
            delete[] szValueBuf;

    }
}

hope this solves ur issue.
-
Shanky

On Sun, May 29, 2016 at 5:35 PM, Michael Urman <murman at gmail.com> 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/
>


More information about the wix-users mailing list