cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Tim_Mayert
Level 9

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.
Labels (1)
0 Kudos
(2) Replies
MichaelU
Level 12 Flexeran
Level 12 Flexeran

If this is C or C++ (like it appears to be), code like szPropertyValue == "" will not test if the string is empty. Also there is some perilous mixing of new/delete with calls to free(), so I'd get the local C/C++ expert to straighten out this code, or move to a language with which the author is more familiar.
0 Kudos
Tim_Mayert
Level 9

Thanks Michael, I did have to change the comparison to the following for it to work correctly:

if (0 == strcmpi(szPropertyValue,"") )

So everything is back working again...
0 Kudos