/////////////////////////////////////////////////////////////////////// #if NATIVE && LIBRARY public static bool HasFlags( ModuleFlags flags, ModuleFlags hasFlags, bool all ) { if (all) { return((flags & hasFlags) == hasFlags); } else { return((flags & hasFlags) != ModuleFlags.None); } }
/// <summary> /// Opens a module. /// </summary> /// <returns>A <see cref="Module"/>.</returns> /// <param name="fileName">The name of the file containing the module, /// or <c>null</c> to obtain a <see cref="Module"/> representing the main /// program itself.</param> /// <param name="flags">The flags used for opening the module. This can /// be the logical OR of any of the <see cref="ModuleFlags"/></param> /// <remarks> /// First of all <see cref="#ctor"/> tries to open <paramref name="fileName"/> /// as a module. If that fails and <paramref name="fileName"/> has the ".la"-suffix /// (and is a libtool archive) it tries to open the corresponding module. If /// that fails and it doesn't have the proper module suffix for the platform /// (<see cref="Suffix"/>), this suffix will be appended and the corresponding /// module will be opended. If that fails and <paramref name="fileName"/> doesn't /// have the ".la"-suffix, this suffix is appended and <see cref="#ctor"/> tries /// to open the corresponding module. If eventually that fails as well, /// a <see cref="ModuleErrorException"/> is thrown. /// </remarks> /// <exception cref="ModuleErrorException"> /// On failure /// </exception> public static Module Open(string fileName, ModuleFlags flags = 0) { var fileName_ = GMarshal.StringToUtf8Ptr(fileName); try { lock (errorLock) { var ret_ = g_module_open(fileName_, flags); if (ret_ == IntPtr.Zero) { throw new ModuleErrorException(Error); } var ret = Opaque.GetInstance <Module> (ret_, Transfer.Full); return(ret); } } finally { GMarshal.Free(fileName_); } }
public static Module open(string file_name, ModuleFlags flags) { IntPtr handle = IntPtr.Zero; if (file_name == null) { handle = loader.GetModuleHandle(null); } else { handle = loader.LoadLibrary(file_name); } if (handle == IntPtr.Zero) { return(null); } return(new Module(handle)); }
/////////////////////////////////////////////////////////////////////// #region Public Constructors public NativeModule( string name, string group, string description, IClientData clientData, Interpreter interpreter, ModuleFlags flags, string fileName, long token ) { this.kind = IdentifierKind.NativeModule; this.id = Guid.Empty; this.name = name; this.group = group; this.description = description; this.clientData = clientData; this.interpreter = interpreter; this.flags = flags; this.fileName = fileName; this.token = token; }
/////////////////////////////////////////////////////////////////////// #region Static "Factory" Members public static ReturnCode Load( Interpreter interpreter, string name, ModuleFlags flags, string fileName, ref int loaded, ref IModule module, ref Result error ) { if (String.IsNullOrEmpty(fileName)) { error = "invalid file name"; return(ReturnCode.Error); } if (module != null) { error = "cannot overwrite valid native module"; return(ReturnCode.Error); } NativeModule newModule = new NativeModule( name, null, null, _Public.ClientData.Empty, interpreter, flags, fileName, 0); if (newModule.Load(ref loaded, ref error) == ReturnCode.Ok) { module = newModule; return(ReturnCode.Ok); } else { newModule.Dispose(); return(ReturnCode.Error); } }
private static extern IntPtr dlopen2(IntPtr filename, ModuleFlags flag);
private static extern IntPtr dlopen(string filename, ModuleFlags flag);
static extern IntPtr g_module_open(IntPtr fileName, ModuleFlags flags);