public Byte[] GetResourceData(Win32ResourceLanguage resource) { if (resource.ParentName.ParentType.ParentImage != this) { throw new ArgumentException("Provided resource does not exist in this Image"); } // use FindResourceEx and LoadResource to get a handle to the resource // use SizeOfResource to get the length of the byte array // then LockResource to get a pointer to it. Use Marshal to get a byte array and take it from there IntPtr resInfo = NativeMethods.FindResourceEx(_moduleHandle, resource.ParentName.ParentType.TypePtr, resource.ParentName.NamePtr, resource.LanguageId); IntPtr resData = NativeMethods.LoadResource(_moduleHandle, resInfo); Int32 size = NativeMethods.SizeOfResource(_moduleHandle, resInfo); if (resData == IntPtr.Zero) { return(null); } IntPtr resPtr = NativeMethods.LockResource(resData); // there is no method to unlock resources, but they should be freed anyway Byte[] data = new Byte[size]; Marshal.Copy(resPtr, data, 0, size); NativeMethods.FreeResource(resData); return(data); }
private Boolean GetResourceLanguagesCallback(IntPtr moduleHandle, IntPtr pType, IntPtr pName, UInt16 langId, IntPtr userParam) { Win32ResourceType tempType = new Win32ResourceType(pType, this); // temp type used for finding the one to reference Win32ResourceType type = _types.Find(new Predicate <Win32ResourceType>(delegate(Win32ResourceType resType) { return(resType == tempType); })); if (type == null) { throw new InvalidOperationException("Resource language callback for a type that isn't known."); } Win32ResourceName tempName = new Win32ResourceName(pName, type); // temp Name used for finding the one to reference Win32ResourceName name = type.Names.Find(new Predicate <Win32ResourceName>(delegate(Win32ResourceName resName) { return(resName == tempName); })); if (name == null) { throw new InvalidOperationException("Resource names callback for a Name that isn't known."); } // Win32ResourceLanguage lang = new Win32ResourceLanguage(langId, name); name.Languages.Add(lang); return(true); }
public Win32ResourceOperation(Win32ResourceLanguage a, Win32ResourceLanguage b) { if (a == null && b == null) { throw new ArgumentException("Both resources cannot be null"); } A = a; B = b; }