首页 > 技术文章 > CefSharp设置Cef库的目录

ztcad 2022-05-10 19:22 原文

CefSahrp默认只识别程序所在的目录,Cef库的文件比较多。如图:

如何指向到cef\x86目录呢,调用系统的API函数SetDllDirectory可实现。

首先获取Cef库的路径

public class CefHelper
{
    public static string GetCefPath()
    {
        var di = new DirectoryInfo(CommonHelper.MapPath("~/cef"));
        return Path.Combine(di.FullName, Environment.Is64BitProcess ? "x64" : "x86");
    }
}

 最后调用函数设置目录

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetDllDirectory(string lpPathName);

SetDllDirectory(CefHelper.GetCefPath()); 

 网上通常的做法是修改app.config,调用CefLibraryHandle加载,设置Locales等路径,这种方法相对来说更简单。

推荐阅读