cmake编译opencv3.2.0_CefSharp基于.Net Framework 4.0 框架编译

本次源码使用的是Github上CefSharp官方的79版本源码

修改后的源码在

https://github.com/w4ngzhen/CefSharp-DotNet40/tree/cefsharp/79​github.com

准备

IDE

Visual Studio 2017 Enterprise

Environment

Windows10 SDK

VC2013 Redistributale Package x86x64

组件清单

以下组件按照顺序进行编译最佳

基础层

  • CefSharp(C#)
  • CefSharp.Core(C++)
  • CefSharp.BrowserSubprocess.Core(C++)
  • CefSharp.BrowserSubprocess(C#)

UI层

  • CefSharp.WinForms(C#)

Example

  • CefSharp.Example
  • CefSharp.WinForms.Example

开始

建立一个名为CefSharp-DotNet4.0的空的解决方案(下文简称sln哈),咱们就开始吧!

CefSharp

首先把79版本的源码中的CefSharp库加入到sln中,形成如下的结构:

de5fe04ee019519c99c493899a030a8d.png

先不将框架切换为4.0尝试编译一下,出现报错提示:

1>------ Rebuild All started: Project: CefSharp, Configuration: Debug x64 ------
1>CSC : error CS7027: Error signing output with public key from file '..CefSharp.snk' -- File not found.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

检查79版本的源码发现,需要将CefSharp.snk文件放置到sln根目录下,这里照做,然后编译通过。

接着切换为4.0尝试编译,编译出现大量错误,仔细检查发现有如下几种:

1、CefSharp.Web.JsonString.FromObject函数的参数DataContractJsonSerializerSettings并不存在

原因:4.0还不存在该种形式的调用

解决办法:移除该方法的settings参数,移除DataContractJsonSerializerSettings构造函数的settings参数

2、CefSharp.Internals.ConcurrentMethodRunnerQueue.Enqueue方法中,调用了PropertyInfo.GetValue方法报错

原因:该PropertyInfo.GetValue方法在4.5及以上可以不传入第二个参数object[] index

解决办法:GetValue函数传入第二个参数为null即可

3、CefSharp.SchemeHandler.FolderSchemeHandlerFactory.ISchemeHandlerFactory.Create中WebUtility.UrlDecode报错

原因:该方法是对一般字符串编码为Url的实现,在4.5及以上中才有

解决办法:实现一个相同的功能的方法替换之,因为后续还有些处理转为4.0后的兼容问题的代码,所以本人在CefSharp增加了一个ExHelper命名空间,用于存放后续的扩展处理代码的Helper,这里首先增加一个WebUtilityHelper的处理类,该类有一个静态方法UrlDecode,其实现本人直接拷贝的.NET 4.7.2的实现,代码如下:

namespace CefSharp.ExHelper
{
    
    /// <summary>
    /// https://referencesource.microsoft.com/#System/net/System/Net/HttpListenerRequest.cs,80a5cbf6a66fa610
    /// </summary>
    public class WebUtilityHelper
    {
    
        private int _bufferSize;

        // Accumulate characters in a special array
        private int _numChars;
        private char[] _charBuffer;

        // Accumulate bytes for decoding into characters in a special array
        private int _numBytes;
        private byte[] _byteBuffer;

        // Encoding to convert chars to bytes
        private Encoding _encoding;

        internal WebUtilityHelper(int bufferSize, Encoding encoding)
        {
    
            _bufferSize = bufferSize;
            _encoding = encoding;

            _charBuffer = new char[bufferSize];
            // byte buffer created on demand
        }

        public static string UrlDecode(string encodedValue)
        {
    
            if (encodedValue == null)
                return null;

            return UrlDecodeInternal(encodedValue, Encoding.UTF8);
        }

        private static string UrlDecodeInternal(string value, Encoding encoding)
        {
    
            if (value == null)
            {
    
                return null;
            }

            int count = value.Length;
            WebUtilityHelper helper = new WebUtilityHelper(count, encoding);

            // go through the string's chars collapsing %XX and
            // appending each char as char, with exception of %XX constructs
            // that are appended as bytes

            for (int pos = 0; pos < count; pos++)
            {
    
                char ch = value[pos];

                if (ch == '+')
               
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值