Beispiel #1
0
 public UnmanagedLibrary(string file, UnmanagedLibraryAccess mode, ushort? languageID)
 {
     this.fileName = file;
     this.mode = mode;
     this.languageID = languageID;
     this.libraryInfo = (UnmanagedLibrary.LibraryInfo)null;
     lock (UnmanagedLibrary.librariesDict)
     {
         if (!UnmanagedLibrary.librariesDict.TryGetValue(file, out this.libraryInfo) && mode == UnmanagedLibraryAccess.Read)
         {
             this.libraryInfo = new UnmanagedLibrary.LibraryInfo();
             this.libraryInfo.File = file;
             this.libraryInfo.Handle = NativeMethods.LoadLibraryEx(file, IntPtr.Zero, 2U);
             if (this.libraryInfo.Handle == IntPtr.Zero)
                 throw new Win32Exception();
             UnmanagedLibrary.librariesDict[file] = this.libraryInfo;
         }
         if (this.libraryInfo != null)
         {
             if (mode != UnmanagedLibraryAccess.Read)
                 throw new InvalidOperationException(string.Format("Cannot open {0} for updating as it is already open for reading.", (object)file));
             ++this.libraryInfo.ReferenceCount;
         }
     }
     if (mode != UnmanagedLibraryAccess.Write)
         return;
     this.stringTables = new Dictionary<int, UnmanagedLibrary.StringTable>();
     this.resourceHandle = NativeMethods.BeginUpdateResource(file, false);
     if (this.resourceHandle == IntPtr.Zero)
         throw new Win32Exception();
 }
Beispiel #2
0
 public UnmanagedLibrary(string file, UnmanagedLibraryAccess mode, ushort?languageID)
 {
     this.fileName    = file;
     this.mode        = mode;
     this.languageID  = languageID;
     this.libraryInfo = (UnmanagedLibrary.LibraryInfo)null;
     lock (UnmanagedLibrary.librariesDict)
     {
         if (!UnmanagedLibrary.librariesDict.TryGetValue(file, out this.libraryInfo) && mode == UnmanagedLibraryAccess.Read)
         {
             this.libraryInfo        = new UnmanagedLibrary.LibraryInfo();
             this.libraryInfo.File   = file;
             this.libraryInfo.Handle = NativeMethods.LoadLibraryEx(file, IntPtr.Zero, 2U);
             if (this.libraryInfo.Handle == IntPtr.Zero)
             {
                 throw new Win32Exception();
             }
             UnmanagedLibrary.librariesDict[file] = this.libraryInfo;
         }
         if (this.libraryInfo != null)
         {
             if (mode != UnmanagedLibraryAccess.Read)
             {
                 throw new InvalidOperationException(string.Format("Cannot open {0} for updating as it is already open for reading.", (object)file));
             }
             ++this.libraryInfo.ReferenceCount;
         }
     }
     if (mode != UnmanagedLibraryAccess.Write)
     {
         return;
     }
     this.stringTables   = new Dictionary <int, UnmanagedLibrary.StringTable>();
     this.resourceHandle = NativeMethods.BeginUpdateResource(file, false);
     if (this.resourceHandle == IntPtr.Zero)
     {
         throw new Win32Exception();
     }
 }