Connecting Tech Pros Worldwide Help | Site Map

Compiling errors in code in visual c++ 2008 express edition

Newbie
 
Join Date: Nov 2008
Posts: 1
#1: Nov 19 '08
When I am compiling in visual c++ 2008 express edition I am receiving these two errors

main.cpp(224) : error C2664: '_stricmp' : cannot convert parameter 1 from 'WCHAR [260]' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

main.cpp(269) : error C2664: 'strcmp' : cannot convert parameter 2 from 'WCHAR [256]' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

the 2 lines of code that is giving error is
if(_stricmp(lppe.szExeFile,process)==0)
if (strcmp(DllName,me32.szModule) == 0){
which is part of the functions
Expand|Select|Wrap|Line Numbers
  1. DWORD GetPIDForProcess (char* process)
  2. {
  3.     BOOL            working=0;
  4.     PROCESSENTRY32 lppe= {0};
  5.     DWORD            targetPid=0;
  6.  
  7.     HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS ,0);
  8.     if (hSnapshot) 
  9.     {
  10.         lppe.dwSize=sizeof(lppe);
  11.         working=Process32First(hSnapshot,&lppe);
  12.         while (working)
  13.         {
  14.             if(_stricmp(lppe.szExeFile,process)==0)
  15.             {
  16.                 targetPid=lppe.th32ProcessID;
  17.                 break;
  18.             }
  19.             working=Process32Next(hSnapshot,&lppe);
  20.         }
  21.     }
  22.  
  23.     CloseHandle( hSnapshot );
  24.     return targetPid;
  25. }
and

Expand|Select|Wrap|Line Numbers
  1. DWORD GetDLLBase(char* DllName, DWORD tPid)
  2. {
  3.     HANDLE snapMod;  
  4.     MODULEENTRY32 me32;
  5.  
  6.     if (tPid == 0) return 0;
  7.     snapMod = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, tPid);  
  8.     me32.dwSize = sizeof(MODULEENTRY32);  
  9.     if (Module32First(snapMod, &me32)){ 
  10.         do{
  11.             if (strcmp(DllName,me32.szModule) == 0){ 
  12.                 CloseHandle(snapMod); 
  13.                 return (DWORD) me32.modBaseAddr; 
  14.             }
  15.         }while(Module32Next(snapMod,&me32));
  16.     }
  17.  
  18.     CloseHandle(snapMod); 
  19.     return 0;  
  20.  
  21. }
Can someone edited my code so I can compile correctly?
Member
 
Join Date: Apr 2008
Posts: 67
#2: Nov 19 '08

re: Compiling errors in code in visual c++ 2008 express edition


In visual c++, you need to be aware of unicode. If you use a plain char pointer, it is not unicode compatible, because it is a byte instead of two bytes. There are some macros that define character typedr based upon whether you have unicode enabled in your project, for example TCHAR. I would suggest you in to msdn and read about unicode for full details and sample code.

Regards
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,366
#3: Nov 19 '08

re: Compiling errors in code in visual c++ 2008 express edition


You cannot use functions like strcmp in a Windows program. When Unicode is not enabled you need strcmp but when itis enabled you need wcscmp. Microsoft has provided a set of macros that switch between the Unicode and non-Unicode names. You use the macros instead of calling the functions directly.

These are the TCHAR routine macros:

http://msdn.microsoft.com/en-us/libr...ba(VS.80).aspx.

Going along with this is using TCHAR instead of char.

And also using _tmain rather than main(), etc...
Needs Regular Fix
 
Join Date: Sep 2007
Location: The Netherlands
Posts: 427
#4: Nov 19 '08

re: Compiling errors in code in visual c++ 2008 express edition


If you're not using wide chars then the easiest thing is not compile with unicode. Hit Alt-F7 in your project and under "Configuration Properties" change "Character Set" from Unicode to Multi-Byte.
Reply