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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • entice
    New Member
    • Nov 2008
    • 1

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

    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_cas t, 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_cas t, C-style cast or function-style cast

    the 2 lines of code that is giving error is
    if(_stricmp(lpp e.szExeFile,pro cess)==0)
    if (strcmp(DllName ,me32.szModule) == 0){
    which is part of the functions
    Code:
    DWORD GetPIDForProcess (char* process)
    {
    	BOOL			working=0;
    	PROCESSENTRY32 lppe= {0};
    	DWORD			targetPid=0;
    
    	HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS ,0);
    	if (hSnapshot) 
    	{
    		lppe.dwSize=sizeof(lppe);
    		working=Process32First(hSnapshot,&lppe);
    		while (working)
    		{
    			if(_stricmp(lppe.szExeFile,process)==0)
    			{
    				targetPid=lppe.th32ProcessID;
    				break;
    			}
    			working=Process32Next(hSnapshot,&lppe);
    		}
    	}
    
    	CloseHandle( hSnapshot );
    	return targetPid;
    }
    and

    Code:
    DWORD GetDLLBase(char* DllName, DWORD tPid)
    {
    	HANDLE snapMod;  
    	MODULEENTRY32 me32;
    
    	if (tPid == 0) return 0;
    	snapMod = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, tPid);  
    	me32.dwSize = sizeof(MODULEENTRY32);  
    	if (Module32First(snapMod, &me32)){ 
    		do{
    			if (strcmp(DllName,me32.szModule) == 0){ 
    				CloseHandle(snapMod); 
    				return (DWORD) me32.modBaseAddr; 
    			}
    		}while(Module32Next(snapMod,&me32));
    	}
    
    	CloseHandle(snapMod); 
    	return 0;  
    
    }
    Can someone edited my code so I can compile correctly?
  • pootle
    New Member
    • Apr 2008
    • 68

    #2
    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

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      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...

      Comment

      • arnaudk
        Contributor
        • Sep 2007
        • 425

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

        Comment

        Working...