public static bool TryCreateInstance(string dllName, string fullPath, out ExternalExporter exporter) { exporter = null; try { Assembly Library = Assembly.LoadFrom(fullPath); // look for a IScriptExporter Type[] types = Library.GetTypes(); foreach (Type type in types) { if (type.GetInterface(typeof(IScriptExporter).ToString()) != null) { IScriptExporter scriptExporter = Library.CreateInstance(type.ToString()) as IScriptExporter; CSharpExporter newExporter = new CSharpExporter(); newExporter.Library = Library; newExporter.m_exporter = scriptExporter; exporter = newExporter; return true; } } } catch(Exception) { return false; } return false; }
public static bool TryCreateInstance(string dllName, string fullPath, out ExternalExporter exporter) { CppExporter cppExporter = new CppExporter(); exporter = cppExporter; try { if (cppExporter.LibraryHandle == IntPtr.Zero) { cppExporter.LibraryHandle = NativMethods.LoadLibrary(dllName); } if (cppExporter.LibraryHandle != IntPtr.Zero) { cppExporter.ExportScriptFunc = new IntPtr(NativMethods.GetProcAddress(cppExporter.LibraryHandle, "ExportScript")); if (cppExporter.ExportScriptFunc == IntPtr.Zero) throw new Exception(""); cppExporter.exportScript = (ExportScriptDelegate)Marshal.GetDelegateForFunctionPointer( cppExporter.ExportScriptFunc, typeof(ExportScriptDelegate)); exporter = cppExporter; } } catch (Exception) { NativMethods.FreeLibrary(cppExporter.LibraryHandle); cppExporter = null; exporter = null; return false; } return cppExporter.LibraryHandle != IntPtr.Zero; }