patchwiz.dll 有一个依赖项 mspatchc.dll, 这个两个dll 包含在 Microsoft Windows Software Development Kit (SDK). 如果你安装之后你会在C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin 文件夹下找到这两个dll。
但这两个dll 都是c++ 库,也就是说无法在我们的,net 项目里使用添加引用方式直接引用。在.net下要使用非托管代码,那就要借助 DllImport。
using System;
using System.Runtime.InteropServices;
namespace Microsoft.PatchCreationService.MspGenerator
{
class Program
{
public const uint LOGNONE = 0x00000000; //Write no messages to the log.
public const uint LOGINFO = 0x00000001; //Write informational messages to the log.
public const uint LOGWARN = 0x00000002; //Write warnings to the log.
public const uint LOGERR = 0x00000004; //Write error messages to the log.
public const uint LOGPERFMESSAGES = 0x00000008; //Write performance messages to the log.
public const uint UINONE = 0x00000000f; //Do not display the user interface.
public const uint UIALL = 0x00000010; //Display the user interface.
/// <summary>
/// Full log without UI.
/// </summary>
public const uint FULL = LOGINFO | LOGWARN | LOGERR | LOGPERFMESSAGES | UINONE;
static int Main(string[] args)
{
if (args.Length < 4)
{
return 1;
}
if (string.IsNullOrEmpty(args[0]) || string.IsNullOrEmpty(args[1])
|| string.IsNullOrEmpty(args[2]) || string.IsNullOrEmpty(args[3]))
{
return 1;
}
return UiCreatePatchPackageEx(args[0], args[1], args[2], IntPtr.Zero, args[3], true, FULL, 0);
}
[DllImport(dllName: "Patchwiz.dll", EntryPoint = "UiCreatePatchPackageEx", CharSet = CharSet.Unicode)]
internal static extern int UiCreatePatchPackageEx(string szPcpPath, string szPatchPath, string szLogPath, IntPtr hwndStatus, string szTempFolder, bool fRemoveTempFolderContents, UInt32 dwFlags, UInt32 dwReserved);
}
}
使用此方法的前提是
1) 你自己已经生成了 pcp 文件。
要注意的是:
1) szTempFolder 一定要不存在,否则会报错。
参数说明:
szPcpPath: pcp 文件路径
szPatchPath: 补丁包文件输出路径
szLogPath: 日志文件输出路径
szTempFolder: 临时文件路径