![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
|
Function problems
Hello again.
I have two questions: 1) I have some code in a function I call "deleteprocess()". I declared this as void, but then later changed it to int. In deleteprocess(), I have a list of Win32 API functions that I run, "DeleteFile() , and RemoveDirectory()". Now, I have three places where I want to run "deleteprocess()". One, ID_STUFF_GO, two, IDD_BUTTON, and three, IDD_DO_THEM_ALL. All three of my ID's are located in WndProc(), and they are all in the WM_CREATE handler. This is where I'm stumped. The function deleteprocess() works in ID_STUFF_GO, but not in the other two! I have it declared the same way in all three ID's. Could someone please explain this to me, and tell me how I might remidy the situation, as I don't want to write the whole code out in my program, which makes it bigger than it could be. 2) Does anyone know of any good .exe compressors, and is my program still able to be compressed if it has no resource file? Thanks in advance. Pr :banana:
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,203
Rep Power: 5
![]() |
For your first question, you haven't provided enough information. It would help if you specified what you mean when you say the function "works" and what it means when you say it "doesn't work" -- eg is it a problem with the code not compiling or does the code compile but not execute correctly? It would also help if you provided a small but complete example that illustrates your problem -- the process of producing such an example may help you find the problem and (if you still can't find it) peopel have more chance of helping. If you call your function twice in succession, is the second call likely to "not work"? Is the function body in the same source file as WndProc()? Is it declared in a header file?
There are a few good executable compressors out there, some commercial, some free. One freely available (in the sense of the gnu licence, not in terms of what you pay for it) that I like is UPX, available here. If you google for "executable file compression" you will find others. Most of the compressors that work with windows applications compress the executable code, as well as any resources (and some of the smarter ones discard resources that are not used by the program). So, yes, executables are able to be compressed regardless of whether they have a resource file or not --- the only difference is that the results can be a bit more obvious if you have resources. |
|
|
|
|
|
#3 | |
|
Professional Programmer
|
Quote:
When I say it works, I mean that the code compiles, and the program does what the function tells it to do. But in other places in the code, with the same function declared, the program will not run the function, it will (this is what it appears to me) ignore it, if you will. The function body is in the same source file as WndProc(). Here is the code: int deleteprocess()
{
HWND hwnd;
int ret = MessageBox(hwnd, "Please note that doing this might cause AIM to be unstable.\nDo you still wish to continue?", "Please note...", MB_YESNO | MB_ICONQUESTION);
if(ret == IDYES)
{
int get = MessageBox(hwnd, "May ViewpointKiller close AIM if it is running?", "Question", MB_YESNO | MB_ICONQUESTION);
if (get == IDYES)
{
char szName[100]="aim.exe";
int Process;
Process=KillProcess(szName);
}
if (get == IDNO)
{
MessageBox(hwnd, "Please close any instances of AIM running.", "Notice", MB_OK);
}
DeleteFile("Viewpoint\\Viewpoint Media Player\\AxMetaStream.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\AxMetaStream_.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\AxMetaStream_0302021C.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\ClassIDs.ini");
DeleteFile("Viewpoint\\Viewpoint Media Player\\ComponentMgr_03000F11.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\MetaStreamID.ini");
DeleteFile("Viewpoint\\Viewpoint Media Player\\MtsAxInstaller.exe");
DeleteFile("Viewpoint\\Viewpoint Media Player\\MTSDownloadSites.txt");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\AOLUserShell.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\Cursors.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\JpegReader.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\Mts3Reader.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\SceneComponent.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\SreeDMMX.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\SWFview.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\VMPvideo.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\BlueStreak.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\ExtremeShot.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\GifReader.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\LensFlares.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\Mts2Reader.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\ObjectMovie.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\ServiceComponent.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\VectorView.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\VETScriptInterpreter.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\VMPAudio.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\VMPSpeech.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\WaveletReader.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\NewComponents\\ZoomView.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\npViewpoint.dll");
DeleteFile("Viewpoint\\Viewpoint Media Player\\npViewpoint.xpt");
DeleteFile("C:\\Documents and Settings\\All users\\Application Data\\Viewpoint\\Viewpoint Media Player\\MetaStreamID.ini");
DeleteFile("AOL Instant Messenger\\Sysfiles\\viewpoint.exe");
DeleteFile("Viewpoint\\Viewpoint Media Player\\AolInstantInstallMMX_Win.mtj");
DeleteFile("Mozilla Firefox\\Plugins\\npViewpoint.dll");
DeleteFile("Mozilla Firefox\\Plugins\\npViewpoint.xpt");
DeleteFile("Viewpoint\\Viewpoint Media Player\\ComponentMgr.dll");
DeleteFile("MetaStream\\MetaStream3\\ComponentMgr_03000F11.dll");
DeleteFile("MetaStream\\MetaStream3\\MTSDownloadSites.txt");
DeleteFile("MetaStream\\MetaStream3\\Components\\JpegReader.dll");
DeleteFile("MetaStream\\MetaStream3\\Components\\Mts3Reader.dll");
DeleteFile("MetaStream\\MetaStream3\\Components\\SceneComponent.dll");
DeleteFile("MetaStream\\MetaStream3\\Components\\SreeDMMX.dll");
DeleteFile("MetaStream\\MetaStream3\\DownloadedComponents\\SWFView_Win.mtj");
RemoveDirectory("MetaStream\\MetaStream3\\Components");
RemoveDirectory("MetaStream\\MetaStream3\\NewComponents");
RemoveDirectory("MetaStream\\MetaStream3\\DownloadedComponents");
RemoveDirectory("MetaStream\\MetaStream3");
RemoveDirectory("MetaStream");
RemoveDirectory("Viewpoint\\Viewpoint Media Player\\Components");
RemoveDirectory("Viewpoint\\Viewpoint Media Player\\NewComponents");
RemoveDirectory("Viewpoint\\Viewpoint Media Player\\DownloadedComponents");
RemoveDirectory("Viewpoint\\Viewpoint Media Player");
RemoveDirectory("Viewpoint");
RegDelnode(HKEY_LOCAL_MACHINE, "SOFTWARE\\Viewpoint");
if (RegDelnode == -1)
{
MessageBox(hwnd, "Could not find registry key!", "Note", MB_OK);
}
RegDelnode(HKEY_LOCAL_MACHINE, "SOFTWARE\\MetaStream");
if (RegDelnode == -1)
{
MessageBox(hwnd, "Could not find registry key!", "Note", MB_OK);
}
RegDelnode(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\{03F998B2-0E00-11D3-A498-00104B6EB52E}");
if (RegDelnode == -1)
{
MessageBox(hwnd, "Could not find registry key!", "Note", MB_OK);
}
RegDelnode(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\{1B00725B-C455-4DE6-BFB6-AD540AD427CD}");
if (RegDelnode == -1)
{
MessageBox(hwnd, "Could not find registry key!", "Note", MB_OK);
}
RegDelnode(HKEY_LOCAL_MACHINE, "SOFTWARE\\MozillaPlugins\\@viewpoint.com/VMP");
if (RegDelnode == -1)
{
MessageBox(hwnd, "Could not find registry key!", "Note", MB_OK);
}
RegDelnode(HKEY_CURRENT_USER, "SOFTWARE\\Viewpoint");
if (RegDelnode == -1)
{
MessageBox(hwnd, "Could not find registry key!", "Note", MB_OK);
}
RegDelnode(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Viewpoint Media Player");
MessageBox(hwnd, "Now go to your Application Data folder and delete the Viewpoint folder from that.", "Almost Done..", MB_OK);
MessageBox(hwnd, "Viewpoint should now be dead.\nCheck your Program Files folder and registry for Viewpoint; it should be gone.", "Dead!", MB_OK | MB_ICONINFORMATION);
}
if (ret == IDNO)
{
// nothing
}
}Where it is declared: case ID_STUFF_GO:
{
int ret = MessageBox(hwnd, "Please note that doing this might cause AIM to be unstable.\nDo you still wish to continue?", "Please note...", MB_YESNO | MB_ICONQUESTION);
if(ret == IDYES)
{
int get = MessageBox(hwnd, "May ViewpointKiller close AIM if it is running?", "Question", MB_YESNO | MB_ICONQUESTION);
if (get == IDYES)
{
char szName[100]="aim.exe";
int Process;
Process=KillProcess(szName);
}
if (get == IDNO)
{
MessageBox(hwnd, "Please close any instances of AIM running.", "Notice", MB_OK);
}
deleteprocess();
RegDelnode(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Viewpoint Media Player");
MessageBox(hwnd, "Now go to your Application Data folder and delete the Viewpoint folder from that.", "Almost Done..", MB_OK);
MessageBox(hwnd, "Viewpoint should now be dead.\nCheck your Program Files folder and registry for Viewpoint; it should be gone.", "Dead!", MB_OK | MB_ICONINFORMATION);
EndDialog(hwnd, IDOK);
}
if (ret == IDNO)
{
// nothing
}
if(ret == -1)
MessageBox(hwnd, "Dialog failed!", "Error",
MB_OK | MB_ICONINFORMATION);
}
break;That compiles correctly, and the program runs it correctly. case IDD_DO_THEM_ALL:
{
deleteprocess();
}
break;That, even though it compiles and runs, the program "ignores" it and "won't" run it.
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,203
Rep Power: 5
![]() |
At a guess, the problem is that your initial code for ID_STUFF_GO does the same checks as are done in your deleteprocess() function .....
This means, to the user of the program, the response to ID_STUFF_GO will be to ask you TWICE if it can do it's stuff, and only delete all the files, directories, and registery entries if you respond in the affirmative BOTH times. You either need to take the checks out of the deleteprocess() function or out of the WndProc() entries [but not both]. If you want the response to some events to do "deleteprocess() plus a bit more", then use the return code from deleteprocess() to indicate what the response to the first dialog is (eg "return ret;" at the end of the function). It would also help if your indenting reflected what the code is doing, as it makes it harder to track down what the flow of control in your code really is. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jan 2006
Location: London
Posts: 1
Rep Power: 0
![]() |
Further to that, you should probably have distinct functions:
RemoveProcess() RemoveFiles() RemoveDirectories() RemoveRegEntries() If you use these in the WM_COMMAND handlers (or wherever they're used), it would be much clearer to yourself and maintainers what's going on. You have all the code there already, it's just that it's sort of all lumped together. |
|
|
|
|
|
#6 |
|
Professional Programmer
|
Thanks, grumpy and kbw. I fixed the problem, but the UPX compression utility kinda answered my second question. The reason I asked was because I wanted to take out some excess code, but now that I can compress the program, the excess code doesn't bother me now.
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,203
Rep Power: 5
![]() |
Hmmmm...... prm753. I'd suggest focusing first on getting your code into a form where it is both correct (i.e. does what you intend) and maintainable (eg someone looking at the code can understand what it does and change it without causing chaos) rather than focusing on the size of an executable file. A small executable file doesn't mean much if you don't achieve those two things and --- if you think about it --- the main problem in this thread came about because the code was incorrect and you didn't understand why.
Another thing to remember with executable file compressors is that the code has to be uncompressed before it can be executed. In practice, two of the most common overheads of a compressed executable are that they run slower (eg it takes time to do the decompression) and they use more memory (eg it is necessary to have both the decompressor engine and the original executable code in memory at once). And hard disk space (or space of a CD/DVD disk) is still cheaper than RAM ..... |
|
|
|
|
|
#8 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 822
Rep Power: 4
![]() |
In this code
HWND hwnd;
int ret = MessageBox(hwnd, "Please note that doing this might cause AIM to be unstable.\nDo you still wish to continue?", "Please note...", MB_YESNO | MB_ICONQUESTION);
if(ret == IDYES)You should either pass in the hwnd to the deleteprocess function, or use NULL instead of hwnd, or have the window handle in a global variable. |
|
|
|
|
|
#9 |
|
Professional Programmer
|
Thanks, grumpy, The Dark, and kbw for your assistance.
What was happening with my code was that my MessageBox()'s were failing. I put NULL instead of hwnd in my MessageBox()'s in deleteprocess() and it worked! My code went from 1200 lines to 850, and from 430 kb to 415 kb. grumpy, could you elaborate on what you said about an executeable that has been packed needs to be unpacked? I had a friend of mine test the packed version of ViewpointKiller and it worked for him. Hopefully his computer will boot up tommorow. j/k ![]() Thanks again.
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|