Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 2

C# dll not recognizing string parameter encoding from InstallScript

Hello, first post here, hopefully someone can provide some insights on this problem:

I built a C# dll used for serial validation. It's called from within the InstallScript using DotNetCoCreateObject. I'm passing through szName, szCompany, and szSerial after receiving the data. This part all works properly,
however when the string values get passed into the DLL, weird things happen.
For example, say we have the following values:
szName: User
szCompany: Test Inc
szSerial: 123456

Inside of the C# DLL functions, it sees these string values and when I print them, they look to be correct. However if I do a String.Equals(szName, "User") inside of the DLL, it fails. String.Compare() works. So that's ok. But the problem is when I try to create a hash string from say szName, the result is different than if I create the hash with a hard coded value of "User".

So I'm suspecting there to be some kind of string encoding issue when the strings are passed into the DLL, but I'm not finding any way to fix this issue so I can correctly validate the serial using the szName, szCompany, and szSerial strings.

Does anybody know the solution?
Labels (1)
0 Kudos
(3) Replies
Level 2

I'm having the same issue. The string return value from my .net dll is different when I call it from InstallShield 09 vs using the .net dll in my .net application. In this case it's an encryption routine to encrypt passwords to store in a database. The same method is used by my application when creating new users. However, the result of the method is different depending on where I call it from. Has anyone solved this issue yet?

0 Kudos
Level 3

The following solution may help you.

Keep in mind the call to managed code is going through COM interop and apparently the buffer for the string is filled with null characters. I forget how I found this, I may have popped up a Messagebox with the string. You'd see '\0' filling the buffer, which I believe is 512 or 1024 characters.

I use the following method to strip the nulls:

/// We are getting strings from InstallScript, via COM Interop, that are buffered
/// with null characters such that the source string is 1024 chars, buffered with '\0'.
/// This method's job is to clean up these extra nulls which cause various issues.

/// The sourceString is the string we want to 'clean up'
/// The 'cleaned up' string

private string CleanupNulls(string sourceString)
if(sourceString == null)
throw new ArgumentNullException("sourceString");

char[] trimArray = { '\0' };
return sourceString.Trim(trimArray);
0 Kudos
Level 4

I encountered the same issue. I placed my return value into a list first.Here is my code I used to fix the issue:

// Remove new line character from end of
szDelimiterSet = "\n";
StrGetTokens ( lstGuids, sValue, szDelimiterSet);
switch (szDelimiterSet)
case "\n":
szToken = "";
nResult = ListGetFirstString(lstGuids, szToken);

while (nResult != END_OF_LIST)
nPos = StrLength(szToken) - 1;
if (0 <= nPos) then
if (0x0D = szToken[nPos]) then
szToken[nPos] = '\0';
ListSetCurrentString(lstGuids, szToken);

szToken = "";
nResult = ListGetNextString(lstGuids, szToken);
0 Kudos