3 Replies - 11338 Views - Last Post: 11 September 2007 - 06:55 PM Rate Topic: -----

#1 ModestBigferd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-September 07

cannot convert parameter 2 from 'const char [32]' to 'LPCW

Post icon  Posted 11 September 2007 - 02:23 AM

I could very well be losing it. Right now I'm learning some basic windows programming with a focus on game design with the book "Tricks of the Game Programming Gurus". Anyway, as I go through the different elements I tend to keep working in the same project just adding on and commenting out things as I learn. This can get kinda messy as you can imagine so I went to start a new project and just copy and paste the skeleton elements. What's messing with my head is that things in the new project WON'T work while the EXACT SAME things in the old one work fine. Now, I've gone through and double-checked everything about a hundred times and I can't figure it out. My Includes are all the same, as well as including the "WinMM.lib" file in my project and project folder. Here is the code for both files starting with the GOOD one:

// WNDCLASSEX - A complete windows program

#define WIN32_LEAN_AND_MEAN

// INCLUDES /////////////////////////////////////////////////

#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <mmsystem.h>

#include "Resources.h"

// DEFINES //////////////////////////////////////////////////
#define WINDOW_CLASS_NAME "WINCLASS1"

// MACROS ///////////////////////////////////////////////////
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

// GLOBALS //////////////////////////////////////////////////
HINSTANCE hinstance_app;
char buffer[80];

// FUNCTIONS ////////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	PAINTSTRUCT ps;
	HDC hdc;

	switch(msg)
	{
	case WM_CREATE:
		{
			return(0);
		} break;
	case WM_ACTIVATE:
		{
			if (LOWORD(wparam) != WA_INACTIVE)
			{
				//PlaySound("IDW_SWOOSH", hinstance_app, SND_RESOURCE | SND_ASYNC);
			}
			else
			{
				//Do Nothing
			}
		} break;
	case WM_COMMAND:
		{
			switch(LOWORD(wparam))
			{
			case MENU_FILE_ID_OPEN:
				{
					PlaySound("IDW_BOOM3", hinstance_app, SND_RESOURCE | SND_ASYNC);
				} break;
			case MENU_FILE_ID_CLOSE:
				{
					PlaySound("IDW_BOOM3", hinstance_app, SND_RESOURCE | SND_ASYNC);
				} break;
			case MENU_FILE_ID_SAVE:
				{
					PlaySound("IDW_BOOM3", hinstance_app, SND_RESOURCE | SND_ASYNC);
				} break;
			case MENU_FILE_ID_EXIT:
				{
					PlaySound("IDW_BOOM3", hinstance_app, SND_RESOURCE | SND_ASYNC);
				} break;
			case MENU_HELP_ABOUT:
				{
					PlaySound("IDW_BOOM3", hinstance_app, SND_RESOURCE | SND_ASYNC);
				} break;
			default: break;
			}
		} break;
	case WM_CHAR:
		{
			//char ascii_code = wparam;
			//unsigned int key_state = lparam;
			//hdc = GetDC(hwnd);
			//SetTextColor(hdc, RGB(0,255,0));
			//SetBkColor(hdc, RGB(0,0,0));
			//SetBkMode(hdc, OPAQUE);
			//sprintf(buffer, "WM_CHAR: Character = %c   ", ascii_code);
			//TextOut(hdc, 0,0, buffer, strlen(buffer));
			//sprintf(buffer, "Key State = 0X%X  ", key_state);
			//TextOut(hdc, 0,16, buffer, strlen(buffer));
			//ReleaseDC(hwnd, hdc);
		} break;
	case WM_SIZE:
		{
			//int width  = LOWORD(lparam);
			//int height = HIWORD(lparam);
			//hdc = GetDC(hwnd);
			//SetTextColor(hdc, RGB(0,255,0));
			//SetBkColor(hdc, RGB(0,0,0));
			//SetBkMode(hdc, OPAQUE);
			//sprintf(buffer, "WM_SIZE Called - New Size = (%d,%d)", width, height);
			//TextOut(hdc, 0,0, buffer, strlen(buffer));
			//ReleaseDC(hwnd, hdc);
		} break;
	case WM_MOVE:
		{
			//int xpos = LOWORD(lparam);
			//int ypos = HIWORD(lparam);
			//hdc = GetDC(hwnd);
			//SetTextColor(hdc, RGB(0,255,0));
			//SetBkColor(hdc, RGB(0,0,0));
			//SetBkMode(hdc, OPAQUE);
			//sprintf(buffer, "WM_MOVE Called - New Position = (%d,%d)", xpos, ypos);
			//TextOut(hdc, 0,0, buffer, strlen(buffer));
			//ReleaseDC(hwnd, hdc);
		} break;
	case WM_PAINT:
		{
			hdc = BeginPaint(hwnd, &ps);
			EndPaint(hwnd, &ps);
			return(0);
		} break;
	case WM_CLOSE:
		{
			int result = MessageBox(hwnd,
									"Are you sure you want to close this application?",
									"WM_CLOSE Message Processor",
									MB_YESNO | MB_ICONQUESTION);
			if (result == IDYES)
			{
				return (DefWindowProc(hwnd, msg, wparam, lparam));
			}
			else
			{
				return(0);
			}
		} break;
	case WM_DESTROY:
		{
			PostQuitMessage(0);
			return(0);
		} break;
	default: break;
	}

	return(DefWindowProc(hwnd, msg, wparam, lparam));
}

// WINMAIN //////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
	WNDCLASSEX winclass;
	HWND hwnd;
	MSG msg;
	HDC hdc;
	//COLORREF old_fcolor;
	//COLORREF old_bcolor;
	//int old_tmode;

	winclass.cbSize			= sizeof(WNDCLASSEX);
	winclass.style			= CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
	winclass.lpfnWndProc	= WindowProc;
	winclass.cbClsExtra		= 0;
	winclass.cbWndExtra		= 0;
	winclass.hInstance		= hinstance;
	winclass.hIcon			= LoadIcon(hinstance, "IDI_REDCROSS");
	winclass.hCursor		= LoadCursor(hinstance, "IDC_BLUE");
	winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
	winclass.lpszMenuName	= "MainMenu";
	winclass.lpszClassName	= WINDOW_CLASS_NAME;
	winclass.hIconSm		= LoadIcon(hinstance, "IDI_REDCROSS");

	hinstance_app = hinstance;

	if (!RegisterClassEx(&winclass))
	{
		return(0);
	}

	if(!(hwnd = CreateWindowEx(NULL,
							   WINDOW_CLASS_NAME,
							   "Your Basic Window",
							   WS_OVERLAPPEDWINDOW | WS_VISIBLE,
							   400,300,
							   400,400,
							   NULL,
							   NULL,
							   hinstance,
							   NULL)))
	{
		return (0);
	}
	while(TRUE)
	{
		DWORD start_time = GetTickCount();
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if (msg.message == WM_QUIT)
			{
				break;
			}
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		hdc = GetDC(hwnd);

		//old_fcolor = SetTextColor(hdc, RGB(0,255,0));
		//old_bcolor = SetBkColor(hdc, RGB(0,0,0));
		//old_tmode = SetBkMode(hdc, TRANSPARENT);
		//TextOut(hdc, 20,30, "Hello you shitfuck you!", strlen("Hello you shitfuck you!"));
		//SetTextColor(hdc, old_fcolor);
		//SetBkColor(hdc, old_bcolor);
		//SetBkMode(hdc, old_tmode);

		//SetTextColor(hdc, RGB(0,255,0));
		//SetBkColor(hdc, RGB(0,0,0));
		//SetBkMode(hdc, OPAQUE);
		//sprintf(buffer,"Up Arrow: = %d	",KEYDOWN(VK_UP));
		//TextOut(hdc, 0,0, buffer, strlen(buffer));
		//sprintf(buffer,"Down Arrow: = %d	",KEYDOWN(VK_DOWN));
		//TextOut(hdc, 0,16, buffer, strlen(buffer));
		//sprintf(buffer,"Right Arrow: = %d	",KEYDOWN(VK_RIGHT));
		//TextOut(hdc, 0,32, buffer, strlen(buffer));
		//sprintf(buffer,"Left Arrow: = %d	",KEYDOWN(VK_LEFT));
		//TextOut(hdc, 0,48, buffer, strlen(buffer));

		//for (int index = 0; index < 1000; index++)
		//{
			//int x = rand()%400;
			//int y = rand()%400;
			//COLORREF color = RGB(rand()%255,rand()%255,rand()%255);

			//SetPixel(hdc,x,y,color);
		//}

		//for (int index = 0; index < 1000; index++)
		//{
			//int x1 = rand()%400;
			//int y1 = rand()%400;
			//int x2 = rand()%400;
			//int y2 = rand()%400;
			//COLORREF color = RGB(rand()%255,rand()%255,rand()%255);
			//HPEN pen = CreatePen(PS_SOLID, 1, color);
			//HPEN old_pen = (HPEN)SelectObject(hdc, pen);
			//MoveToEx(hdc,x1,y1,NULL);
			//LineTo(hdc,x2,y2);
			//SelectObject(hdc, old_pen);
			//DeleteObject(pen);
		//}

		//HPEN blue_pen = CreatePen(PS_SOLID, 1, RGB(0,0,255));
		//HBRUSH red_brush = CreateSolidBrush(RGB(255,0,0));
		//HPEN old_pen = (HPEN)SelectObject(hdc, blue_pen);
		//HBRUSH old_brush = (HBRUSH)SelectObject(hdc, red_brush);
		//Rectangle(hdc,10,10,100,100);
		//SelectObject(hdc, old_pen);
		//SelectObject(hdc, old_brush);
		//DeleteObject(blue_pen);
		//DeleteObject(red_brush);

		//HPEN green_pen = CreatePen(PS_SOLID, 1, RGB(0,255,0));
		//HBRUSH green_brush = CreateSolidBrush(RGB(0,255,0));
		//HPEN old_pen = (HPEN)SelectObject(hdc,green_pen);
		//HBRUSH old_brush = (HBRUSH)SelectObject(hdc,green_brush);
		//Ellipse(hdc,30,30,70,70);
		//SelectObject(hdc,old_pen);
		//SelectObject(hdc,old_brush);
		//DeleteObject(green_pen);
		//DeleteObject(green_brush);
		
		ReleaseDC(hwnd, hdc);

		while((GetTickCount() - start_time) < 33);

		if (KEYDOWN(VK_ESCAPE))
		{
			SendMessage(hwnd, WM_CLOSE, 0,0);
		}
	}
	return(msg.wParam);
}



now the NEW one that doesn't work:

// RoughStart - A fullscreen window running at 30fps

#define WIN32_LEAN_AND_MEAN

// INCLUDES ////////////////////////////////////////////////
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <math.h>
#include <mmsystem.h>

// DEFINES /////////////////////////////////////////////////
#define WINDOW_CLASS_NAME "GAMEWINDOW"

// MACROS //////////////////////////////////////////////////
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

// GLOBALS //////////////////////////////////////////////////
HINSTANCE hinstance_app;

// FUNCTIONS ////////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	PAINTSTRUCT ps;
	HDC hdc;

	switch(msg)
	{
	case WM_CREATE:
		{
			return(0);
		} break;
	case WM_COMMAND:
		{

		} break;
	case WM_PAINT:
		{
			hdc = BeginPaint(hwnd, &ps);
			EndPaint(hwnd, &ps);
			return(0);
		} break;
	case WM_CLOSE:
		{
			int result = MessageBox(hwnd, "Are you sure you want to exit?", "Exit Program?", MB_YESNO | MB_ICONQUESTION);
			if (result == IDYES)
			{
				return (DefWindowProc(hwnd, msg, wparam, lparam));
			}
			else
			{
				return(0);
			}
		} break;
	case WM_DESTROY:
		{
			PostQuitMessage(0);
			return(0);
		} break;
	default: break;
	}
	return(DefWindowProc(hwnd, msg, wparam, lparam));
}

// WINMAIN //////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
	WNDCLASSEX winclass;
	HWND hwnd;
	MSG msg;
	HDC hdc;

	winclass.cbSize			= sizeof(WNDCLASSEX);
	winclass.style			= CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
	winclass.lpfnWndProc	= WindowProc;
	winclass.cbClsExtra		= 0;
	winclass.cbWndExtra		= 0;
	winclass.hInstance		= hinstance;
	winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
	winclass.lpszMenuName	= NULL;
	winclass.lpszClassName	= WINDOW_CLASS_NAME;
	winclass.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);

	hinstance_app = hinstance;

	if (!RegisterClassEx(&winclass))
	{
		return(0);
	}

	if(!(hwnd = CreateWindowEx(NULL,
							   WINDOW_CLASS_NAME,
							   "Game Window",
							   WS_POPUP | WS_VISIBLE,
							   0,0,
							   GetSystemMetrics(SM_CXSCREEN),
							   GetSystemMetrics(SM_CXSCREEN),
							   NULL,
							   NULL,
							   hinstance,
							   NULL)))
	{
		return (0);
	}

	while(TRUE)
	{
		DWORD start_time = GetTickCount();
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if (msg.message == WM_QUIT)
			{
				break;
			}
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		while((GetTickCount() - start_time) < 33);

		if (KEYDOWN(VK_ESCAPE))
		{
			SendMessage(hwnd, WM_CLOSE, 0,0);
		}
	}

	return(msg.wParam);
}



And here is the build log:


------ Build started: Project: Rough Start, Configuration: Debug Win32 ------
Compiling...
Main.cpp
c:\documents and settings\jason bickford\my documents\visual studio 2005\projects\rough start\rough start\main.cpp(46) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [32]' to 'LPCWSTR'
		Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\jason bickford\my documents\visual studio 2005\projects\rough start\rough start\main.cpp(84) : error C2440: '=' : cannot convert from 'const char [11]' to 'LPCWSTR'
		Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\jason bickford\my documents\visual studio 2005\projects\rough start\rough start\main.cpp(104) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [11]' to 'LPCWSTR'
		Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\jason bickford\my documents\visual studio 2005\projects\rough start\rough start\main.cpp(130) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data
Build log was saved at "file://c:\Documents and Settings\Jason Bickford\My Documents\Visual Studio 2005\Projects\Rough Start\Rough Start\Debug\BuildLog.htm"
Rough Start - 3 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Is This A Good Question/Topic? 0
  • +

Replies To: cannot convert parameter 2 from 'const char [32]' to 'LPCW

#2 ajwsurfer  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 373
  • Joined: 24-October 06

Re: cannot convert parameter 2 from 'const char [32]' to 'LPCW

Posted 11 September 2007 - 09:54 AM

You can start with the first line of the error message:

c:\documents and settings\jason bickford\my documents\visual studio 2005\projects\rough start\rough start\main.cpp(46) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [32]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Also notice that the one that does not work is missing:

#include <stdlib.h>

P.S. I hope that the stdlib.h file carries the definition needed to convert from 'const char [32]' to 'LPCWSTR'

;)

This post has been edited by ajwsurfer: 11 September 2007 - 09:55 AM

Was This Post Helpful? 0
  • +
  • -

#6 help-linux  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 54
  • Joined: 12-August 06

Re: cannot convert parameter 2 from 'const char [32]' to 'LPCW

Posted 11 September 2007 - 12:18 PM

Failing that, go to:
Project -> <your project name> Propertys -> General;
Change "Character set" to "Use multi-byte character set"
Was This Post Helpful? 1

#7 ModestBigferd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-September 07

Re: cannot convert parameter 2 from 'const char [32]' to 'LPCW

Posted 11 September 2007 - 06:55 PM

Sweet, changing the character set did the trick. It's weird though that I never had to change the first one. Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1