Sign in to follow this  
disknoir1984

visual studio 2008 win32 problem

Recommended Posts

I've been using dev c++ while learning c++ for the past two years. I want to learn to use the win32 api which works fine with devc++. However, as I will eventually want to use directx, I downloaded visual studio 2008 express. The code that works in devc++ does not work in vs. I'm sure that its just a setup issue, but with the mass of info regarding vs 2008 I can't seem to figure out whats going on. As I say, I'm new to windows programming and i'm finding he learning curve pretty steep. This is the basic code i'm trying to compile:
#include <windows.h>

HINSTANCE hInst;
HWND wndHandle;

bool initWindow(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, 
				   HINSTANCE hPrevInstance, 
				   LPTSTR lpCmdLine, int nCmdShow)
{
	if (!initWindow(hInstance))
		return false;
	
	// Main message loop:
    MSG msg; 
    ZeroMemory( &msg, sizeof(msg) );
    while( msg.message!=WM_QUIT )
    {
		if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
        {
			TranslateMessage( &msg );
            DispatchMessage( &msg );
        }		
    }
		
	return (int) msg.wParam;
}

bool initWindow(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= 0;
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName	= "DirectXExample";
	wcex.hIconSm		= 0;
	RegisterClassEx(&wcex);

	
	wndHandle = CreateWindow("DirectXExample", 
							 "DirectXExample", 
							 WS_OVERLAPPEDWINDOW,
							 CW_USEDEFAULT, 
							 CW_USEDEFAULT, 
							 640, 
							 480, 
							 NULL, 
							 NULL, 
							 hInstance, 
							 NULL);
   if (!wndHandle)
      return false;
   
   ShowWindow(wndHandle, SW_SHOW);
   UpdateWindow(wndHandle);

   return true;
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
	{
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}

and this is the error i'm getting:
Compiling...
winmain.cpp
d:\my documents\visual studio 2008\projects\project 1\project 1\winmain.cpp(19) : error C2731: 'WinMain' : function cannot be overloaded
        d:\my documents\visual studio 2008\projects\project 1\project 1\winmain.cpp(16) : see declaration of 'WinMain'
d:\my documents\visual studio 2008\projects\project 1\project 1\winmain.cpp(52) : error C2440: '=' : cannot convert from 'const char [15]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\my documents\visual studio 2008\projects\project 1\project 1\winmain.cpp(67) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [15]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build log was saved at "file://d:\My Documents\Visual Studio 2008\Projects\project 1\project 1\Debug\BuildLog.htm"
project 1 - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

If there is something simple that I'm missing, please enlighten me. If not, is there a book or web resourse that will help. Thanks

Share this post


Link to post
Share on other sites
Short answer: go to project properties, General, Character Set and change from Unicode to Use Multi Byte Character Set.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this