PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Bunch of errors

I'm uh having a few problems. 28 of them to be exact. One of them that shows up is this:
error C2664: '__cdecl CFile::CFile(const unsigned short *,unsigned int)' : cannot convert parameter 1 from 'const char *' to 'const unsigned short *'

and
error C2664: 'WriteProfileInt' : cannot convert parameter 1 from 'char [12]' to 'const unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Most of them are conversion errors. The program code works fine on Win32. (Yes I realize there are differences, I just don't know what they are) I have no idea what to do. Any help would be greatly appreciated. Thanks.
simonjacobs · 01 Aug 2003, 21:51 UTC
I think your function calls are expecting strings in multi byte format on the ppc instead of single byte on the desktop. Either try:

L"text" instead of "text" or convert them. There is a function to convert which I dont remember off hand, search for string conversion in the docs.

WideCharToMultiByte or something.
The PPC doesn't use multibyte chars, but wide chars (also referred to as unicode strings).

Look into header <tchar.h>, it provides macros to allow you to write code that compiles in both ASCII and wide-chars.
I used to have a problem with this, until I learned the "pattern"... Always use the TEXT() macro, and then only use functions defined in TCHAR.h, as Thierry said (hint: when in VC++ or I think eVC++ as well, look up the function you want in the docs, say swprintf or printf, and scroll down, there is usually a section labeled Generic Text String Mappings, and it shows the TCHAR.h function name there... just use that!). Do these things and you should be able to compile for the desktop and PPC's without any problems.
Hey guys did you hear that??? It was the sound of everything you just said flying way over my head. But hey, thanks for trying. It's not your fault I have no idea what I'm doing. OK, here's the offending code: (Obviously these things are snippets, not right after one another)

Code:
CFile file(pszFile, CFile::modeRead);
VERIFY( GetKeyboardState(m_VKeys) );
UINT wm_Refresh = ::RegisterWindowMessage("MyProg_Refresh");
r.left = AfxGetApp()->GetProfileInt("Main Window", "Left", 100);
AfxRegisterWndClass(0, ::LoadCursor(NULL, IDC_ARROW)),
Ah... Simple enough... Instead of "MyProg_Refresh", you need to put L"MyProg_Refresh" or better still TEXT("MyProg_Refresh").

I just quickly looked up RegisterWindowMessage in the eVC++ docs... It requires a LPCTSTR, which to make a long story short, is a pointer. Just putting the text in quotes doesn't give it a pointer, that's what L" or TEXT("") do (well, essentially anyway).

Without looking anything up, I'd bet that goes for all of those items...
Ah, your suggestion worked. 1 error down, the rest to go. Unfortunately, your suggestion only helped that one example. I'm mainly getting crap like "cannot convert from char[19] to unsigned short". Thanks so much for helping with this.
That error generally points to the same kind of problem... Your passing in an array of char's, but it's looking for a pointer (I believe an LPCSTR is the same thing as an unsigned short in this case).
simonjacobs · 02 Aug 2003, 10:36 UTC
Um, surely an array of chars IS passed as a pointer. The problem is that it wants a pointer to unicode chars not ansi chars.

As I said in my first reply, for strings declared in the function like:

MyFunc("wibble") you can change to MyFunc(L"wibble")

Otherwise for the others you need to convert. The function I mentioned actually can convert unicode->ansi, the one you want for the other way is:

MultiByteToWideChar

Look it up in the docs or do a google search on converting ansi to unicode.
You are right of course simon... it was late, my brain wasn't turned on (which is different than the low levels of activity I normally run it at :) ).

My point was simply that I thought just doing L"" or TEXT("") would solve the problems in all cases, without looking up the functions to be sure, because that would provide the correct pointer type (unsigned short*).
simonjacobs · 02 Aug 2003, 13:51 UTC
I see what you mean.

If you are in a function such as:

dosomething(char *text)
{ }

and in the function you need text in unicode I am not sure if TEXT(text) works or not. I would guess that you have to convert either with a function call or simply do it by hand with a loop. After all the change is simply a question of padding the string with zero's in front of each character.
I'm not willing to bet my life on it, but I believe the TEXT() macro converts the string to unicode (and hence provides an unsigned short* to it) if unicode is defined (e.g., WinCE) and does nothing when it's not (the desktop)... which I guess doesn't really explain why it would work on the desktop because if it does nothing I would expect it to return a char*...

But in any case, I think your right, if the function is defined as taking char*, I don't think TEXT() will work in that case, you have to take care to use the unicode versions of all functions if you want it to work on WinCE, then you can use TEXT() everywhere and have it be cross-platform without change.
ChezDoodles · 02 Aug 2003, 19:51 UTC
To convert from char[] to wchar[], use MultiByteToWideChar, and to go from wchar[] to char[] use WideCharToMultiByte.

Don't worry that the funtion is called "MultiByte" - it refers to MBCS (MultiByteCharacterString) which is also a char[] deep down. MBCS is normally one 1 byte chars - but some characters inbetween can be 2 byte to support special characters sets. MBCS was a step along the way from ANSI to UNICODE on the Win9x platform back in the '90s.
mlepage · 03 Aug 2003, 03:26 UTC — MBCS
I believe MBCS is variable-byte-length characters. That is, physically, the string is single byte characters, but logically, a character can be 2 (or more?) bytes. It makes algorithms (e.g. go forward 4 characters) hell. Stick with single-byte characters or UNICODE (wide characters).
ChezDoodles · 03 Aug 2003, 07:18 UTC
Check the documentation to the two functions - you can specify ANSI codepages - meaning there is no risk ending up with characters that actually takes up more space than one byte if you don't want to.
Well I finally checked the MSDN library and listened to what you guys said, and fixed most of the errors. I'm down to 3 or 4 now. Here's the exact code thats causing problems:
Code:
CFile file(pszFile, CFile::modeRead);
m_pRom = new unsigned char[m_RomSize];
return file.Read(m_pRom, m_RomSize) == m_RomSize;

and
Code:
GetKeyboardState(m_VKeys);

and
Code:
#if 1
// Vital for keyboard input!
return ::AttachThreadInput(
m_EmulatorThreadID,
idThread, //::GetCurrentThreadId(),
fAttach );
#else
return FALSE;
#endif


I assume its because some of those functions aren't available in eVC++. Again, thanks for any help.