我想解决在C#中发布MSI快捷方式如下所述: How to parse "special" .lnk files, aka. MSI shortcuts aka. Windows Installer advertised shortcuts using C#C#dllimport的在Windows 7下,错误1603失败
[DllImport("msi.dll", CharSet = CharSet.Auto)]
private static extern UInt32 MsiGetShortcutTarget(
string szShortcutTarget,
[Out] StringBuilder szProductCode,
[Out] StringBuilder szFeatureId,
[Out] StringBuilder szComponentCode);
public static string ParseShortcut(string file)
{
StringBuilder product = new StringBuilder(MaxGuidLength + 1);
StringBuilder feature = new StringBuilder(MaxFeatureLength + 1);
StringBuilder component = new StringBuilder(MaxGuidLength + 1);
UInt32 res = MsiGetShortcutTarget(file, product, feature, component);
...
}
我使用VS 2010和不同的尝试“平台目标”和/或“目标框架”的设置。 MsiGetShortcutTarget总是返回1603(在安装过程中发生致命错误)在Windows 7下。
我试图用C++做同样的事情,我可以解决快捷方式,一切都很好。我还测试了一个msi.dll,我从Windows XP中复制,并且该dll可以使用C#代码解析快捷方式。我不知道为什么C#代码将无法与Windows 7下的msi.dll一起使用。
我用已知的产品GUID和组件GUID testet MsiGetComponentPath来解析C#中的目标路径,该DLL返回1603为MsiGetShortcutTarget和它完美的作品。所以只有MsiGetComponentPath在Windows 7下失败,我不知道它为什么出错。
char []只是另一个测试,应该是StringBuilder那就对了。 – Fry 2010-12-20 14:50:13