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
- :
- My test code/
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
May 01, 2013
10:35 AM
Issue: Removing last character from property/variable
Hello,
I am having an issue with an InstallScript MSI project. What’s happening is that when IS performs the MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_SERVER", szJPSSQLServer, nvSize ) action, I am not getting the desired result. In this case it should be writing “(local)” without quotes to the public property IS_SQLSERVER_SERVER. For some reason it is removing the last character and writing “(local” without the quotes.
Dlg_SdStartCopy:
szTitle = "";
szMsg = "";
//
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
szSubKey = "SOFTWARE\\MyCompany\\MyApp";
RegDBSetKeyValueEx(szSubKey, "USERNAME", REGDB_STRING, szUserName, -1);
RegDBSetKeyValueEx(szSubKey, "IS_SQLSERVER_SERVER", REGDB_STRING, szSQLServer, -1);
//
MessageBox(IS_SQLSERVER_SERVER, INFORMATION);
MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_SERVER", szSQLServer, nvSize );
MessageBox(IS_SQLSERVER_SERVER, INFORMATION);
MsiGetProperty( ISMSI_HANDLE, "PORTNUMBER", svPortNumber, nvSize );
I am having an issue with an InstallScript MSI project. What’s happening is that when IS performs the MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_SERVER", szJPSSQLServer, nvSize ) action, I am not getting the desired result. In this case it should be writing “(local)” without quotes to the public property IS_SQLSERVER_SERVER. For some reason it is removing the last character and writing “(local” without the quotes.
Dlg_SdStartCopy:
szTitle = "";
szMsg = "";
//
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
szSubKey = "SOFTWARE\\MyCompany\\MyApp";
RegDBSetKeyValueEx(szSubKey, "USERNAME", REGDB_STRING, szUserName, -1);
RegDBSetKeyValueEx(szSubKey, "IS_SQLSERVER_SERVER", REGDB_STRING, szSQLServer, -1);
//
MessageBox(IS_SQLSERVER_SERVER, INFORMATION);
MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_SERVER", szSQLServer, nvSize );
MessageBox(IS_SQLSERVER_SERVER, INFORMATION);
MsiGetProperty( ISMSI_HANDLE, "PORTNUMBER", svPortNumber, nvSize );
(5) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
May 01, 2013
11:16 AM
What is nvSize initialized too?
In the first call to MsiGetProperty the nvSize is an input telling MSI what the size of your buffer (szSQLServer) is. If the buffer is too small MsiGetProperty returns ERROR_MORE_DATA, which you do not detect. In this case the nvSize is one TCHAR character less than the size of the buffer that you need.
So if the buffer was too small then your first call is returning the buffer size (one too small) and your second call is telling MSI that it only has that size yielding the string minus the last character, as you observe. You might want to look at the example code in the MsiGetProperty (InstallShield help) and implement something along that line to resize your buffer for the whole string.
In the first call to MsiGetProperty the nvSize is an input telling MSI what the size of your buffer (szSQLServer) is. If the buffer is too small MsiGetProperty returns ERROR_MORE_DATA, which you do not detect. In this case the nvSize is one TCHAR character less than the size of the buffer that you need.
So if the buffer was too small then your first call is returning the buffer size (one too small) and your second call is telling MSI that it only has that size yielding the string minus the last character, as you observe. You might want to look at the example code in the MsiGetProperty (InstallShield help) and implement something along that line to resize your buffer for the whole string.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
May 01, 2013
11:33 AM
I see that the second call to MsiGetProperty is for a different property, so my comments about the second call in the prior post are wrong. But I still advise evaluating what nvSize is at the time of the call and checking out the example code to make sure you resize the buffer for the whole string. I had similar issues several months ago when working with MsiGetProperty but I got it working.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
May 01, 2013
01:24 PM
Thanks, Phil. I have nvSize initialized to 255.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
May 01, 2013
02:34 PM
I am not sure if your last post means it was initially set to 255 or if you checked that it was 255 at the time of the call. Your code fragment lists several calls that use nvSize without initializing it between the calls.
In a test project I added Property "TEST_STR" to the Property Table and initialized it to "(local)".
When I call the following I always get the expected result of "(local)".
nvSize = 255;
MsiGetProperty( hMSI, "TEST_STR", szValue, nvSize);
MessageBox(szValue, MB_OK); //this always returns the full string "(local)" AND nvSize is not wet to 7
But if I then follow that code with:
szValue = "";
nReturn = MsiGetProperty( hMSI, "TEST_STR", szValue, nvSize);
Sprintf(szMsg, "MsiGetProperty returned: %d\nszValue is: %s\nnvSize is: %d\n", nReturn, szValue, nvSize);
MessageBox(szMsg, MB_OK); //szValue is now "(local" AND nvSize is not wet to 7. nReturn indicates ERROR_MORE_DATA.
I get the result you reported, "(local" because nvSize was set to 7, (which is too small) by the prior call.
I think I would implement code like the following, although you could just set nvSize to 255 prior to your call. I would also use Sprintf to see what your function is returning in both nReturn and nvSize.
szValue = "";
nReturn = MsiGetProperty( hMSI, "TEST_STR", szValue, nvSize);
if(nReturn = ERROR_MORE_DATA /*234*/) then
nvSize++;
Resize(szValue, nvSize);
nReturn = MsiGetProperty( hMSI, "TEST_STR", szValue, nvSize);
endif; //there are other posible return codes to process
Sprintf(szMsg, "MsiGetProperty returned: %d\nszValue is: %s\nnvSize is: %d\n", nReturn, szValue, nvSize);
MessageBox(szMsg, MB_OK);
I hope this helps.
In a test project I added Property "TEST_STR" to the Property Table and initialized it to "(local)".
When I call the following I always get the expected result of "(local)".
nvSize = 255;
MsiGetProperty( hMSI, "TEST_STR", szValue, nvSize);
MessageBox(szValue, MB_OK); //this always returns the full string "(local)" AND nvSize is not wet to 7
But if I then follow that code with:
szValue = "";
nReturn = MsiGetProperty( hMSI, "TEST_STR", szValue, nvSize);
Sprintf(szMsg, "MsiGetProperty returned: %d\nszValue is: %s\nnvSize is: %d\n", nReturn, szValue, nvSize);
MessageBox(szMsg, MB_OK); //szValue is now "(local" AND nvSize is not wet to 7. nReturn indicates ERROR_MORE_DATA.
I get the result you reported, "(local" because nvSize was set to 7, (which is too small) by the prior call.
I think I would implement code like the following, although you could just set nvSize to 255 prior to your call. I would also use Sprintf to see what your function is returning in both nReturn and nvSize.
szValue = "";
nReturn = MsiGetProperty( hMSI, "TEST_STR", szValue, nvSize);
if(nReturn = ERROR_MORE_DATA /*234*/) then
nvSize++;
Resize(szValue, nvSize);
nReturn = MsiGetProperty( hMSI, "TEST_STR", szValue, nvSize);
endif; //there are other posible return codes to process
Sprintf(szMsg, "MsiGetProperty returned: %d\nszValue is: %s\nnvSize is: %d\n", nReturn, szValue, nvSize);
MessageBox(szMsg, MB_OK);
I hope this helps.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
May 01, 2013
02:58 PM
Thanks, Phil. Before I did that I created a new variable for the buffer size and used it only for that MsiSetProperty and it worked fine.
Thanks for your time and help!
Thanks for your time and help!