AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi How to check if resource exists in PE and PE+ executable?
Thema durchsuchen
Ansicht
Themen-Optionen

How to check if resource exists in PE and PE+ executable?

Ein Thema von WojTec · begonnen am 26. Aug 2014 · letzter Beitrag vom 26. Aug 2014
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

How to check if resource exists in PE and PE+ executable?

  Alt 26. Aug 2014, 14:36
Delphi-Version: XE5
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?
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#2

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

  Alt 26. Aug 2014, 14:42
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.
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#3

Re: How to check if resource exists in PE and PE+ executable?

  Alt 26. Aug 2014, 18:27
It's simplier that I thought Thanks
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:35 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