Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi How to check if resource exists in PE and PE+ executable? (https://www.delphipraxis.net/181574-how-check-if-resource-exists-pe-pe-executable.html)

WojTec 26. Aug 2014 14:36

Delphi-Version: XE5

How to check if resource exists in PE and PE+ executable?
 
How to check if resource exists in PE and PE+ executable?. I have solution that result is depended on target Windows platform, because API require module handle:

Delphi-Quellcode:
function ResourceEntryExists(const AFileName, AResourceName: string): Boolean;
var
  hModule: Cardinal;
  pResource: Pointer;
  hResource: HRSRC;
  hData: Cardinal;
begin
  Result := False;

  pResource := nil;
  hModule := LoadLibraryEx(PChar(AFileName), 0, DONT_RESOLVE_DLL_REFERENCES);

  if hModule <> 0 then
  try
    hResource := FindResource(hModule, PChar(UpperCase(AResourceName)), RT_RCDATA);
    hData := LoadResource(hModule, hResource);

    if hData <> 0 then
    try
      pResource := LockResource(hData);
      Result := pResource <> nil;
    finally
      FreeResource(hData);
    end;
  finally
    FreeLibrary(hModule);
  end;
end;
I want to have one program version. So how to make it platform independet?

Neutral General 26. Aug 2014 14:42

AW: How to check if resource exists in PE and PE+ executable?
 
Hi,

Nice code, but MSDN says you shouldn't use DONT_RESOLVE_DLL_REFERENCES because it's deprecated.
Instead you should use LOAD_LIBRARY_AS_DATAFILE or LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE.

WojTec 26. Aug 2014 18:27

Re: How to check if resource exists in PE and PE+ executable?
 
It's simplier that I thought ;) Thanks :)


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:00 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz