FindWindow Problems (on Windows 98/ME)

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 4
Reputation: Haktivex is an unknown quantity at this point 
Solved Threads: 0
Haktivex Haktivex is offline Offline
Newbie Poster

FindWindow Problems (on Windows 98/ME)

 
1
  #1
Sep 2nd, 2006
Hello folks

Allow me to introduce myself. I am Haktivex, a programmer for a tool known as TibiCAM, used to record movies for an online game known as Tibia.

Now heres the issue. For a long time we supported all operating systems, Windows 98, ME, etc. However recently these operating systems have stopped working. Some things to note:

1. We switched compilers (Microsoft Visual C++ Express) - Originally was compiled on Visual C++ 6.0

2. Compiling on Visual C++ 2003 did not help either.

3. None of the FindWindow code was changed.

4. Works fine on XP, etc.

When running on Windows 98/ME, instead of FindWindow finding the Tibia client, instead it finds DLL files, usually something like directx files, and some people have reported it finding Gadu-Gadu (IM program) files.

I have considered that the issue could be caused by ansi/unicode but I have no grounds to confirm this consideration. It could also be the compilers. Would anybody suggest that the Visual C++ 6.0 be used? Or is there something we can change with our current compilers/IDE's to get support back?

Here is the single line of code that is giving us so much trouble:

  1. HWND hTemp = FindWindow("tibiaclient", NULL);

Thanks alot,
Haktivex.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 56
Reputation: Eddy Dean is an unknown quantity at this point 
Solved Threads: 3
Eddy Dean Eddy Dean is offline Offline
Junior Poster in Training

Re: FindWindow Problems (on Windows 98/ME)

 
1
  #2
Sep 2nd, 2006
I don't know why these errors occur, but you might want to try creating processsnapshots to find the handles.

This way is a bit harder, and it's much more code, but it might just work, right?


Greetz, Eddy
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 4
Reputation: Haktivex is an unknown quantity at this point 
Solved Threads: 0
Haktivex Haktivex is offline Offline
Newbie Poster

Re: FindWindow Problems (on Windows 98/ME)

 
0
  #3
Sep 2nd, 2006
Originally Posted by Eddy Dean View Post
I don't know why these errors occur, but you might want to try creating processsnapshots to find the handles.

This way is a bit harder, and it's much more code, but it might just work, right?


Greetz, Eddy
Hello,

Process Snapshots require (as far as I am concerned) the process id of an application, which can be found using FindWindow - which is causing us these troubles.

Regards,
Haktivex.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 56
Reputation: Eddy Dean is an unknown quantity at this point 
Solved Threads: 3
Eddy Dean Eddy Dean is offline Offline
Junior Poster in Training

Re: FindWindow Problems (on Windows 98/ME)

 
1
  #4
Sep 2nd, 2006
  1. // snapshot.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <windows.h>
  6. #include <iostream>
  7. #include <stdio.h>
  8. #include <Tlhelp32.h>
  9.  
  10. using namespace std;
  11.  
  12.  
  13. int main(int argc, char* argv[])
  14. {
  15. DWORD tibiaID;
  16. HANDLE hProcessSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0);
  17. if(hProcessSnapshot == INVALID_HANDLE_VALUE)
  18. {
  19. cout << "invalid snapshot handle" << endl;
  20. }
  21.  
  22. PROCESSENTRY32 ProcessStruct;
  23.  
  24. ProcessStruct.dwSize = sizeof(PROCESSENTRY32);
  25.  
  26. Process32First(hProcessSnapshot, &ProcessStruct);
  27.  
  28. if(strcmp(ProcessStruct.szExeFile, "tibia.exe") == 0)
  29. {
  30. //you have the right process.
  31. tibiaID = ProcessStruct.th32ProcessID;
  32. }
  33. else
  34. {
  35. // tibia.exe is not the first process
  36. //looping through the other records
  37. while(Process32Next(hProcessSnapshot, &ProcessStruct))
  38. {
  39. if(strcmp(ProcessStruct.szExeFile, "tibia.exe") == 0)
  40. {
  41. //the right record has been found
  42. tibiaID = ProcessStruct.th32ProcessID;
  43. break;
  44. }
  45. }
  46.  
  47. }
  48. cout << tibiaID;
  49. return 0;
  50. }

retreives the processID of tibia.exe. You can also compare to the module name of tibia.exe.

Creating a handle from the ID is something you already know, so that won't be a problem.

Yours,
Eddy
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: FindWindow Problems (on Windows 98/ME)

 
1
  #5
Sep 2nd, 2006
> HWND hTemp = FindWindow("tibiaclient", NULL);
The newer compilers use UNICODE by default.

I think you can either turn this off.

Or prepare your code for the future by writing
HWND hTemp = FindWindow( _TEXT("tibiaclient"), NULL);

http://www.i18nguy.com/unicode/c-unicode.html
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 4
Reputation: Haktivex is an unknown quantity at this point 
Solved Threads: 0
Haktivex Haktivex is offline Offline
Newbie Poster

Re: FindWindow Problems (on Windows 98/ME)

 
0
  #6
Oct 31st, 2006
Thanks for your reply Salem.

Unfortunately, I have just realized that I was looking after the wrong problem all along. FindWindow is doing it's job correctly, it is the next few lines causing the problem.

  1. // Now get the ProcessID, so we can get a snapshot and open the process.
  2. GetWindowThreadProcessId(hTemp, &lTibiaProcessID);
  3.  
  4. hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, lTibiaProcessID);
  5. Module32First(hSnapshot, modA);
  6. strcpy(szTibiaPath, modA->szExePath);
Under Windows NT/XP/ etc this works just fine and dandy, and returns the path correctly. However, under Windows 98/ME etc, this returns some file not relevant to what we are searching for. The FindWindow procedure as originally thought to be the problem is not.
Last edited by Haktivex; Oct 31st, 2006 at 2:52 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC