I have been reading a tutorial about how to edit solitaire's memory addresses, since i am really interested in memory editing. I ran into a problem i can't fix as yet.
I am using microsoft visual c++ 2010 express.
Here it is
error C2664: 'strcmp' : 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
strcmp is a function that takes two parameters. Each parameter must be a pointer to a const char.
You are trying to feed it an object of type WCHAR [260]. It does not take those objects. It takes constchar* objects. You must pass it a constchar* or something that the compiler knows how to transform into a constchar*.
If you pass it the address of pe32.szExeFile[0], you will then be passing it a WCHAR*, which is a bit closer. I never work with WCHAR type, so I can't advise on the relationship between WCHAR and char.
So i need to make a pointer to his: pe32.szExeFile like: &pe32.szExeFile?
Actually, that bunch of code was given, with the tutorial, so the function GetProcId(char* ProcName), was said to be unexplained. I don't really understand that part.
Don't be mad though, i understand the other part, since it's not that complicated.
Well, there's a few things you can do. Two of them are:
1. You can #undef UNICODE at the beginning of the file.
2. You can use this instead of strcmp():
1 2 3 4 5 6 7 8
template <typename T1,typename T2>
int generic_strcmp(const T1 *str1,const T2 *str2){
for (;;str1++,str2++){
int d=*str1-*str2;
if (d!=0)
return d;
}
}
Moschops: WCHAR is just a macro for wchar_t. It's not a complex type.
For each str- function, there's a wcs- version: strlen, strcpy, strchr, ... for Ansi; wcslen, wcscpy, wcschr, ... for Unicode.
Andy
PS And when tchar.h is included, the _tcs- macros map to either str- or wcs- depending on how _UNICODE is declared: _UNICODE controls the CRT, whereas UNICODE controls the Windows API mappings.
I think your best fix is to change the projects General / Character Set property to "Use Multi-Byte Character Set" (I would do this rather than use #undef UNICODE / #undef _UNICODE)
wcscmp() will fix the error you quoted, but then you'd have to move some other bits of your code to use Unicode (wchar_t/WCHAR) rather than char.
Just switching strcmp -> lstrcmp (or wcscmp) won't make everything right, as one of the params being passed to strcmp (or whatever) is currently a wchar_t (the left one) and the other a char.
The easiest way is to alter the char set the vcproj is using, so everything builds Ansi. Then the code should work as-is (or with lstrmcmp, for that matter).
If the project is left to build Unicode, the lstrcmp change will also require GetProcId() to be alterered to take a wchar_t* (or to use TCHAR*, tchar.h macro style). Which means the passed in string needs to become a "long" string:
pid = GetProcId(L"solitaire.exe");
or (with tchar.h macro)
pid = GetProcId(_T("solitaire.exe"));
Or you leave GetProcId() param as it is, but convert the passed in value from Ansi to Unicode (using MultiByteToWideChar) before calling lstrcmp.
Just switching strcmp -> lstrcmp (or wcscmp) won't make everything right, as one of the params being passed to strcmp (or whatever) is currently a wchar_t (the left one) and the other a char.
It is truly horrifying to learn that there are some dev environments where the person writing the code does not inherently have the ability to debug that code :(