private static extern void NativeInitialize(LogCallbackType logCallback, InvalidateViewsDlg invalidateCallback, out IntPtr engineInfo);
/// <summary> /// init game engine /// call it one time during startup on the UI thread.</summary> public static void Init() { // the full dll name can be loaded in a config when needed. if (s_libHandle != IntPtr.Zero) return; CriticalError = s_notInitialized; try { Uri uri = new Uri(System.Windows.Forms.Application.StartupPath); string dllDir = uri.LocalPath + "\\NativePlugin"; string dllName = "LvEdRenderingEngine.dll"; if (IntPtr.Size == 4) {// 32 bit s_fullDllName = dllDir + "\\x86\\" + dllName; } else if (IntPtr.Size == 8) {// 64 bit. s_fullDllName = dllDir + "\\x64\\" + dllName; } else { throw new Exception("unsupported address space"); } if (!File.Exists(s_fullDllName)) throw new FileNotFoundException(s_fullDllName); s_libHandle = NativeMethods.LoadLibrary(s_fullDllName); if (s_libHandle == IntPtr.Zero) { int hr = Marshal.GetHRForLastWin32Error(); Marshal.ThrowExceptionForHR(hr); } // verify entry points /* Type type = typeof(GameEngine); foreach (MethodInfo minfo in type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic)) { foreach( object obj in minfo.GetCustomAttributes(false)) { DllImportAttribute dllimport = obj as DllImportAttribute; if (dllimport != null) { string entryname = dllimport.EntryPoint; // verify entry point name. IntPtr fntPtr = NativeMethods.GetProcAddress(s_libHandle, entryname); if (fntPtr == IntPtr.Zero) throw new ArgumentException(string.Format("Can't find native function: {0}(...) in {1}", dllimport.EntryPoint, dllName)); break; } } } */ CriticalError = string.Empty; IntPtr data; s_invalidateCallback = new InvalidateViewsDlg(InvalidateViews); s_logInstance = new LogCallbackType(LogCallback); NativeInitialize(s_logInstance, s_invalidateCallback, out data); if (data != IntPtr.Zero) { string engineInfo = Marshal.PtrToStringUni(data); s_inist.PopulateEngineInfo(engineInfo); } // get SynchronizationContext for current thread. // Note: s_syncContext = SynchronizationContext.Current; //Application.AddMessageFilter(new MessageFilter()); Util3D.Init(); } catch (Exception e) { Console.WriteLine("loading dll: " + s_fullDllName); Console.WriteLine("Engine init failed: " + e.Message); CriticalError = e.Message; } }
/// <summary> /// init game engine /// call it one time during startup on the UI thread.</summary> public static void Init() { // the full dll name can be loaded in a config when needed. if (s_libHandle != IntPtr.Zero) { return; } CriticalError = s_notInitialized; try { Uri uri = new Uri(System.Windows.Forms.Application.StartupPath); string dllDir = uri.LocalPath + "\\NativePlugin"; string dllName = "LvEdRenderingEngine.dll"; if (IntPtr.Size == 4) {// 32 bit s_fullDllName = dllDir + "\\x86\\" + dllName; } else if (IntPtr.Size == 8) {// 64 bit. s_fullDllName = dllDir + "\\x64\\" + dllName; } else { throw new Exception("unsupported address space"); } if (!File.Exists(s_fullDllName)) { throw new FileNotFoundException(s_fullDllName); } s_libHandle = NativeMethods.LoadLibrary(s_fullDllName); if (s_libHandle == IntPtr.Zero) { int hr = Marshal.GetHRForLastWin32Error(); Marshal.ThrowExceptionForHR(hr); } // verify entry points /* * Type type = typeof(GameEngine); * * foreach (MethodInfo minfo in type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic)) * { * foreach( object obj in minfo.GetCustomAttributes(false)) * { * DllImportAttribute dllimport = obj as DllImportAttribute; * if (dllimport != null) * { * string entryname = dllimport.EntryPoint; * // verify entry point name. * IntPtr fntPtr = NativeMethods.GetProcAddress(s_libHandle, entryname); * if (fntPtr == IntPtr.Zero) * throw new ArgumentException(string.Format("Can't find native function: {0}(...) in {1}", dllimport.EntryPoint, dllName)); * break; * } * } * } */ CriticalError = string.Empty; IntPtr data; s_invalidateCallback = new InvalidateViewsDlg(InvalidateViews); s_logInstance = new LogCallbackType(LogCallback); NativeInitialize(s_logInstance, s_invalidateCallback, out data); if (data != IntPtr.Zero) { string engineInfo = Marshal.PtrToStringUni(data); s_inist.PopulateEngineInfo(engineInfo); } // get SynchronizationContext for current thread. // Note: s_syncContext = SynchronizationContext.Current; //Application.AddMessageFilter(new MessageFilter()); Util3D.Init(); } catch (Exception e) { Console.WriteLine("loading dll: " + s_fullDllName); Console.WriteLine("Engine init failed: " + e.Message); CriticalError = e.Message; } }
private static extern void NativeInitialize(LogCallbackType logCallback, InvalidateViewsDlg invalidateCallback);
private static extern void NativeInitialize(IntPtr handle, LogCallbackType callback);
private static extern void NativeInitialize(IntPtr handle,LogCallbackType callback);