 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Tue Jul 29, 2008 10:44 pm Post subject: [C++] 'Simple Window' Errors |
|
|
I'm following theForger's Win32 tutorial, and I slapped this source below into MSVC++ 2008 and came up with these errors:
(41) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR'
(51) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
(55) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [24]' to 'LPCWSTR'
All of them tell me: | Quote: | | Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast |
Although I don't see how I can type-cast as they're aren't being assigned new values. I did fix one error using type-casting where I made my comment in the code.
| Code: | #include <windows.h>
const char g_szClassName[] = "myWindowClass";
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = (LPCSTR)/*had to add for mvc++*/ g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK); //Line 41 Error <<<<<<<<<<<<<
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL); //Line 51 error<<<<<<<<<<<<<<<<<
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK); //Line 55 error<<<<<<<<<<<<
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
} |
By the way, Dev-C++ compiles this PERFECTLY without a single error.
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Tue Jul 29, 2008 10:49 pm Post subject: |
|
|
VC++ compiles in Unicode by default. Go to View->Property Pages->Configuration Properties->General->Character Set = Using Multi-Byte Character Set
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Tue Jul 29, 2008 10:55 pm Post subject: |
|
|
Either that or start using UNICODE. Include tchar.h to the file and then use _T, _TEXT, or TEXT in front of all your strings. Like so:
CreateWindowEx( 0, _T("WindowClass"), _T("WindowTitle"), ... );
These macro's will add an 'L' in front of the string making it UNICODE.
_________________
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Tue Jul 29, 2008 11:00 pm Post subject: |
|
|
Oh, thanks. Problem solved.You told me to do this before so I figured it would have still been on Multi-Byte. Do I have to change it every time I open it? And lastly, is there a hotkey/button to run the program after its compiled or do I have to hunt it down in my project folder =\
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Tue Jul 29, 2008 11:05 pm Post subject: |
|
|
You only have to change it every time you make a project, but not every time you open a project. And hit F5 to Build and Run the program.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
sponge I'm a spammer
Reputation: 1
Joined: 07 Nov 2006 Posts: 6009
|
Posted: Tue Jul 29, 2008 11:10 pm Post subject: |
|
|
Learn to indent.
_________________
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Tue Jul 29, 2008 11:15 pm Post subject: |
|
|
| sponge wrote: | | Learn to indent. |
Yeah, sorry about the block of code. Copied from a .pdf into MSVC++ then from MSVC++ onto CEF and it just came out that way.
_________________
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Wed Jul 30, 2008 3:59 am Post subject: |
|
|
| Stick to unicode and use _T(). It doesnt take much more time =|.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|