[C++] Resource in file updaten

Pagina: 1
Acties:

  • cobratbq
  • Registratie: Maart 2001
  • Laatst online: 17-12-2015
Gelezen documentatie:
http://msdn.microsoft.com..._win32_Updating_Resources

C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
HMODULE hExe;        // handle to existing .EXE file 
HRSRC hResLoad;
HANDLE hUpdateRes;  // update resource handle 
void *lpResLock;    // pointer to resource data 
char iconfile[] = "c:\\explorer.exe";
char exefile[] = "test2.exe";

hExe = LoadLibrary(iconfile); 
if (hExe == NULL) 
    MessageBox("Could not load exe.");

hResLoad = (HRSRC) ExtractIcon(NULL,iconfile,0);
if( hResLoad == NULL )
    MessageBox("Errortje!");

icn_icon.SetIcon((HICON)hResLoad);

lpResLock = LockResource(hResLoad);
if (lpResLock == NULL) 
    MessageBox("Could not lock dialog box.");

//HIER BEGINT HET PROBLEEM, TRUE GEEFT AAN DAT DE RESOURCE
//OVERSCHREVEN MOET WORDEN
hUpdateRes = BeginUpdateResource(exefile,TRUE);
if( hUpdateRes == NULL )
        MessageBox("Could not begin Update");

//BIJ DEZE FUNCTIE GAAT HET FOUT
UpdateResource(hUpdateRes,
    RT_ICON,
    MAKEINTRESOURCE(0),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
    hResLoad,                   // ptr to resource info 
    SizeofResource(hExe,hResLoad)
); // size of resource info.

//HIER WORDEN DE WIJZINGEN DOORGEVOERD DISCARD=FALSE
if (!EndUpdateResource(hUpdateRes, FALSE)) 
    MessageBox("Could not write changes to file.");

DestroyIcon((HICON)hResLoad);
// Clean up. 
if (!FreeLibrary(hExe))
    MessageBox("Could not free executable.");


Wat doe ik hier fout?
Het probleem zit in het gedeelte van UpdateResource?
Om precies te zijn zit het probleem in de functie UpdateResource.
Ik wil in een exe-bestand het icoontje veranderen adhv dit programma.
Hij laadt momenteel het bestandje van explorer.exe (en laat deze zien)
Alles gaat goed totdat het bestandje test2.exe aangepast wordt met het nieuwe icoon en dan krijg ik een foutmelding.
Het bestand test2.exe wordt ook gelijk onbruikbaar.

(Ik gebruik Visual C++ 2003)

[ Voor 55% gewijzigd door cobratbq op 07-09-2003 20:41 ]

One ring to rule them all, one ring to find them, one ring to bring them all, and in darkness bind them...


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 04:06

.oisyn

Moderator Devschuur®

Demotivational Speaker

C++:
1
2
3
4
5
6
7
UpdateResource(hUpdateRes, 
    RT_ICON, 
    MAKEINTRESOURCE(0), 
    MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), 
    hResLoad,                   // ptr to resource info  
    SizeofResource(hExe,hResLoad) 
); // size of resource info. 


die hResLoad op regel 5 moet natuurlijk wel lpResLock zijn

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • cobratbq
  • Registratie: Maart 2001
  • Laatst online: 17-12-2015
sorry, foutje is erin geslopen door het experimenteren. Helaas haalt het niet uit als ik van hResLoad lpResLock maak.

One ring to rule them all, one ring to find them, one ring to bring them all, and in darkness bind them...


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 04:06

.oisyn

Moderator Devschuur®

Demotivational Speaker

Wat is die foutmelding die je krijgt?

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • cobratbq
  • Registratie: Maart 2001
  • Laatst online: 17-12-2015
Foutmelding: Als ik het programma sluit, dus niet gelijk bij het starten van de UpdateFunctie, timerun MFC Application windowtje met Debug en Close button.

Als ik in de MS IDE zit:
2x "Unhandled exception at 0x77f7f570 in timerun.exe: User breakpoint."
(Deze melding komt wel direct als ik de functie aanroep)

Het bestand test2.exe wordt niet gebruikt, dus het programma heeft volle toegang.
Test2.exe is ook een correct executable-bestand, dus dat veroorzaakt als het goed is ook geen problemen.

Verder is de functie voor het grootste gedeelte overgenomen uit het voorbeeld van Microsoft (zie hyperlink bovenaan in post)

[ Voor 38% gewijzigd door cobratbq op 07-09-2003 20:45 ]

One ring to rule them all, one ring to find them, one ring to bring them all, and in darkness bind them...