/// <summary> /// Extracts the raw data of the resource from the module. /// </summary> /// <param name="hModule">The module handle.</param> /// <param name="resrouceName">The name of the resource.</param> /// <param name="resourceType">The type of the resource.</param> /// <returns>The resource raw data.</returns> private static byte[] GetResourceData(SafeModuleHandle hModule, ResourceName resourceName, ResourceTypes resourceType) { //Find the resource in the module. IntPtr hResInfo = IntPtr.Zero; try { hResInfo = DllImports.FindResource(hModule, resourceName.Value, resourceType); } finally { resourceName.Free(); } if (hResInfo == IntPtr.Zero) { throw new Win32Exception(); } //Load the resource. IntPtr hResData = DllImports.LoadResource(hModule, hResInfo); if (hResData == IntPtr.Zero) { throw new Win32Exception(); } //Lock the resource to read data. IntPtr hGlobal = DllImports.LockResource(hResData); if (hGlobal == IntPtr.Zero) { throw new Win32Exception(); } //Get the resource size. int resSize = DllImports.SizeofResource(hModule, hResInfo); if (resSize == 0) { throw new Win32Exception(); } //Allocate the requested size. byte[] buf = new byte[resSize]; //Copy the resource data into our buffer. Marshal.Copy(hGlobal, buf, 0, buf.Length); return(buf); }