Click to See Complete Forum and Search --> : getting started


daydreamerz
September 26th, 2006, 07:11 PM
I want to start learning how to make windows applications using visual c++ express so I downloaded the microsoft platform sdk. I found this sample code on a website and I tried to run it just to see if I did eveything right.

#include <windows.h>

LRESULT WndProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndClsEx;

WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProcedure;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hInstance = hInstance;

return 0;
}

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



and I got these errors
.\win.cpp(12) : error C2440: '=' : cannot convert from 'LRESULT (__cdecl *)(HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
.\win.cpp(21) : error C2373: 'WndProcedure' : redefinition; different type modifiers
.\win.cpp(3) : see declaration of 'WndProcedure'

so, I just wanted to know if there's something wrong within the program or did I not download everything right.

UnfitElf
September 26th, 2006, 08:29 PM
Hi daydreamerz,

// LRESULT WndProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// Should be
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); Note: Your programe has no message pump and is never creating a window so when it is executed u wont see anything on the screen but is does actually 'run'

Happy programming :)

Notsosuperhero
September 26th, 2006, 09:36 PM
In your function prototype, use
LRESULT CALLBACK WndProcedure(...)[/url]
instead of
[code]
LRESULT WndPrcedure(...)

And that should get rid of those errors.

daydreamerz
September 27th, 2006, 12:10 AM
Thank you, I figured it out :)