This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Custom Action to check if Property exists problem
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Feb 15, 2008
10:20 AM
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.
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.
(2) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Feb 15, 2008
10:35 AM
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.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Feb 19, 2008
07:53 AM
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...
if (0 == strcmpi(szPropertyValue,"") )
So everything is back working again...
![](/skins/images/089A6DFE1F4989CB8CCC689A38D62C96/responsive_peak/images/icon_anonymous_message.png)