
timmayert asked a question.
Custom Action to check if Property exists problem
I created a custom action MSI dll that I use to check if properties exist and what the values are. In my testing I am checking for a property that I know does not exist, but when I run my custom action it will basically come back saying the property does exist???
Could someone tell me what I am doing wrong in my custom action code below:
TCHAR* szPropertyValue = NULL;
CString csPropertyValue = _T("");
CString csPropertyName = _T("NETWORK_CONTENT");
DWORD dwCount = 0;
UINT uiReturn;
uiReturn = MsiGetProperty(hModule, csPropertyName, TEXT(""), &dwCount);
if (ERROR_MORE_DATA == uiReturn)
{
++dwCount; // on output does not include terminating null, so add 1
szPropertyValue = new TCHAR[dwCount];
if (szPropertyValue)
{
uiReturn = MsiGetProperty(hModule, csPropertyName, szPropertyValue, &dwCount);
}
}
if ( ERROR_SUCCESS != uiReturn )
{
// There was a problem therefore did not get property.
if (szPropertyValue != NULL)
delete [] szPropertyValue;
return false;
}
else
{
// The MsiGetProperty call returned ERROR_SUCCESS so it must mean that
// it found the property or at least was
// able to complete the call and return 0.
if (szPropertyValue == NULL)
{
// The property contain NULL so that should mean that it does not
// exist so return false.
free( szPropertyValue );
return false;
}
if (szPropertyValue == "")
{
// The property contain NULL so that should mean that it does not
// exist so return false.
free( szPropertyValue );
return false;
}
// Property exists and is not NULL or empty "" so the CString value that
// may be used to check the value of.
csPropertyValue = szPropertyValue;
free( szPropertyValue );
if ( bValueNeeded == false )
{
// The value is not needed, just need to know if the property exists. So
// return true.
return true;
}
// do other processing here....
}
when debugging through this it will always come back with the property existing even though the value of szPropertyValue is nothing???
Can any one see what is wrong with my code?
Thanks for any help.
if (0 == strcmpi(szPropertyValue,"") )
So everything is back working again...