Solved

Reading the caption/title of a resource number in shell32.dll

Posted on 2004-10-12
4
221 Views
Last Modified: 2010-04-05
Hi Everyone,

I am new to Win 32 API programming and I am trying to read and then display the caption/title of a resource number in the shell32.dll file.

Any help will be greatly appreciated.

Thank you
0
Comment
Question by:clekkas
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
SJohnson earned 150 total points
ID: 12293065
This will return all resources in a given file:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, PAGSmrtBtn;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function enumResNamesProc(module: HMODULE; restype, resname: PChar;
  list: TStrings): Integer; stdcall;
begin
  if HiWord(Cardinal(resname)) <> 0 then
    list.Add('  ' + resname)
  else
    list.Add(Format('  #%d', [loword(Cardinal(resname))]));
  Result := 1;
end;

Function StockResourceType(restype: PChar): string;
const
  restypenames: Array [1..22] of String =
    ( 'RT_CURSOR', //       = MakeIntResource(1);
      'RT_BITMAP', //       = MakeIntResource(2);
      'RT_ICON',   //       = MakeIntResource(3);
      'RT_MENU',   //       = MakeIntResource(4);
      'RT_DIALOG', //       = MakeIntResource(5);
      'RT_STRING', //       = MakeIntResource(6);
      'RT_FONTDIR',//       = MakeIntResource(7);
      'RT_FONT',   //       = MakeIntResource(8);
      'RT_ACCELERATOR',//   = MakeIntResource(9);
      'RT_RCDATA', //       = MakeIntResource(10);
      'RT_MESSAGETABLE',//  = MakeIntResource(11);
      // DIFFERENCE = 11;
      'RT_GROUP_CURSOR',// = MakeIntResource(DWORD(RT_CURSOR +7DIFFERENCE));
      'UNKNOWN',        // 13 not used
      'RT_GROUP_ICON',  //   = MakeIntResource(DWORD(RT_ICON +DIFFERENCE));
      'UNKNOWN',        // 15 not used
      'RT_VERSION',     // = MakeIntResource(16);
      'RT_DLGINCLUDE',  // = MakeIntResource(17);
      'UNKNOWN',
      'RT_PLUGPLAY',    // = MakeIntResource(19);
      'RT_VXD',         // = MakeIntResource(20);
      'RT_ANICURSOR',   // = MakeIntResource(21);
      'RT_ANIICON'     // = MakeIntResource(22);
    );
var
  resid: Cardinal absolute restype;
begin
  if resid in [1..22] then
    Result := restypenames[resid]
  else
    Result := 'UNKNOWN';
end;


function enumResTypesProc(module: HMODULE; restype: PChar; list: TStrings): Integer; stdcall;
begin
  if HiWord(Cardinal(restype)) <> 0 then
    list.Add(restype)
  else
    list.Add(Format('Stock type %d: %s', [LoWord(Cardinal(restype)),
      StockResourcetype(restype)]));
  EnumResourceNames(module, restype, @enumResNamesProc, Integer(list));
  Result := 1;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Hnd: Cardinal;
  FName: String;
begin
  memo1.Clear;
  with TOpenDialog.Create(nil) do
    try
      Filter := 'Files|*.EXE;*.DLL;*.OCX';
      if not Execute then
        Exit;
      FName := Filename;
    finally
      Free;
    end;

  Hnd := LoadLibrary(pChar(FName));
  if not EnumResourceTypes(Hnd, @enumResTypesProc, Integer(memo1.Lines)) then
    memo1.Lines.Add(Format('GetLastError= %8.8x', [GetLastError]))
  else
    memo1.Lines.Add('Successful');
  FreeLibrary(Hnd);
end;

end.


To use, just drop a TMemo and a TButton on a form and link the TButton's OnClick event to the Button1Click procedure.

Stu.
0
 

Author Comment

by:clekkas
ID: 12308866
Thanks Stu.

Let me give it a try and if it works I will give you full points.

Thanks once again
0
 

Author Comment

by:clekkas
ID: 12440670
Hi Stu,

Thanks that did the trick. sorry for the delay.

0
 
LVL 1

Expert Comment

by:SJohnson
ID: 12441701
No worries. Glad to have helped.

Stu
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now