Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Installation 只能从VB.NET向InstallShield属性读/写21个字符_Installation_Windows Installer_Installshield_Custom Action_Dtf - Fatal编程技术网

Installation 只能从VB.NET向InstallShield属性读/写21个字符

Installation 只能从VB.NET向InstallShield属性读/写21个字符,installation,windows-installer,installshield,custom-action,dtf,Installation,Windows Installer,Installshield,Custom Action,Dtf,我正在使用VB.NET和InstallShield中的自定义操作来更新安装过程中的一些属性 只要我不尝试在属性中读取或写入超过21个字符,一切都正常,在这种情况下,它就会崩溃 为了清楚起见,如果我通过IS在属性中输入这个字符串“12345678912345678921”,然后尝试从VB.NET读取它,一切正常。如果我添加另一个字符并读取它,它就会崩溃。 写作是类似的-如果我写(从VB.NET)上面的第一个字符串,它就工作了。如果我添加另一个字符,它将失败 我怀疑MsiSetProperty和Ms

我正在使用VB.NETInstallShield中的自定义操作来更新安装过程中的一些属性

只要我不尝试在属性中读取或写入超过21个字符,一切都正常,在这种情况下,它就会崩溃

为了清楚起见,如果我通过IS在属性中输入这个字符串“12345678912345678921”,然后尝试从VB.NET读取它,一切正常。如果我添加另一个字符并读取它,它就会崩溃。 写作是类似的-如果我写(从VB.NET)上面的第一个字符串,它就工作了。如果我添加另一个字符,它将失败

我怀疑MsiSetProperty和MsiGetProperty的定义不正确:

_
公共共享函数MsiSetProperty(hInstall作为IntPtr,名称作为字符串,值作为字符串)作为UInteger
端函数
_
私有共享函数MsiGetProperty_Core(hInstall作为IntPtr,szName作为String,szValueBuf作为StringBuilder,ByRef pchValueBuf作为Integer)作为整数
端函数
公共共享函数MSIGetProperty(hMSI作为IntPtr,PropertyName作为String)作为String
尝试
将MSIProp作为新的StringBuilder()进行调整
Dim stringSize为整数=256
作为整数的Dim值=MsiGetProperty_核心(hMSI、PropertyName、MSIProp、stringSize)
返回MSIProp.ToString()
抓住
返回“-1”
结束尝试
端函数
这是我访问字段的方式:

公共属性ReportServerURL作为字符串
得到
返回MSIFunctions.MSIGetProperty(_msiHandle,“REPORTSERVERURL”)
结束
设置(值为字符串)
MSIFunctions.MsiSetProperty(_msiHandle,“REPORTSERVERURL”,值)
端集
端属性

有什么想法吗?

尝试使用DTF而不是dll导入。DTF是部署工具基础
——一组丰富的.NET程序集类,用于处理Windows Installer的所有方面和自定义操作。您不必处理所有COM或Win32死机,并且只能使用.NET类编写

我想您的实际问题与VB.NET如何导入dll文件的技术细节(可能是一些缓冲区大小问题)有关,但如果DTF解决了这个问题,我不会花任何时间

  • (快速浏览答案底部)

    • 问题在于我是如何阅读该房产的。您必须为传入数据预先分配空间。显然,没有在StringBuilder中指定空间,它只分配足够21个字符的空间

      我最初的(糟糕的)阅读方法是:

      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
      
      工作原理如下(请注意StringBuilder中的空间预分配)。我的默认值为256,但您可能可以输入您认为必要的任何值:

      Public Shared Function MSIGetProperty(hMSI As IntPtr, PropertyName As String) As String
          Try
              Dim stringSize As Integer = 256
              Dim MSIProp As New StringBuilder(stringSize) 'MUST pre-allocate storage
              Dim value As Integer = MsiGetProperty_Core(hMSI, PropertyName, MSIProp, stringSize)
              Return MSIProp.ToString()
          Catch
              Return "-1"
          End Try
      End Function
      

      美好的我不知道DTF。我将尝试并发布结果。您应该调用MsiGetProperty一次,获取更多错误数据,然后检查stringSize需要多少字节。创建一个该大小的字符串,然后再次调用它。或者只使用已经为您完成所有这些工作的DTF互操作库。:)