Good day my masters 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.
with this code line(with 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);
}