public void CleanUpNativeData(IntPtr pNativeData) { if (!ResourceUnsafeNativeMethods.IS_INTRESOURCE(pNativeData)) { Marshal.FreeCoTaskMem(pNativeData); } }
public static ResourceBuffer LoadResource( this SafeModuleHandle module, ResInfoHandle resource) { if (resource.IsInvalid) { throw new ArgumentException("Invalid resource info handle."); } ResDataHandle data = ResourceUnsafeNativeMethods.LoadResource(module, resource); if (data.IsInvalid) { throw new Win32Exception(); } uint size = ResourceUnsafeNativeMethods.SizeofResource(module, resource); if (size == 0) { throw new Win32Exception(); } ResourceBuffer ptr = ResourceUnsafeNativeMethods.LockResource(data); ptr.Initialize(size); return(ptr); }
public static ResourceName FromPtr(IntPtr ptr) { if (ResourceUnsafeNativeMethods.IS_INTRESOURCE(ptr)) { return(new ResourceName((short)ptr.ToInt64())); } return(new ResourceName(Marshal.PtrToStringUni(ptr))); }
/// <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 IntPtr MarshalManagedToNative(object ManagedObj) { if (!(ManagedObj is ResourceName)) { throw new ArgumentException(nameof(ManagedObj)); } var name = (ResourceName)ManagedObj; if (name.Name != null) { return(Marshal.StringToCoTaskMemUni(name.Name)); } return(ResourceUnsafeNativeMethods.MAKEINTRESOURCE(name.Id)); }
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)); }
protected override bool ReleaseHandle() { return(ResourceUnsafeNativeMethods.FreeLibrary(handle)); }