Einzelnen Beitrag anzeigen

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