예제 #1
0
        // I could just branch within the callbacks, but I want to accomodate Vista separately

        private Boolean GetResourceTypesCallbackEx(IntPtr moduleHandle, IntPtr pType, IntPtr userParam)
        {
            ResourceType type = new ResourceType(pType, this);

            UnderlyingAdd(_currentType = type);

            // enumerate all resources for that type
            NativeMethods.EnumResNameProc callback = new NativeMethods.EnumResNameProc(GetResourceNamesCallbackEx);
            NativeMethods.EnumResourceNamesEx(moduleHandle, pType, callback, IntPtr.Zero, NativeMethods.MuiResourceFlags.EnumLn, 0);

            return(true);
        }
예제 #2
0
        private Boolean GetResourceTypesCallback(IntPtr moduleHandle, IntPtr pType, IntPtr userParam)
        {
            Win32ResourceType type = new Win32ResourceType(pType, this);

            _types.Add(type);

            // enumerate all resources for that type
            NativeMethods.EnumResNameProc callback = new NativeMethods.EnumResNameProc(GetResourceNamesCallback);
            NativeMethods.EnumResourceNames(moduleHandle, pType, callback, IntPtr.Zero);

            return(true);
        }
예제 #3
0
        private bool GetResourceTypesCallback(IntPtr moduleHandle, IntPtr pType, IntPtr userParam)
        {
            var type = new ResourceType(pType, this);

            UnderlyingAdd(_currentType = type);

            // enumerate all resources for that type
            var callback = new NativeMethods.EnumResNameProc(GetResourceNamesCallback);

            NativeMethods.EnumResourceNames(moduleHandle, pType, callback, IntPtr.Zero);

            return(true);
        }
예제 #4
0
 private EmbeddedManifestReader(string path)
 {
     IntPtr hModule = IntPtr.Zero;
     try
     {
         hModule = NativeMethods.LoadLibraryExW(path, IntPtr.Zero, NativeMethods.LOAD_LIBRARY_AS_DATAFILE);
         if (hModule == IntPtr.Zero)
             return;
         NativeMethods.EnumResNameProc callback = new NativeMethods.EnumResNameProc(EnumResNameCallback);
         NativeMethods.EnumResourceNames(hModule, NativeMethods.RT_MANIFEST, callback, IntPtr.Zero);
     }
     finally
     {
         if (hModule != IntPtr.Zero)
             NativeMethods.FreeLibrary(hModule);
     }
 }
예제 #5
0
        public IEnumerable <UInt32> EnumerateIconResources(IntPtr resourceType, CancellationToken cancellationToken)
        {
            var resourceIds = new HashSet <UInt32>();

            NativeMethods.EnumResNameProc enumResNameProc = (module, type, value, param) =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return(false);
                }

                if (NativeExecutable.IsIntResource(value))
                {
                    resourceIds.Add((UInt32)Math.Abs(value.ToInt32()));
                }
                else
                {
                    // value is a pointer to a string which represants the name of the resource
                    var   resourceName = Marshal.PtrToStringAnsi(value);
                    Int32 resourceId;
                    if (NativeResourceDescriptor.TryParseResourceIdentifier(resourceName, out resourceId))
                    {
                        resourceIds.Add((UInt32)Math.Abs(resourceId));
                    }
                }

                return(true);
            };

            var result = NativeMethods.EnumResourceNames(this.Handle, resourceType, enumResNameProc, IntPtr.Zero);
            // This happens if the specified file contains no resources of the desired type.
            var lastWin32Error = Marshal.GetLastWin32Error();

            if (result || lastWin32Error == (Int32)NativeMethods.SystemErrorCode.ERROR_RESOURCE_TYPE_NOT_FOUND || lastWin32Error == (Int32)NativeMethods.SystemErrorCode.ERROR_RESOURCE_ENUM_USER_STOP)
            {
                return(resourceIds);
            }

            throw new Win32Exception(lastWin32Error);
        }
        private EmbeddedManifestReader(string path)
        {
            IntPtr hModule = IntPtr.Zero;

            try
            {
                hModule = NativeMethods.LoadLibraryExW(path, IntPtr.Zero, NativeMethods.LOAD_LIBRARY_AS_DATAFILE);
                if (hModule == IntPtr.Zero)
                {
                    return;
                }
                NativeMethods.EnumResNameProc callback = EnumResNameCallback;
                NativeMethods.EnumResourceNames(hModule, NativeMethods.RT_MANIFEST, callback, IntPtr.Zero);
            }
            finally
            {
                if (hModule != IntPtr.Zero)
                {
                    NativeMethods.FreeLibrary(hModule);
                }
            }
        }