It seems wcslen doesn't play nice will null pointers.  So we should
update those test to be similar to:
if ((userName == NULL)||(wcslen(userName) == 0))

Also, is there a reason you are driving your own custom logging instead
of using WcaLog? Below code redone, verified compliable, that should
allow you to do a msiexec foo.msi /l*v %Temp%\Foo.log.  This will give
you a verbose log of everything going on inside the installer and within
the CA.


#include "strutil.h"

UINT __stdcall VerifyUserInformation(__in MSIHANDLE hInstall)
{
     LPWSTR userName = NULL;
     LPWSTR email = NULL;
     HRESULT hr = S_OK;
     UINT er = ERROR_SUCCESS;

     hr = WcaInitialize(hInstall, "VerifyUserInformation");
     ExitOnFailure(hr, "Failed to Initialize");

     WcaLog(LOGMSG_VERBOSE, "After initialize");

     hr = WcaSetProperty(L"UserInfoError", L"");
     ExitOnFailure(hr, "Failed to initialize UserInfoError");

     WcaLog(LOGMSG_VERBOSE, "After set property");

         if (WcaIsUnicodePropertySet(L"UNAME"))
     {
         WcaLog(LOGMSG_VERBOSE, "Inside
(WcaIsUnicodePropertySet('UNAME')");
         hr = WcaGetProperty(L"UNAME", &userName);
         ExitOnFailure(hr, "Failed to get UNAME.");
         WcaLog(LOGMSG_VERBOSE, "UNAME is %ls.", userName);
     }

     if (WcaIsUnicodePropertySet(L"EMAIL"))
     {
         WcaLog(LOGMSG_VERBOSE, "Inside
(WcaIsUnicodePropertySet('EMAIL')");
         hr = WcaGetProperty(L"EMAIL", &email);
         ExitOnFailure(hr, "Failed to get EMAIL.");
         WcaLog(LOGMSG_VERBOSE, "EMAIL is %ls.", email);
     }

     if((NULL == userName)||(wcslen(userName) == 0))
     {
         WcaLog(LOGMSG_VERBOSE, "Inside (wcslen(userName) == 0)");
         hr = WcaSetProperty(L"UserInfoError", L"Please enter your
name.");
         WcaLog(LOGMSG_VERBOSE, "Please enter your name.");
     }
     else if((NULL == email)||(wcslen(email) == 0))
     {
         WcaLog(LOGMSG_VERBOSE, "Inside (wcslen(email) == 0)");
         hr = WcaSetProperty(L"UserInfoError", L"Please enter your email
address.");
         WcaLog(LOGMSG_VERBOSE, "Please enter your email address.");
     }

     WcaLog(LOGMSG_VERBOSE, "After all the if statements");

LExit:
     ReleaseStr(userName);
     ReleaseStr(email);
     if (FAILED(hr))
     {
         er = ERROR_INSTALL_FAILURE;
     }
     return WcaFinalize(er);
}

-----Original Message-----
From: Kevin Hebert [mailto:ke...@legendary-immersion.com] 
Sent: Tuesday, November 29, 2011 2:39 PM
To: General discussion for Windows Installer XML toolset.
Subject: Re: [WiX-users] Custom Action to verify input

Finally got the linker errors resolved.  I run my msi, and if I leave 
the name or email blank, instead of an error, the installer just quits.

Here's the CA:

UINT __stdcall VerifyUserInformation(__in MSIHANDLE hInstall)
{
     wchar_t *filePath = L"C:\\Log.txt";
     log(filePath, L"Inside VerifyUserInformation(__in MSIHANDLE 
hInstall)");
     LPWSTR userName = NULL;
     LPWSTR email = NULL;
     HRESULT hr = S_OK;
     UINT er = ERROR_SUCCESS;

     hr = WcaInitialize(hInstall, "VerifyUserInformation");
     ExitOnFailure(hr, "Failed to Initialize");

     log(filePath, L"After initialize");

     hr = WcaSetProperty(L"UserInfoError", L"");
     ExitOnFailure(hr, "Failed to initialize UserInfoError");

     log(filePath, L"After set property");

     if (WcaIsPropertySet("UNAME"))
     {
         log(filePath, L"Inside (WcaIsPropertySet('UNAME')");
         hr = WcaGetProperty(L"UNAME", &userName);
         log(filePath, userName);
         ExitOnFailure(hr, "Failed to get UNAME.");
         WcaLog(LOGMSG_VERBOSE, "UNAME is %ls.", userName);
     }

     if (WcaIsPropertySet("EMAIL"))
     {
         log(filePath, L"Inside (WcaIsPropertySet('EMAIL')");
         hr = WcaGetProperty(L"EMAIL", &email);
         log(filePath, email);
         ExitOnFailure(hr, "Failed to get EMAIL.");
         WcaLog(LOGMSG_VERBOSE, "EMAIL is %ls.", email);
     }

     if(wcslen(userName) == 0)
     {
         log(filePath, L"Inside (wcslen(userName) == 0)");
         hr = WcaSetProperty(L"UserInfoError", L"Please enter your
name.");
         WcaLog(LOGMSG_VERBOSE, "Please enter your name.");
     }
     else if(wcslen(email) == 0)
     {
         log(filePath, L"Inside (wcslen(email) == 0)");
         hr = WcaSetProperty(L"UserInfoError", L"Please enter your email

address.");
         WcaLog(LOGMSG_VERBOSE, "Please enter your email address.");
     }

     log(filePath, L"After all the if statements");

LExit:
        /* ReleaseStr(userName);
         ReleaseStr(email); */
     if (FAILED(hr))
     {
         er = ERROR_INSTALL_FAILURE;
     }
     return WcaFinalize(er);
}

Here's the xml with the call to the CA:

<CustomAction Id="verifyUserInformation" BinaryKey="installerDLL" 
DllEntry="VerifyUserInformation" Execute="immediate" 
Return="check"></CustomAction>
<Publish Event="DoAction" Value="verifyUserInformation" 
Order="1">1</Publish>
<Publish Event="SpawnDialog" Order="2" Value="ConfigDlg"><![CDATA[ 
UserInfoError ]]></Publish>
<Publish Event="NewDialog" Order="3" Value="PassDlg"><![CDATA[ NOT 
UserInfoError ]]></Publish>

I added some logs (as you can see) to see what was going on.  I get the 
log "After Set Property", and that's it.  Nothing else after that.  Not 
even one for "After all the if statements".

------------------------------------------------------------------------
------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to