从C#调用MsiEnumRelatedProducts崩溃 [英] Calling MsiEnumRelatedProducts from C# is crashing
本文介绍了从C#调用MsiEnumRelatedProducts崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从C#调用MsiEnumRelatedProducts一直没有麻烦.我已经尝试了一些关于p/invoke定义的变体,但是没有运气(out和ref).我认为问题是最后一个参数,它是一个LPTSTR,应该指向39个字符长的字符串.
I'm having no end of trouble calling MsiEnumRelatedProducts from C#. I've tried a couple of variations on the p/invoke definition but no luck (out and ref). I think the problem is the last parameter, which is an LPTSTR that is supposed to point to a string 39 characters long.
这是拨打电话的电话:
public static string EnumRelatedProducts(string UpgradeCode, int Index)
{
string ProductCode;
UInt32 rc = MsiEnumRelatedProducts(UpgradeCode, 0, 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个产品时,才会发生崩溃.
Note that the crash only occurs when the passed UpgradeCode has at least 1 installed product.
推荐答案
尝试这样声明:
[DllImport("msi.dll")]
private static extern uint MsiEnumRelatedProducts(
string lpUpgradeCode,
uint dwReserved,
uint lProductIndex,
StringBuilder lpProductBuf);
这篇关于从C#调用MsiEnumRelatedProducts崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文