Einzelnen Beitrag anzeigen

Benutzerbild von ATS3788
ATS3788

Registriert seit: 18. Mär 2004
Ort: Kriftel
646 Beiträge
 
Delphi XE Starter
 
#5

AW: Res --> DLL - dcc32 compalieren

  Alt 17. Jul 2012, 15:31
shmia
Zitat:
Nur das wäre ja zu einfach,
wo bleibt da der Spass

Das habe ich von C++ umgeschrieben
nur dummerweisse stimmt die grösse nicht bei

SizeofResource(hExe, hRes)


Delphi-Quellcode:
var
hResLoad : HGLOBAL; // handle to loaded resource
hExe : HMODULE; // handle to existing .EXE file
hRes : HRSRC; // handle/ptr. to res. info. in hExe
hUpdateRes : THANDLE; // update resource handle
lpResLock : pointer; // pointer to resource data
result : BOOL;
begin
// Load the .EXE/.DLL file that contains the ICONs you want to copy.
hExe := LoadLibraryEX('D:\Resource\Debug\Win32\testdll.dll' , 0 , LOAD_LIBRARY_AS_DATAFILE);
if hEXE = 0 then begin
raise Exception.Create('Could not load exe.');
exit;
end;
// Locate the ICON resource
hRes := FindResource(hExe, 'ico1', RT_GROUP_ICON );
if hRes = 0 then begin
  raise Exception.CreateFmt('Could not locate an ICON - %s' , ['ico0']);
    exit;
end;
// Load the ICON into global memory.
hResLoad := LoadResource(hExe, hRes);
if hResLoad = 0 then begin

raise Exception.Create('Could not load Icon.');
    exit;

end;

// Lock the ICON into global memory.
lpResLock := LockResource(hResLoad);
if lpResLock = nil then begin
  raise Exception.Create('Could not lock dialog box.');
    exit;
 end;


// Open the file to which you want to add the ICON resource.
hUpdateRes := BeginUpdateResource('D:\Resource\Debug\Win32\test7.dll' , FALSE);
if hUpdateRes = 0 then begin
     raise Exception.Create('Could not open file for writing.');
    exit;
 end;


 Button1.Caption := IntToStr(SizeofResource(hExe, hRes));

// Add the ICON resource to the update list.
result := UpdateResource(hUpdateRes, // update resource handle
    RT_GROUP_ICON, // change dialog box resource
    'zzy77', //yyz77 //MAKEINTRESOURCE(102),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language
    lpResLock, // ptr to resource info
    SizeofResource(hExe, hRes)); // size of resource info
 if not result then begin
     raise Exception.Create('Could not add resource.');
    exit;
 end;

// Write changes to the dll and then close it.
if not EndUpdateResource(hUpdateRes, FALSE) then begin
     raise Exception.Create('Could not write changes to file.');
    exit
end;
 // Clean up.
if not FreeLibrary(hExe) then begin

  raise Exception.Create('Could not free executable.');
    exit;

end;
Wo bin ich mal wieder blind.
Habe mir das mit ResEdit angeschaut, die Resource wird erstellt
nur leider zu wenig bytes.
Stört euch nicht an dialog box das habe ich noch nicht geändert
Martin MIchael

Geändert von ATS3788 (17. Jul 2012 um 16:05 Uhr)
  Mit Zitat antworten Zitat