加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 从C#调用MsiEnumRelatedProducts正在崩溃

发布时间:2020-12-14 02:08:36 所属栏目:Windows 来源:网络整理
导读:从C#调用MsiEnumRelatedProducts,我没有遇到任何麻烦.我在p / invoke定义上尝试了几个变种,但没有运气(out和ref).我认为问题是最后一个参数,它是一个LPTSTR,应该指向一个39个字符长的字符串. 这是pinvoke和电话: public static string EnumRelatedProducts(
从C#调用MsiEnumRelatedProducts,我没有遇到任何麻烦.我在p / invoke定义上尝试了几个变种,但没有运气(out和ref).我认为问题是最后一个参数,它是一个LPTSTR,应该指向一个39个字符长的字符串.

这是pinvoke和电话:

public static string EnumRelatedProducts(string UpgradeCode,int Index)
{
    string ProductCode;
    UInt32 rc = MsiEnumRelatedProducts(UpgradeCode,Index,out ProductCode);
    Console.WriteLine("Returned");
    if (rc != 0)
    {
        return string.Empty;
    }

    return ProductCode;
}

[DllImport("msi.dll",CharSet = CharSet.Auto)]
private static extern UInt32 MsiEnumRelatedProducts(string UpgradeCode,int reserved,int Index,out string ProductCode);

请注意,只有在传递的UpgradeCode至少安装了1个产品时才会发生崩溃.

解决方法

尝试这样声明:

[DllImport("msi.dll")]
private static extern uint MsiEnumRelatedProducts(
             string lpUpgradeCode,uint dwReserved,uint lProductIndex,StringBuilder lpProductBuf);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读