private static void Load()
        {
            CfxDebug.Announce();

            string libCfx, libCef;

            FindLibraries(out libCef, out libCfx);

            var loader = NativeFunctionLoader.Create();

            var libcfxPath = System.IO.Path.Combine(libCfxDirPath, libCfx);
            var libcefPath = System.IO.Path.Combine(libCefDirPath, libCef);

            // as of 3.2883, this must be in the path due to libcef dependencies.

            var path = Environment.GetEnvironmentVariable("PATH");

            Environment.SetEnvironmentVariable("PATH", libCefDirPath + ";" + path);

            libcefPtr = loader.LoadNativeLibrary(libcefPath);
            if (libcefPtr == IntPtr.Zero)
            {
                throw new CfxException("Unable to load libcef library " + libcefPath);
            }

            libcfxPtr = loader.LoadNativeLibrary(libcfxPath);
            if (libcfxPtr == IntPtr.Zero)
            {
                throw new CfxException("Unable to load libcfx library " + libcfxPath);
            }

            cfx_gc_handle_switch = SwitchGcHandle;

            int    platform;
            IntPtr release;
            IntPtr string_get_pointer;
            IntPtr string_destroy;
            IntPtr get_function_pointer;

            cfx_api_initialize_delegate api_initialize = (cfx_api_initialize_delegate)LoadDelegate(loader, libcfxPtr, "cfx_api_initialize", typeof(cfx_api_initialize_delegate));
            int retval = api_initialize(
                libcefPtr,
                Marshal.GetFunctionPointerForDelegate(cfx_gc_handle_switch),
                out platform,
                out CW_USEDEFAULT,
                out release,
                out string_get_pointer,
                out string_destroy,
                out get_function_pointer
                );

            if (retval != 0)
            {
                switch (retval)
                {
                case 1:
                    throw new CfxException("Unable to get native function cef_api_hash from libcef library");

                case 2:
                    Runtime.cfx_api_hash_delegate api_hash = (Runtime.cfx_api_hash_delegate)LoadDelegate(loader, libcefPtr, "cef_api_hash", typeof(Runtime.cfx_api_hash_delegate));
                    var apiHash = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(api_hash(0));
                    throw new CfxException("API hash mismatch: incompatible libcef.dll (" + apiHash + ")");
                }
            }

            PlatformOS = (CfxPlatformOS)platform;

            cfx_release              = (cfx_release_delegate)Marshal.GetDelegateForFunctionPointer(release, typeof(cfx_release_delegate));
            cfx_string_get_ptr       = (cfx_string_get_ptr_delegate)Marshal.GetDelegateForFunctionPointer(string_get_pointer, typeof(cfx_string_get_ptr_delegate));
            cfx_string_destroy       = (cfx_string_destroy_delegate)Marshal.GetDelegateForFunctionPointer(string_destroy, typeof(cfx_string_destroy_delegate));
            cfx_get_function_pointer = (cfx_get_function_pointer_delegate)Marshal.GetDelegateForFunctionPointer(get_function_pointer, typeof(cfx_get_function_pointer_delegate));

            cef_string_userfree_utf16_free = (cef_string_userfree_utf16_free_delegate)LoadDelegate(loader, libcefPtr, "cef_string_userfree_utf16_free", typeof(cef_string_userfree_utf16_free_delegate));

            CfxApiLoader.LoadCfxRuntimeApi();
            librariesLoaded = true;
        }
Exemple #2
0
        private static void Load()
        {
            CfxDebug.Announce();

            string libCfx, libCef;

            FindLibraries(out libCef, out libCfx);

            var loader = NativeFunctionLoader.Create();

            var libcfxPath = System.IO.Path.Combine(libCfxDirPath, libCfx);
            var libcefPath = System.IO.Path.Combine(libCefDirPath, libCef);

            libcefPtr = loader.LoadNativeLibrary(libcefPath);
            if(libcefPtr == IntPtr.Zero) {
                throw new CfxException("Unable to load libcef library " + libcefPath);
            }

            libcfxPtr = loader.LoadNativeLibrary(libcfxPath);
            if (libcfxPtr == IntPtr.Zero) {
                throw new CfxException("Unable to load libcfx library " + libcfxPath);
            }

            cfx_free_gc_handle = FreeGcHandle;

            int platform;
            IntPtr release;
            IntPtr string_get_pointer;
            IntPtr string_destroy;
            IntPtr get_function_pointer;

            cfx_api_initialize_delegate api_initialize = (cfx_api_initialize_delegate)LoadDelegate(loader, libcfxPtr, "cfx_api_initialize", typeof(cfx_api_initialize_delegate));
            int retval = api_initialize(libcefPtr, Marshal.GetFunctionPointerForDelegate(cfx_free_gc_handle), out platform, out CW_USEDEFAULT, out release, out string_get_pointer, out string_destroy, out get_function_pointer);

            if(retval != 0) {
                switch(retval) {
                    case 1:
                        throw new CfxException("Unable to get native function cef_api_hash from libcef library");
                    case 2:
                        cfx_api_hash_delegate api_hash = (cfx_api_hash_delegate)LoadDelegate(loader, libcefPtr, "cef_api_hash", typeof(cfx_api_hash_delegate));
                        var apiHash = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(api_hash(0));
                        throw new CfxException("API hash mismatch: incompatible libcef.dll (" + apiHash + ")");
                }
            }

            PlatformOS = (CfxPlatformOS)platform;

            cfx_release = (cfx_release_delegate)Marshal.GetDelegateForFunctionPointer(release, typeof(cfx_release_delegate));
            cfx_string_get_ptr = (cfx_string_get_ptr_delegate)Marshal.GetDelegateForFunctionPointer(string_get_pointer, typeof(cfx_string_get_ptr_delegate));
            cfx_string_destroy = (cfx_string_destroy_delegate)Marshal.GetDelegateForFunctionPointer(string_destroy, typeof(cfx_string_destroy_delegate));
            cfx_get_function_pointer = (cfx_get_function_pointer_delegate)Marshal.GetDelegateForFunctionPointer(get_function_pointer, typeof(cfx_get_function_pointer_delegate));

            cef_string_userfree_utf16_free = (cef_string_userfree_utf16_free_delegate)LoadDelegate(loader, libcefPtr, "cef_string_userfree_utf16_free", typeof(cef_string_userfree_utf16_free_delegate));

            CfxApiLoader.LoadCfxRuntimeApi();
            librariesLoaded = true;
        }