我正在使用VB.NET和InstallShield中的自定义操作在安装期间更新某些属性。
只要我不尝试在属性中读取或写入超过 21 个字符,一切正常,在这种情况下它会崩溃。
为了清楚起见,如果我通过 IS 将这个字符串“123456789112345678921”输入到属性中,然后尝试从 VB.NET 读取它,一切正常。如果我添加另一个字符并阅读它,它会崩溃。写作是相似的——如果我写(来自VB.NET)上面的第一个字符串就可以了。如果我添加另一个字符,它会失败。
我怀疑我的 MsiSetProperty 和 MsiGetProperty 定义不正确:
<DllImport(MSI_LIB, EntryPoint:="MsiSetProperty", CharSet:=CharSet.Auto)> _
Public Shared Function MsiSetProperty(hInstall As IntPtr, name As String, value As String) As UInteger
End Function
<DllImport(MSI_LIB, EntryPoint:="MsiGetProperty", CharSet:=CharSet.Auto)> _
Private Shared Function MsiGetProperty_Core(hInstall As IntPtr, szName As String, <Out> szValueBuf As StringBuilder, ByRef pchValueBuf As Integer) As Integer
End Function
Public Shared Function MSIGetProperty(hMSI As IntPtr, PropertyName As String) As String
Try
Dim MSIProp As New StringBuilder()
Dim stringSize As Integer = 256
Dim value As Integer = MsiGetProperty_Core(hMSI, PropertyName, MSIProp, stringSize)
Return MSIProp.ToString()
Catch
Return "-1"
End Try
End Function
这就是我访问字段的方式:
Public Property ReportServerURL As String
Get
Return MSIFunctions.MSIGetProperty(_msiHandle, "REPORTSERVERURL")
End Get
Set(value As String)
MSIFunctions.MsiSetProperty(_msiHandle, "REPORTSERVERURL", value)
End Set
End Property
关于发生了什么的任何想法?