problem in updating the icon
-
Hi all, i want to replace a exe default icon with any other icon. i have written this code to do this
HANDLE hFile;
DWORD dwFileSize, dwBytesRead;
LPBYTE lpBuffer;
HANDLE hResource;HRSRC hRes; // handle/ptr. to res. info. in hExe
HANDLE hUpdateRes; // update resource handle
char *lpResLock; // pointer to resource data
HRSRC hResLoad; // handle to loaded resource
BOOL result;
HMODULE hSrcExe,hDestExe;
int iLoop;hFile = CreateFile("E:\\icon.ico",
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);if (INVALID_HANDLE_VALUE != hFile)
{
dwFileSize = GetFileSize(hFile, NULL);
lpBuffer = new BYTE[dwFileSize];
int aa = ReadFile(hFile, lpBuffer, dwFileSize, &dwBytesRead, NULL);
hResource = BeginUpdateResource("E:\\xyz.exe", FALSE);if (NULL != hResource) { if (UpdateResource(hResource, RT\_ICON, MAKEINTRESOURCE(1), MAKELANGID(LANG\_NEUTRAL, SUBLANG\_DEFAULT), (LPVOID) lpBuffer, dwFileSize) != FALSE) { EndUpdateResource(hResource, FALSE); } }
}
but its not updating the icon... I am not getting where is the problem. Can anybody help me in this... Thanks in advance
-
Hi all, i want to replace a exe default icon with any other icon. i have written this code to do this
HANDLE hFile;
DWORD dwFileSize, dwBytesRead;
LPBYTE lpBuffer;
HANDLE hResource;HRSRC hRes; // handle/ptr. to res. info. in hExe
HANDLE hUpdateRes; // update resource handle
char *lpResLock; // pointer to resource data
HRSRC hResLoad; // handle to loaded resource
BOOL result;
HMODULE hSrcExe,hDestExe;
int iLoop;hFile = CreateFile("E:\\icon.ico",
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);if (INVALID_HANDLE_VALUE != hFile)
{
dwFileSize = GetFileSize(hFile, NULL);
lpBuffer = new BYTE[dwFileSize];
int aa = ReadFile(hFile, lpBuffer, dwFileSize, &dwBytesRead, NULL);
hResource = BeginUpdateResource("E:\\xyz.exe", FALSE);if (NULL != hResource) { if (UpdateResource(hResource, RT\_ICON, MAKEINTRESOURCE(1), MAKELANGID(LANG\_NEUTRAL, SUBLANG\_DEFAULT), (LPVOID) lpBuffer, dwFileSize) != FALSE) { EndUpdateResource(hResource, FALSE); } }
}
but its not updating the icon... I am not getting where is the problem. Can anybody help me in this... Thanks in advance
You do not check the return status from your commands, apart from not executing the
UpdateResource() `or` EndUpdateResource()
functions if an error occurs. You should run your code through the debugger to see if everything gets executed correctly, and if not, check any error codes by usingGetLastError()
.txtspeak is the realm of 9 year old children, not developers. Christian Graus
-
You do not check the return status from your commands, apart from not executing the
UpdateResource() `or` EndUpdateResource()
functions if an error occurs. You should run your code through the debugger to see if everything gets executed correctly, and if not, check any error codes by usingGetLastError()
.txtspeak is the realm of 9 year old children, not developers. Christian Graus
i have seen that everthing is executing fine, then also icon is not getting replaced.
-
i have seen that everthing is executing fine, then also icon is not getting replaced.
learningvisualc wrote:
i have seen that everthing is executing fine, then also icon is not getting replaced.
Sorry, but I cannot think of anything else to suggest, other than to check that you are using the correct resource id in the destination executable. If each function returns success status then it should work.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
-
Hi all, i want to replace a exe default icon with any other icon. i have written this code to do this
HANDLE hFile;
DWORD dwFileSize, dwBytesRead;
LPBYTE lpBuffer;
HANDLE hResource;HRSRC hRes; // handle/ptr. to res. info. in hExe
HANDLE hUpdateRes; // update resource handle
char *lpResLock; // pointer to resource data
HRSRC hResLoad; // handle to loaded resource
BOOL result;
HMODULE hSrcExe,hDestExe;
int iLoop;hFile = CreateFile("E:\\icon.ico",
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);if (INVALID_HANDLE_VALUE != hFile)
{
dwFileSize = GetFileSize(hFile, NULL);
lpBuffer = new BYTE[dwFileSize];
int aa = ReadFile(hFile, lpBuffer, dwFileSize, &dwBytesRead, NULL);
hResource = BeginUpdateResource("E:\\xyz.exe", FALSE);if (NULL != hResource) { if (UpdateResource(hResource, RT\_ICON, MAKEINTRESOURCE(1), MAKELANGID(LANG\_NEUTRAL, SUBLANG\_DEFAULT), (LPVOID) lpBuffer, dwFileSize) != FALSE) { EndUpdateResource(hResource, FALSE); } }
}
but its not updating the icon... I am not getting where is the problem. Can anybody help me in this... Thanks in advance
Try looking up the WM_SETICON message on the MSDN site, "An application sends the WM_SETICON message to associate a new large or small icon with a window. The system displays the large icon in the ALT+TAB dialog box, and the small icon in the window caption."