icon changer

i cant make it to work, it only change the icon to default
can anyone help me ? thanks in advance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
DWORD read;
    DWORD dwSize;
    char* buffer;
    HANDLE hFile = CreateFile("icon1.ico", 
                           GENERIC_READ,      
                           0,                  
                           NULL,                 
                           OPEN_ALWAYS,        
                           FILE_ATTRIBUTE_NORMAL,
                           NULL);
                           
    dwSize = GetFileSize(hFile, NULL); 
    buffer = new char[dwSize];	
	
	ReadFile(hFile, buffer, dwSize, &read, NULL);
	CloseHandle(hFile);
	
	HANDLE hUpdateRes = BeginUpdateResource("sample.exe", FALSE);
	UpdateResource(hUpdateRes, RT_ICON, MAKEINTRESOURCE(1), 0, buffer, dwSize); 	
	EndUpdateResource(hUpdateRes, FALSE);
    
    delete[] buffer;	
	return 0;
Topic archived. No new replies allowed.