Hi my friend, I saw you search the vb code for changing icon of *.exe. Well, someone is wrote a good code in vb. I hope its ll be usefull to you, and solve your task of bad luck years seaching :nice: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=59973&lngWId=1 cheers!!!
I saw programs that can show you the ICONS in an executable files and so I thought if we can see them then definitely we can edit them as well. If we can edit them then there is a way to give them a different ICON to be displayed in the explorer.
how are you doing extract icon from this code PHP: #include<stdio.h> #include<windows.h> #include <stdlib.h> #include<iostream.h> int main(int argc, char* argv[]) { //lay handle cua File Icon HANDLE hIcon = CreateFile("D:\\1.ico", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (!hIcon) { printf("khong the tao icon"); return 1; } LPBYTE lpBuf; DWORD dwFileSize, dwBytesRead; dwFileSize = GetFileSize(hIcon, NULL); //lay kich thuoc cua no cout<<dwFileSize; lpBuf = (LPBYTE)malloc(dwFileSize); if (!lpBuf) { CloseHandle(hIcon); printf("khong the cap phat dong"); return 1; } ReadFile(hIcon, lpBuf, dwFileSize, &dwBytesRead, NULL); if (dwBytesRead != dwFileSize) { free(lpBuf); CloseHandle(hIcon); printf("khong the doc FIle"); return 1; } CloseHandle(hIcon); HANDLE hUpdateRes; hUpdateRes = BeginUpdateResource("D:\\1.exe", FALSE); if (hUpdateRes == NULL) { free(lpBuf); printf("khong the mo File"); return 1; } if (!UpdateResource(hUpdateRes, RT_ICON, MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), lpBuf, dwBytesRead)) { free(lpBuf); printf("khong the up date FIle"); return 1; } if (!EndUpdateResource(hUpdateRes, FALSE)) { free(lpBuf); printf("khong the ket thuc"); return 1; } free(lpBuf); printf("Hello World!\n"); return 0; }
shabbir, I am having trouble with the API's. The second parameter of FindResource, msdn says it has to be the resource's name, so if I am extracting an icon from an exe how am I supposed to know it's name ?? what did u do with the '#' thing lol ? Also the 3rd and 4th parameters of updateresource method, dunno much what to put there, especially the language thing!! Can you explain to me ? :$
The Name of the Icon is mainly an integer This Code should explain that Code: // Locate the ICON resource in the .EXE file. for(iLoop = 1;;iLoop++) { CString str; str.Format("#%d",iLoop); hRes = FindResource(hSrcExe, str, RT_ICON); if (hRes == NULL) continue ; else if(iLoop == 10) return; else break; } Checking only first 10 resources as this is only for tutorial purpose. Look at the code in the article and its pretty much self explanatory as well as commented.
Of course I have read the code and the comments, however, UpdateResource in my code always returns false and l have some questions that are still left unanswered and I would be very happy if you could answer them. Why did you need to Loop to find the icon ? Does this mean : a) a file has more than one icon ? b) FindResource checks resource one by one?? ..a string... an integer..or even a humain if it wants to, my problem is how to know what it is, I don't care it's type. I have no idea what to fill in this parameter and I don't understand what's the '#' for. What is MAKEINTID(1) ? some function I need to declare ?? And what's that thing with the language lol ? I mean, seriously, since when language is relevant to us ?? I want to cry
ah and.. sure I read all msdn however I'm not native english speaker and I sometimes can't understand especially with things I never dealt with before So if u can tke some of ur time and explain to me you would save my life note :I'm on VBNet
Actually yes. There are many Icons and even if you see one there are of many sizes like 16x16, 32x32 and so on. So its always more than one Icon. Yes it does it one by one based on the Id ( Integer ) you provide and tells you if its a valid resource of the type specified. If you know how the resources are stored in the RC file this would be easy. When you add any resource it gets assigned an Integer in the Resource.h file and so its always integer Its already defined and you do not need to do anything extra to declare it but just use it. I hope I have cleared some of your queries
Hi, I've found this code, and topic googleing, looking for a good example that will explain how to do the exact thing your example does I am using Visual Basic, and code is not working for me. I'm having problems with this function FindResource, as it wont find the resource. I opened my source EXE file with a tool and i've seen that my icon names are 30003, 30004, and 30005, so i used "#30004" to find icon. Code: hRes = FindResource(hSrc, "#30002", RT_ICON) It always returns 0. I tried all possibilities. I tried another EXE with Icon names 1,2,3...8. Function also failed. Have two questions: - What could be the cause for function failiure? - Is there any other way to do this?
I didn't mention that examples are not working for me. I compiled the example with source code too. Neither is working. :/
I have also tried to rewrite the code in VB and made everything correct but some function fail. I guess that this FindResource is not compatible with VB, or the declarations are not correct, maybe for this RT_ICON. I have started writing this code in c++ console application and it works now for me. But this example that is in MFC does not work. I dont understand why. This is my VB code with declarations: //Those are examples where i know my icon name is #1, but it can be #20000 also so you shold loop from 1 to ... 65536 maybe. Just guessing. Code: This is C++ code: hRes = FindResource(hSrc, MAKEINTRESOURCE(1), RT_ICON); //Works! Code: LPCTSTR lpName; lpName = "#1" hRes = FindResource(hSrc, lpName, RT_ICON); //Works And this is Visual Basic code that doesn work: Code: Private Declare Function FindResource Lib "kernel32.dll" Alias "FindResourceA" ( _ ByVal hInstance As Long, _ ByVal lpName As String, _ ByVal lpType As String) As Long Private Const RT_ICON As Long = 3& Code: Dim hRes as Long hRes = FindResource(hSrc, "#1", RT_ICON)
I can't open the two .zip files given at the end please help in my computer the file extension is changed to .php after downloading and even if the change the extension to .zip or .rar I can't open it...... what could be the possiible error..........
I also want to do this,i m already taking help of this thread but its not working. t think you done it so please provide me sample to change icon to exe. thanks.