cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
bbarton11
Level 5

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 );
Labels (1)
0 Kudos
(5) Replies
phill_mn
Level 7

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.
0 Kudos
phill_mn
Level 7

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.
0 Kudos
bbarton11
Level 5

Thanks, Phil. I have nvSize initialized to 255.
0 Kudos
phill_mn
Level 7

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.
0 Kudos
bbarton11
Level 5

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!
0 Kudos