Having a bit of trouble...

Started by
5 comments, last by Sanctux 16 years ago
I'm trying to make a window for a Tetris Clone, and I keep getting these 3 errors about an illegal conversion. But I got everything from a Tutorial from this website, but everyone else who has used this says it compiles just fine. Can someone explain these errors? My code is provided after the errors. 1>c:\users\user\documents\visual studio 2008\projects\blocks\blocks\main.cpp(185) : error C2440: '=' : cannot convert from 'const char [10]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\users\user\documents\visual studio 2008\projects\blocks\blocks\main.cpp(194) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [10]' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>c:\users\user\documents\visual studio 2008\projects\blocks\blocks\main.cpp(249) : error C2664: 'BitMapObject::Load' : cannot convert parameter 2 from 'const char [11]' to 'LPCTSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { // Assign instance to global variable hInstMain = hInstance; // Create window class WNDCLASSEX wcx; // Set the size of the structure wcx.cbSize = sizeof(WNDCLASSEX); // Class style wcx.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; // Window Procedure wcx.lpfnWndProc = TheWindowProc; // Class Extra wcx.cbClsExtra = 0; // Window Extra wcx.cbWndExtra = 0; // Application Handle wcx.hInstance = hInstMain; // Icon wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); // Cursor wcx.hCursor = LoadCursor (NULL, IDC_ARROW); // Background Color wcx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // Menu wcx.lpszMenuName = NULL; // Class Name wcx.lpszClassName = WINDOWCLASS; // Small Icon wcx.hIconSm = NULL; // Register the Window Class, return 0 if not successful if(!RegisterClassEx(&wcx)) return(0); // Create Main Window hWndMain = CreateWindowEx(0, WINDOWCLASS, WINDOWTITLE, WS_BORDER | WS_SYSMENU | WS_CAPTION | WS_VISIBLE, 0 , 0, 320, 240, NULL, NULL, hInstMain, NULL); // Error Check if (!hWndMain) return (0); // if program initialization failed, then return with 0 if (!GameInit()) return (0); // Message structure MSG msg; // Message pump for( ; ; ) { // Look for a message if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // There is a message // Check that we aren't quitting if (msg.message == WM_QUIT) break; // Translate Message TranslateMessage(&msg); // Dispatch Message DispatchMessage (&msg); } // Run Main Game Loop GameLoop(); } // Clean up program data GameDone(); // return the wParam from the WM_QUIT message return (msg.wParam); } bool GameInit() { // Set the client area size RECT rcTemp; SetRect (&rcTemp, 0, 0, MAPWIDTH*TILESIZE+TILESIZE*GREY, MAPHEIGHT*TILESIZE); // 160x480 client area AdjustWindowRect(&rcTemp, WS_BORDER | WS_SYSMENU | WS_CAPTION | WS_VISIBLE, FALSE); // Adjust the window size based on desired client area SetWindowPos(hWndMain, NULL, 0, 0, rcTemp.right-rcTemp.left, rcTemp.bottom-rcTemp.top, SWP_NOMOVE); // Set the Window width and height // Create map image HDC hdc = GetDC(hWndMain); bmoMap.Create(hdc, MAPWIDTH*TILESIZE+TILESIZE*GREY, MAPHEIGHT*TILESIZE); FillRect (bmoMap, &rcTemp, (HBRUSH) GetStockObject (BLACK_BRUSH)); ReleaseDC (hWndMain, hdc); bmoBlocks.Load(NULL, "blocks.bmp"); NewGame(); return (true); // return success }
Advertisement
It's a result of Visual C++ changing it's default settings starting in 2005 (which is why all tutorials from before then say the code is okay). To fix this you can go into your project settings and change the character set from "Unicode" to "Multi-Byte Character Set".

If you'd like to know why you have to do this, check out my most recent journal entry for a more in-depth explanation.
Thanks so much for the help. I thought it was something like that causing the error when I read that the tutorial was posted in 2006. Thanks for the link as well. I'm glad to know I found a website, where I can get the help I need.
Now its giving me a linking error, is this a setting as well or just something I should try to figure out myself? I don't want to just keep bothering people with my coding problems if its just me messing up.

1>------ Build started: Project: Blocks, Configuration: Debug Win32 ------
1>Compiling...
1>bitmapobject.cpp
1>Main.cpp
1>Generating Code...
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Linking...
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\user\Documents\Visual Studio 2008\Projects\Blocks\Debug\Blocks.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\user\Documents\Visual Studio 2008\Projects\Blocks\Blocks\Debug\BuildLog.htm"
1>Blocks - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Your project is set to use the console subsystem, which expects an entry point of "int main". This initially gets set when you create your project, where a Win32 project uses the windows subsystem and a Win32 console project uses the console subsystem. You can change this for an existing project by going to the linker options, set it to "WINDOWS" and it should use your WinMain and compile just fine.

Oh and btw, if you want to post long bits of code you can use the "source" tags to give them nice formatting and syntax highlighting.
Ok, How do I go about adding the source tags to my posts? Thanks again for the help. The code compiled just fine.... finally! :)
Try the [ source ] and [ /source ] tags; just omit the spaces. ;)
Jack

This topic is closed to new replies.

Advertisement