/// <summary> /// Loads the specified module. /// </summary> /// <param name="fileName"> /// A string that specifies the file name of the module to load. /// </param> /// <param name="flags"> /// The action to be taken when loading the module. /// </param> /// <returns> /// A <see cref="SafeModuleHandle"/> to the loaded module. /// </returns> public static SafeModuleHandle Load(string fileName, LoadLibraryExFlags flags = 0) { SafeModuleHandle handle = ResourceUnsafeNativeMethods.LoadLibraryEx( fileName, IntPtr.Zero, flags); if (handle.IsInvalid) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } return(handle); }
public static List <ResourceName> GetResourceTypesEx( SafeModuleHandle module) { var names = new List <ResourceName>(); EnumResourceTypesEx( module, (m, type, p) => { names.Add(ResourceName.FromPtr(type)); return(true); }, IntPtr.Zero, 0, 0); return(names); }
public static string LoadString(SafeModuleHandle hInstance, uint uID) { var buffer = new StringBuilder(64); while (true) { int count = LoadString(hInstance, uID, buffer, buffer.Capacity); if (count == 0) { return(null); } if (count < buffer.Capacity - 1) { break; } buffer.Capacity *= 2; } return(buffer.ToString()); }
public static T LoadResourceData <T>( this SafeModuleHandle module, ResInfoHandle resource) { var ptr = module.LoadResource(resource); var size = (long)ptr.ByteLength; var type = typeof(T); if (size != Marshal.SizeOf(type)) { return(default(T)); } if (type.IsValueType && !type.IsPrimitive) { return(Marshal.PtrToStructure <T>(ptr.DangerousGetHandle())); } if (type == typeof(sbyte) || type == typeof(byte)) { return((T)(object)Marshal.ReadByte(ptr.DangerousGetHandle())); } if (type == typeof(short) || type == typeof(ushort)) { return((T)(object)Marshal.ReadInt16(ptr.DangerousGetHandle())); } if (type == typeof(int) || type == typeof(uint)) { return((T)(object)Marshal.ReadInt32(ptr.DangerousGetHandle())); } if (type == typeof(long) || type == typeof(ulong)) { return((T)(object)Marshal.ReadInt64(ptr.DangerousGetHandle())); } throw new ArgumentException("Unable to marshal to type T."); }
public static extern HResult GetThemeStream( SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out IntPtr ppvStream, out uint pcbStream, SafeModuleHandle hInst);
public static ResInfoHandle FindResourceEx( this SafeModuleHandle module, ResourceName type, ResourceName name, short language) { return(ResourceUnsafeNativeMethods.FindResourceEx(module, type, name, language)); }
public static uint ResourceSize(this SafeModuleHandle module, ResInfoHandle resource) { return(ResourceUnsafeNativeMethods.SizeofResource(module, resource)); }
public static extern bool EnumResourceTypesEx( SafeModuleHandle hModule, EnumResTypeProc lpEnumFunc, IntPtr lParam, uint dwFlags, uint LangId);
public static extern int LoadString( SafeModuleHandle hInstance, uint uID, [Out] StringBuilder lpBuffer, int nBufferMax);
public static extern uint SizeofResource( SafeModuleHandle hModule, ResInfoHandle hResInfo);
public static extern ResDataHandle LoadResource( SafeModuleHandle hModule, ResInfoHandle hResInfo);
public static extern ResInfoHandle FindResource( SafeModuleHandle hModule, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ResourceNameMarshaler))] ResourceName lpName, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ResourceNameMarshaler))] ResourceName lpType);