WinAPI Dialog Resource

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.
ranunezAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SJohnsonCommented:
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
ranunezAuthor Commented:
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
MolandoCommented:
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
Slick812Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Slick812Commented:
I should have said that the dialog strings (for caption and other) are in Wide Charater (2 byte)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.