943,984 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3592
  • C++ RSS
Sep 2nd, 2006
1

FindWindow Problems (on Windows 98/ME)

Expand Post »
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:

C++ Syntax (Toggle Plain Text)
  1. HWND hTemp = FindWindow("tibiaclient", NULL);

Thanks alot,
Haktivex.
Similar Threads
Reputation Points: 13
Solved Threads: 0
Newbie Poster
Haktivex is offline Offline
4 posts
since Sep 2006
Sep 2nd, 2006
1

Re: FindWindow Problems (on Windows 98/ME)

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
Reputation Points: 38
Solved Threads: 3
Junior Poster in Training
Eddy Dean is offline Offline
56 posts
since Jul 2006
Sep 2nd, 2006
0

Re: FindWindow Problems (on Windows 98/ME)

Click to Expand / Collapse  Quote originally posted by Eddy Dean ...
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.
Reputation Points: 13
Solved Threads: 0
Newbie Poster
Haktivex is offline Offline
4 posts
since Sep 2006
Sep 2nd, 2006
1

Re: FindWindow Problems (on Windows 98/ME)

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 38
Solved Threads: 3
Junior Poster in Training
Eddy Dean is offline Offline
56 posts
since Jul 2006
Sep 2nd, 2006
1

Re: FindWindow Problems (on Windows 98/ME)

> 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
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 31st, 2006
0

Re: FindWindow Problems (on Windows 98/ME)

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.

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 13
Solved Threads: 0
Newbie Poster
Haktivex is offline Offline
4 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: using borland lib classes
Next Thread in C++ Forum Timeline: Please help me figure out whats wrong with my code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC