cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Daniel_Dority
Level 6

Possible Bug with Strings?

Hey there,

Try this out, let me know how it works for you.


InstallScript MSI Project

Create a List, within the list add several string values with different lengths on a dialog.

Example:

Administrator
Guest

Within the code behind I add a call to C#. I pass the strings on by and evaluate the data. If I picked "Administrator" first, I get these results:

Administrator - With the length of 1024 because it is padded with nulls.

That is fine, I account for it. I made a method which replaces \0 with string.Empty. After I strip it, I get these results:

Administrator - As the length of 13. Good it works.

Back to the dialog, now choose Guest. Pass that value over and you get the following data.

Guest - With the length of 1024 because it is padded with nulls.

After I strip it of nulls, I get this result:

Guestistrator

It happens on EVERY CASE. Meaning, the longest string seems to be always present while any shorter string gets appended to the difference of any string that was chosen previously.

This has to be a bug.

I am doing nothing but a simple Systems.Windows.Forms.MessageBox.Show(InstallShieldData) in C#. Nothing is customized.


As a temporary solution, I created a different method to strip nulls from InstallShield. I use a substring from the start to the first instance of a null, I pull the string I want out.

It works.

Or maybe I'm doing something wrong. Any insight would be great!



Edit:
private string TrimNulls(string s)
{
if(s == null)
{
return string.Empty;
}

if(s.IndexOf("\0") != -1)
{
return s.Substring(0, s.IndexOf("\0"));
}
else { return s; }
}
Labels (1)
0 Kudos
(4) Replies
MichaelU
Level 12 Flexeran
Level 12 Flexeran

How are you passing the strings to your DLLs? It sounds like they are being treated as character arrays instead of properly sized strings.
0 Kudos
Daniel_Dority
Level 6

STRING svUserName;
Object InstallerClass;

set InstallerClass = CoCreateObjectDotNet(SUPPORTDIR ^ "Installation.dll", "Installation.Wrapper" );



[Dialog Loop]

case TextBoxControlID:

CtrlGetText(DialogName, TextBoxControlID, svUserName)

InstallerClass.SaveUserName(svUserName);

[Dialog Loop End]



=============================

C#

namespace Installation
{
class Wrapper
{
private string m_Username = string.Empty;

public void SaveUserName(string Username)
{
// Default value from InstallShield
MessageBox.Show(Username);

// Value from InstallShield after trimming Nulls.
Username = Username.Replace("\0", string.Empty);
MessageBox.Show(Username);

m_Username = Username;
}
}
}




Nothing complex here.
0 Kudos
Daniel_Dority
Level 6

Also as a note, I have successfully replicated this issue in Combo Boxes, and Text Boxes.
0 Kudos
Daniel_Dority
Level 6

Any InstallShield QA's or Devs have anything further on this?
0 Kudos