By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,945 Members | 1,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,945 IT Pros & Developers. It's quick & easy.

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

P: 1
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?
Nov 19 '08 #1
Share this Question
Share on Google+
3 Replies


P: 68
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
Nov 19 '08 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
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...
Nov 19 '08 #3

100+
P: 424
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.
Nov 19 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.