Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
EnumResourceNames (kernel32)
 
.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern bool EnumResourceNames(IntPtr hModule, string lpszType,
   ResNameDelegate lpEnumFunc, IntPtr lParam);

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

  using System;
  using System.Runtime.InteropServices;

  namespace EnumResNames_CS
  {
   class Class1
   {
    private const uint RT_CURSOR = 0x00000001;
    private const uint RT_BITMAP = 0x00000002;
    private const uint RT_ICON = 0x00000003;
    private const uint RT_MENU = 0x00000004;
    private const uint RT_DIALOG = 0x00000005;
    private const uint RT_STRING = 0x00000006;
    private const uint RT_FONTDIR = 0x00000007;
    private const uint RT_FONT = 0x00000008;
    private const uint RT_ACCELERATOR = 0x00000009;
    private const uint RT_RCDATA = 0x0000000a;
    private const uint RT_MESSAGETABLE = 0x0000000b;

    private const uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002;

    [DllImport("kernel32.dll", SetLastError = true)]
    private static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, uint dwFlags);

    [DllImport("kernel32.dll", SetLastError = true)]
    private static extern bool FreeLibrary(IntPtr hModule);

    [DllImport("kernel32.dll", EntryPoint = "EnumResourceNamesW", CharSet = CharSet.Unicode, SetLastError = true)]
    static extern bool EnumResourceNamesWithName(
      IntPtr hModule,
      string lpszType,
      EnumResNameDelegate lpEnumFunc,
      IntPtr lParam);

    [DllImport("kernel32.dll", EntryPoint = "EnumResourceNamesW", CharSet = CharSet.Unicode, SetLastError = true)]
    static extern bool EnumResourceNamesWithID(
      IntPtr hModule,
      uint lpszType,
      EnumResNameDelegate lpEnumFunc,
      IntPtr lParam);

    private delegate bool EnumResNameDelegate(
      IntPtr hModule,
      IntPtr lpszType,
      IntPtr lpszName,
      IntPtr lParam);

    private static bool IS_INTRESOURCE(IntPtr value)
    {
      if ( ((uint) value) > ushort.MaxValue)
    return false;
      return true;
    }
    private static uint GET_RESOURCE_ID(IntPtr value)
    {
      if (IS_INTRESOURCE(value) == true)
    return (uint) value;
      throw new System.NotSupportedException("value is not an ID!");
    }
    private static string GET_RESOURCE_NAME(IntPtr value)
    {
      if (IS_INTRESOURCE(value) == true)
    return value.ToString();
      return Marshal.PtrToStringUni((IntPtr) value);
    }

    [STAThread]
    static void Main(string[] args)
    {
      IntPtr hMod = LoadLibraryEx(@"D:\Test\StringResource\Debug\StringResource.exe", IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE);
      if (EnumResourceNamesWithID(hMod, RT_ICON, new EnumResNameDelegate(EnumRes), IntPtr.Zero) == false)
      {
    Console.WriteLine("gle: {0}", Marshal.GetLastWin32Error());
      }
      FreeLibrary(hMod);
    }

    static bool EnumRes(IntPtr hModule,
      IntPtr lpszType,
      IntPtr lpszName,
      IntPtr lParam)
    {
      Console.WriteLine("Type: {0}", GET_RESOURCE_NAME(lpszType));
      Console.WriteLine("Name: {0}", GET_RESOURCE_NAME(lpszName));
      return true;
    }
   }
  }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions