【Patch】使用 patchwiz.dll 给产品打补丁包

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: 临时文件路径

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值