PocketMatrix forums

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

building for both win32 & wince using unicode

I'm starting a new post for this as my original question was tacked onto one about strings.

My project (PocketFrog based game) builds fine on eVC but all my strings are unicode & this includes string tables.

I want to build using VC6 to cut out the emulator on eVC as it's not much good & I do lots of coding on trains so syncing a device is hard.

When I add the UNICODE definition to a VC6 project I hit a problem with the winmain function being overloaded because the LPTSTR parameter in wince is LPSTR in win32. The problem does not show on VC6 if I omit the UNICODE definition but then I get other errors. Just changing the parameter to LPSTR causes PocketFrog to give errors.

Microsoft MSDN says
ANSI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name. The reason that WinMain cannot return Unicode strings is that lpCmdLine uses the LPSTR data type, not the LPTSTR data type. The GetCommandLine function can be used to access Unicode strings in the command line, because it uses the LPTSTR data type.
but this does not tell me how to fix my problem.

Can anyone help?
You just need to define the WinMain function slightly differently for the two cases, since the command line is not Unicode even if you build a Win32 Unicode program.

Something like:
Code:

#ifdef _WIN32_WCE
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
#else
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
#endif
{
// WinMain code here...
}
Conan · 09 Feb 2003, 14:18 UTC — WinMain error etc
Thanks, I did try that but when I change the LPTSTR to just LPSTR I get a new linker error coming from PocketFrog
rotate.obj : error LNK2001: unresolved external symbol "class Frog::Surface * __cdecl Frog::LoadImageW(class Frog::DisplayDevice *,unsigned int,unsigned short const *,struct HINSTANCE__ *)" (?LoadImageW@Frog@@YAPAVSurface@1@PAVDisplayDevice@1@IPBGPA
UHINSTANCE__@@@Z)
Release/Rotate.exe : fatal error LNK1120: 1 unresolved externals

so it looks like PocketFrog requires the parameter as LPTSTR thogh I'm not sure what's happening really at the moment.

Having read about 100 posts all over Google etc today I can't find an exact match for this issue but there must be someone building a project on VC6 using unicode surely?
Ok, I think I know what's going on now...

This is from winuser.h which typically gets included when you do windows stuff.

Code:

#ifdef UNICODE
#define LoadImage LoadImageW
#else
#define LoadImage LoadImageA
#endif // !UNICODE


When you compile rotate.cpp the compiler will have seen this definition and will generate calls to Frog::LoadImageW which it thinks exists. But when the actual PocketFrog code is compiled it has not seen this definition and will not rename the LoadImage functions, hence the link error.

To fix this you have to make sure that the renaming occurs in all or no cases. You could try changing the include order. If you include the pocket frog headers before any windows headers the pocket frog functions will not be renamed. If pocketfrog itself includes winuser.h directly or indirectly somewhere this may not help though.

Your last resort, if things continue to be problematic is to rename the pocketfrog LoadImage functions yourself to avoid collision with the Win32 API function.

So much for namespaces. Nice going Microsoft.
Conan · 09 Feb 2003, 16:47 UTC — many thanks for your help Orpe
thanks for your input to this problem. Despite several hours of thinking about it my brain never made the connection. I will investigate as suggested and see if I can solve this.
Conan · 10 Feb 2003, 13:53 UTC — Unicode not required
It turns out that I was 'barking up the wrong tree'. Unicode defines were not needed. I just had to create my project correctly & ensure that tchar.h was included & all uses of strings,file handling etc were set up to work correctly in both eVC & VC6.

What a relief to be able to debug normally again.

Many thanks for all the assistance