[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

WinAPI Dialog Resource

Posted on 2004-11-08
5
Medium Priority
?
1,041 Views
Last Modified: 2012-05-05
Using WinAPI, how do I get the Caption of a Dialog Resource in a DLL, without first creating the Dialog (Hidden or not) and then reading the caption.
0
Comment
Question by:ranunez
5 Comments
 
LVL 1

Expert Comment

by:SJohnson
ID: 12530254
I honestly don't believe you can.  Certainly not with WinAPI.  Maybe a hack or something could do it, but I wouldn't bet on it!!

You maybe able to load the DLL (using LoadLibrary) then try and load the dialog resouce into memory using a resource stream, then see if the caption is there.

You are going to have to load the library whether you want to or not anyway simply to get a handle.

Stu
0
 

Author Comment

by:ranunez
ID: 12533700
How would I reference the Dialog structure in Delphi once the resource is in memory.  I can load the DLL, load the Resource, and I think I know how to get the Caption, but I don't know how to reference the Dialog Resource Structure.
0
 
LVL 2

Expert Comment

by:Molando
ID: 12534592
Ok, I do not have time to write this, but this is how you should do it.
In your delphix\demo folder load in resXplorer

look at TExeImage.CreateImage

resexplorer will show you a hex dump of the Dialog. the easiestway to read this is to look at every alternate character.
I think you are looking for the first 3 or 4 readable characters in a row after the first 22 bytes. The title normally starts between 22 and 40 bytes in. There may be a better offset you can grab, but the readable character thing should work
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 2000 total points
ID: 12539060
hello  ranunez ,  There are two different kinds of Dialog Resources a DIALOG and a DIALOGEX , and they have different byte offsets for the same dialog data, so you will need to test the first byte for $40 or 1 . . ., the Caption for a Dialog is at the $18 byte offset in  DIALOG and at offset $20 in a DIALOGEX . . However the dialog may NOT have a Caption Data segment, so I would test the $16 for the $20 (Caption Identifier) and offset $1E for $20 in DIALOGEX to see if there is a caption . .

here is some code that I have used



procedure TForm1.GetDialogData(pRes: PByteArray);
var
pCaption: PWChar;
begin
if pRes = nil then Exit;
// the first Byte will be $40 for DIALOG or 1  for DIALOGEX
if (pRes[0] <> $40) and (pRes[0] <> 1) then
  begin
  ListBox2.Items.Add('ERROR - This is NOT a Dialog Res Data');
  ListBox2.Items.Add(' ');
  Exit;
  end;

if pRes[0] = $40 then // for  DIALOG  type
  begin
  if pRes[$16] = $20 then
    begin
    pCaption := @pRes[$18];
    ListBox2.Items.Add(pCaption);
    end else
    ListBox2.Items.Add('  ***, NO Caption in Dialog');
  ListBox2.Items.Add('Left - '+IntToStr(PWord(@pRes[$A])^));
  ListBox2.Items.Add('Top - '+IntToStr(PWord(@pRes[$C])^));
  ListBox2.Items.Add('Width - '+IntToStr(PWord(@pRes[$E])^));
  ListBox2.Items.Add('Height - '+IntToStr(PWord(@pRes[$10])^));
  end else
  begin  // for DIALOGEX  type
  if pRes[$1E] = $20 then
    begin
    pCaption := @pRes[$20];
    ListBox2.Items.Add(pCaption);
    end else
    ListBox2.Items.Add('  ***, NO Caption in Dialog');
  ListBox2.Items.Add('Left - '+IntToStr(PWord(@pRes[$12])^));
  ListBox2.Items.Add('Top - '+IntToStr(PWord(@pRes[$14])^));
  ListBox2.Items.Add('Width - '+IntToStr(PWord(@pRes[$16])^));
  ListBox2.Items.Add('Height - '+IntToStr(PWord(@pRes[$18])^));
  end;

ListBox2.Items.Add(' ');
end;


procedure TForm1.sbut_GetResDialogClick(Sender: TObject);
var
hResLib: THandle;
ResStream1: TResourceStream;
begin
hResLib := LoadLibrary('E:\nSetup.dll');
if hResLib = 0 then
  begin
  ShowMessage('ERROR - Could NOT Load Library');
  Exit;
  end;
try
ResStream1 := TResourceStream.Create(hResLib,'Second', RT_DIALOG);

GetDialogData(ResStream1.Memory);
FreeAndNil(ResStream1);
finally
FreeLibrary(hResLib);
end;

end;


 - - - - - - - - - - - - - - - - - - -  - - - - - - - -  - - - - - - -

this gives you the offsets for several data segments in a Dialog resource.
ask question if you need more Info
0
 
LVL 34

Expert Comment

by:Slick812
ID: 12539077
I should have said that the dialog strings (for caption and other) are in Wide Charater (2 byte)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 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