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
- :
- Re: MsiGetProperty doesnt work for long text
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 20, 2017
07:36 AM
MsiGetProperty doesnt work for long text
Hi,
I've an basic MSI Project with a custom action scheduled in the UI Sequence.
This action invokes a function of an C# Dll file stored in the binary table.
Inside of this function I use MsiGetProperty to retrieve a path (basically the SourceDir which was copied into an own property before) of the msi package. This works fine as long as the MSI is installed from a directory with a short path e.g: "C:\Test\"
If the path gets a bit longer (for example you copy the msi to the Windows Desktop, resulting in a path like "C:\Users\Administrator\Desktop\ProductName\Installx64\" -> so just about 50 Characters) the MsiGetProperty seems not to return the appropiate value anymore.
At this point I can see in the MSILog my property was set before and contains the correct value - I just can't get it.
The code I use looks like this:
[CODE]
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
private static extern int MsiGetProperty(IntPtr hInstall, string szName, [Out] StringBuilder szValueBuf, ref int pchValueBuf);
private static String GetPropertyStringValue(IntPtr hInstall, String PropertyName)
{
try
{
int BufferSize = 0;
int GetResult = 0;
StringBuilder sb = new StringBuilder();
GetResult = MsiGetProperty(hInstall, PropertyName, sb, ref BufferSize);
if (ERROR_MORE_DATA == GetResult)
{
var sb2 = new StringBuilder();
int FullSize = BufferSize + 1;
GetResult = MsiGetProperty(hInstall, PropertyName, sb2, ref FullSize);
sb = sb2;
}
return sb.ToString();
}
catch (Exception ex)
{
MsiSetProperty(hInstall, "ERRORMESSAGE", String.Format("{0}: {1}", PropertyName, "failed with ex"));
MsiSetProperty(hInstall, "ERRORMESSAGE", String.Format("{0}: {1}", PropertyName, ex.ToString()));
}
return string.Empty;
}[/CODE]
I tried a lot of things right now:
Using other charset, adding 2, 10, 20 instewaad of just 1 to the buffersize to ensure it is big enough.
I added some kind of "debug.Prints" into my ERRORMESSAGE property to check in the Msi Log if my function is called, check the returned Buffersize and so on.
I seems like any code below the 2nd call of MsiGetProperty is not executed (obviously I would expect an exception message in case of a runtime error), therefore I can't tell what's the returned result-value of that Api call.
The strange thing is this works fine until the property value is shorter than ~30 Characters.
Does anybody have an idea what I'm doing wrong or new to add here?
I've an basic MSI Project with a custom action scheduled in the UI Sequence.
This action invokes a function of an C# Dll file stored in the binary table.
Inside of this function I use MsiGetProperty to retrieve a path (basically the SourceDir which was copied into an own property before) of the msi package. This works fine as long as the MSI is installed from a directory with a short path e.g: "C:\Test\"
If the path gets a bit longer (for example you copy the msi to the Windows Desktop, resulting in a path like "C:\Users\Administrator\Desktop\ProductName\Installx64\" -> so just about 50 Characters) the MsiGetProperty seems not to return the appropiate value anymore.
At this point I can see in the MSILog my property was set before and contains the correct value - I just can't get it.
The code I use looks like this:
[CODE]
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
private static extern int MsiGetProperty(IntPtr hInstall, string szName, [Out] StringBuilder szValueBuf, ref int pchValueBuf);
private static String GetPropertyStringValue(IntPtr hInstall, String PropertyName)
{
try
{
int BufferSize = 0;
int GetResult = 0;
StringBuilder sb = new StringBuilder();
GetResult = MsiGetProperty(hInstall, PropertyName, sb, ref BufferSize);
if (ERROR_MORE_DATA == GetResult)
{
var sb2 = new StringBuilder();
int FullSize = BufferSize + 1;
GetResult = MsiGetProperty(hInstall, PropertyName, sb2, ref FullSize);
sb = sb2;
}
return sb.ToString();
}
catch (Exception ex)
{
MsiSetProperty(hInstall, "ERRORMESSAGE", String.Format("{0}: {1}", PropertyName, "failed with ex"));
MsiSetProperty(hInstall, "ERRORMESSAGE", String.Format("{0}: {1}", PropertyName, ex.ToString()));
}
return string.Empty;
}[/CODE]
I tried a lot of things right now:
Using other charset, adding 2, 10, 20 instewaad of just 1 to the buffersize to ensure it is big enough.
I added some kind of "debug.Prints" into my ERRORMESSAGE property to check in the Msi Log if my function is called, check the returned Buffersize and so on.
I seems like any code below the 2nd call of MsiGetProperty is not executed (obviously I would expect an exception message in case of a runtime error), therefore I can't tell what's the returned result-value of that Api call.
The strange thing is this works fine until the property value is shorter than ~30 Characters.
Does anybody have an idea what I'm doing wrong or new to add here?
(1) Reply
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Feb 22, 2017
12:51 AM
Hey,
was finally able to figure this out by myself.
In my case the default size of the StringBuilder was to small to contain the full value.
was finally able to figure this out by myself.
In my case the default size of the StringBuilder was to small to contain the full value.