Resource aus fremder Datei(exe, dll) laden?!
-
Hallo,
ich hoffe mal das meine Frage hier richtig ist.Wie kann ich die Resourcen aus einer fremden .exe oder .dll Datei auslesen (z.B. Bitmaps, Icons, etc.)?
-
hi,
also 1. ja, du bist hier richtig
2. wenns dir zu hoch ist, sag bescheidalso grundsätzlich gesagt: du benutzt die Funktion LoadImage, LoadBitmap, LoadIcon, ...oder allgemein LoadResource

ja, und um halt das handel zur deiner (also der anderen
) .exe-datei zu bekommen verwendest du (so, wie ich das sehe)LoadLibrary("C:\\lass_dir_was_einfallen.exe")so, ähm ...das müsste etwa hinkommen. ahja, hab noch en bsp. aus der msdn für dich:
HRSRC hResLoad; // handle to loaded resource HANDLE hExe; // handle to existing .EXE file HRSRC hRes; // handle/ptr. to res. info. in hExe HANDLE hUpdateRes; // update resource handle char *lpResLock; // pointer to resource data BOOL result; // Load the .EXE file that contains the dialog box you want to copy. hExe = LoadLibrary("hand.exe"); if (hExe == NULL) { ErrorHandler("Could not load exe."); } // Locate the dialog box resource in the .EXE file. hRes = FindResource(hExe, "AboutBox", RT_DIALOG); if (hRes == NULL) { ErrorHandler("Could not locate dialog box."); } // Load the dialog box into global memory. hResLoad = LoadResource(hExe, hRes); if (hResLoad == NULL) { ErrorHandler("Could not load dialog box."); } // Lock the dialog box into global memory. lpResLock = LockResource(hResLoad); if (lpResLock == NULL) { ErrorHandler("Could not lock dialog box."); } // Open the file to which you want to add the dialog box resource. hUpdateRes = BeginUpdateResource("foot.exe", FALSE); if (hUpdateRes == NULL) { ErrorHandler("Could not open file for writing."); } // Add the dialog box resource to the update list. result = UpdateResource(hUpdateRes, // update resource handle RT_DIALOG, // change dialog box resource "AboutBox", // dialog box name MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language lpResLock, // ptr to resource info SizeofResource(hExe, hRes)); // size of resource info. if (result == FALSE) { ErrorHandler("Could not add resource."); } // Write changes to FOOT.EXE and then close it. if (!EndUpdateResource(hUpdateRes, FALSE)) { ErrorHandler("Could not write changes to file."); } // Clean up. if (!FreeLibrary(hExe)) { ErrorHandler("Could not free executable."); }es ist doch immer schön, zu helfen.
lw
-
Vielen Dank, das hat mir schon sehr weitergeholfen.
Ich hab es so gemacht, das man mit Hilfe eines Dialoges auswählen kann welche Datei man öffnen möchte.
Nun bin ich aber auf das Problem gestoßen, das einige Dateien nicht geladen werden können (z.B.die Datei icqrt.dll aus dem ICQ Ordner) wenn sich mein Programm nicht im selben Ordner wie die Datei befindet.
Gibt es irgendwie eine Möglichkeit das Problem zu beheben?
-
Dann scheinst du wohl keine absoluten Pfade zu verwenden

-
GetLastError() verrät bestimmt was dazu

-
Doch, doch, tu ich.
Hab soeben eine Lösung gefunden:
LoadLibraryEx("C:\\Beispiel.dll",NULL,LOAD_WITH_ALTERED_SEARCH_PATH);Damit werden alle Dateien, die von der zu ladenen Datei(hier Beispiel.dll) geladen werden ,in dem Pfad gesucht, der der Funktion im ersten Parameter mit übergeben wird (hier C:\)
oder wie msdn dazu sagt:LOAD_WITH_ALTERED_SEARCH_PATH:
If this value is used, and lpFileName specifies a path, the system uses the alternate file search strategy discussed in the Remarks section to find associated executable modules that the specified module causes to be loaded.Was ebenfalls als 3 Parameter gehen müsste ist DONT_RESOLVE_DLL_REFERENCES. Das bewirkt das nur die angegebene Datei geladen wird und keine weiteren.
Habs aber nocht nicht ausprobiert, daher weiß ich nicht ob es geht.Quelle: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/loadlibraryex.asp