Good day my every one outthere, first let me start by saying that i am a complete novice to c++ programming. i got myself into some trouble while debugging a win32 program in
2008 V.studio. i did post this thread some 24 hours ago but no good result so far. pls go through this again and help me answer my quetions as much as you can.Here's it:


with this code line(and some similar lines anyway):
::MessageBox (wndhnd, "Error!", "Exception Occured", MB_ICONINFORMATION | MB_OK);

Here's the error message i saw as output from my compiler:

1.1>c:\users\user\documents\visual studio 2008\projects\edopedia\edopedia\edopedia\edopedia\edopedia\edopediadirector.cpp(37) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast.

At first i tried to cast parameters 2(Error) and 3(Exception Occured) from char [7] and char[18] respectively to LPCWSTR so as to silent my compiler in the ::MessageBox API function call above (as well as in other code lines of my program where similar error messages were given). Fine the entire Error messages where resolved at a time.

The problem i have now is when i ran the application by pressing ctrl +f5, the window and message boxes that poped up had all of their outputs at both the title bar and paint area displayed in chinese (something like the chinese) character. Not even a single output from the window was displayed in English character(which i actually used all through). Even though i cannot read meaning to these Non-sense that seem like a chinese alphanumeric letters or whaterver, i tried to see if i can output it in the original string(English) which i used earlier. However, the more i try, the more fraustrated i got.
my questions are:

1.what is the meaning, origin, and use of this Non-sense compiler Error: (LPCWSTR)?
2.Have i commit any sin for casting my char arrays to so called (LPCWSTR)?
3.Is there something else i haven't done right?
4.MOST IMPORTANTLY how can i get over this absord chinese-like displays or output from my
window and messageboxes?

I'LL BE STRONGLY INDEBTED TO ANY OF MY MASTERS OUTTHERE WHO CAN GET ME THROUGH
THIS PROBLEM AS IT HAS BECOME A GREAT NIGHTMARE TO MY LIFE FOR THE PAST 11 WEEKS.

if anyone wish to see the chinese-like window exactly as it is, you may send
me your mail address on <<snip>> so i can upload it live to your mailbox.

finally, below are a few major files of the code that produced this chinese-like windows. i cannot list all here because the program is too bulky(about 18 classes so far.):

#include <windows.h> //for windows APIs
#include <stdlib.h>  
#include <string.h>


#include "EdoTopWinClass.h"  //encapsulates the WNDCLASSEX structure
#include "EdoWinControl.h"   //encapsulates HWND parent window and EdoTopWinClass object.
#include "EdoWinException.h" //encps DWORD error & char* message for exception class
#include "SimpleEdoClass.h"  //baseclass for EdoTopWinClass to construct HINSTANCE
#include "EdopediaDirector.h" //controller class to act as the program's manager
#include "WinGetLong.h"       
#include "resource.h"


//global variables declaration
char AppCaption[60];

//window procedure to be called by the operating system
LRESULT CALLBACK EdoWinProc(HWND hwnd, UINT Message, WPARAM wparam, LPARAM lparam);

//main window class name

char gszClassName[] = "EdoWinClass";

//window instance to be used by the OS
HINSTANCE ghInstance = NULL;

//title bar string
char Classname[] = "Edopedia";

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	LoadString(hInstance, IDS_STRING, (LPWSTR)AppCaption, 60);
	ghInstance = hInstance; 
	//exception to handle unexpected errors
	//and protect from unexpected accidents.

	try
	{
		
		EdoTopWinClass edoclassreg(gszClassName, ghInstance, EdoWinProc);
			//is this class already running!
		HWND hwndOther = edoclassreg.GetRunningWindow ();
		if(hwndOther)
		{
			::SetForegroundWindow(hwndOther);
			if(::IsIconic(hwndOther))
				::ShowWindow(hwndOther, SW_RESTORE);
			return 0;
		}
		edoclassreg.Register();

		//Create top Edowindow

		EdoWinControl createedoclass(edoclassreg, Classname);
		createedoclass.Create();
		createedoclass.Show(nCmdShow);

		//Get user attempts through message loop

		int status;
		MSG msg;
        while ((status = ::GetMessage (&msg, 0, 0, 0)) != 0)
		{
		   if (status == -1)
                return -1;
            ::TranslateMessage (&msg);
            ::DispatchMessage (&msg);
        }
		return msg.wParam;
	}
	catch ( EdoWinException expt)
	{
		char buf [80];
        wsprintf ((LPWSTR)buf, (LPCWSTR)"%s, Error %d", expt.GetMessage (), expt.GetError ());
        ::MessageBox (0, (LPCWSTR)buf, (LPCWSTR)"Exception", MB_ICONEXCLAMATION | MB_OK);
	}
	catch (...)
	{
       ::MessageBox (0, (LPCWSTR)"Unknown", (LPCWSTR)"Exception", MB_ICONEXCLAMATION | MB_OK);
	}
	return 0;
}
LRESULT CALLBACK EdoWinProc(HWND hwnd, UINT Message, WPARAM wparam, LPARAM lparam)
{
	EdopediaDirector * pDrector = WinGetLong<EdopediaDirector *> (hwnd);
  
        switch(Message) 
		{
		case WM_CREATE:
			//Catch exceptions if need arrises
			try
			{
				pDrector = new EdopediaDirector(hwnd,
					reinterpret_cast<CREATESTRUCT *>(lparam));
				WinSetLong<EdopediaDirector *> (hwnd, pDrector);
			}
			catch (EdoWinException exe)
			{
				::MessageBox (hwnd, (LPCWSTR)exe.GetMessage(), (LPCWSTR)"Initialization",
                MB_ICONEXCLAMATION | MB_OK);
				return -1;
			}
			catch (...)
			{
				::MessageBox (hwnd, (LPCWSTR)"Unknown Error", (LPCWSTR)"Initialization",
                MB_ICONEXCLAMATION | MB_OK);
				return -1;
			}
			return 0;

		case WM_SIZE:
			pDrector ->clientsize(LOWORD(lparam), HIWORD(lparam));
			return 0;
		
		case WM_PAINT:
			pDrector -> paintwnd();
			return 0;
		
		case WM_COMMAND:
			pDrector -> command(LOWORD (wparam));
			return 0;
		
		case WM_DESTROY:
			WinSetLong<EdopediaDirector *> (hwnd, 0);
			delete pDrector;
			return 0;
		}
		return DefWindowProc(hwnd, Message, wparam, lparam);
}

I don't know about the "Chinese" characters, but it should be reasonably easy to fix the message box program. What I would suggest is making a < 20 line (or as small as possible) program that simply tries to display a message box. That should be easily debug-able by someone here. Unfortunately I'm not a Microsoft C guy so I can't help directly.

Also, you should really use a descriptive title to identify your question to the community. "Help me!" is not very useful :)

Dave

Edited 6 Years Ago by daviddoria: n/a

There is a relatively easy solution to this problem which is caused by a misunderstanding of the configuration change for Unicode.

Please place all your strings inside a _T() method or prefix them with L

_T() is preferred as this will still work if/when you disable Unicode.

Eexample:

{
    ...
    MessageBox(NULL, _T("Error!"), _T("A Fatal Error Occurred"), MB_ICONEXCLAMATION | MB_OK);
    ...
}

Also, DO NOT DO THE FOLLOWING

{
    ...
    char[12] myChars = "Hello World";
    char[6] myTitle = "Title";
    MessageBox(NULL, _T(myTitle), _T(myChars), MB_ICONEXCLAMATION | MB_OK);
    ...
}

You will need to convert from char to wchar or use TCHAR to maintain compatibility.

(LPCWSTR basically means Long Pointer Const Wide String, which is a 32bit pointer to a const wchar and is defined as typedef CONST WCHAR *LPCWSTR; )

Edited 6 Years Ago by Ketsuekiame: n/a

This article has been dead for over six months. Start a new discussion instead.