GUI compiles in Dev C++ but not VC++
I'm trying to learn GUI and I'm having a tough time even starting because some things will only compile in Dev C++ and some things will only compile in VC++.
I went to this site trying to compile some of their GUI applications to get a feel for them and many of them won't even work on either compilers, I've only found one of them to work with Dev C++.
I'm not sure how to fix them or get them to work. I like using VC++ and I don't much like bloodshed. Could you help me figure out how to start running GUI applications in VC++ so I can start learning it?
I'm spending more time trying to actually find examples that run in a compiler than I am actually doing any learning.
Thanks.
Here's the code I'm trying to run, and a site with examples where most of them arent even working in either compilers:
http://www.foosyerdoos.fsnet.co.uk/MainFiles/DynaContainFiles/Cont.html
Please help!
Code for program that will run in Dev C++ but not VC++:
//=========================================================================================
//SIMPLE WINDOW - Copyright 2000-2002 Ken Fitlike
//=========================================================================================
//API functions used: CreateWindowEx,DefWindowProc,DispatchMessage,GetMessage,
//GetSystemMetrics,LoadImage,MessageBox,PostQuitMessage,RegisterClassEx,ShowWindow,
//UpdateWindow,TranslateMessage,WinMain.
//=========================================================================================
//
//=========================================================================================
//#define UNICODE //make active when compiling on WinNT/2000/XP (W-fns)
#define WIN32_LEAN_AND_MEAN //optional: no mfc
#include <windows.h> //include all the basics
//=========================================================================================
//LCC-WIN32 Specific: LR_SHARED (used by LoadImage API function) is currently not defined
//in WIN.H. If you have a later version of this lcc-win32 header that defines LR_SHARED
//then you may safely discard the following conditional definition.
#if !defined LR_SHARED
#define LR_SHARED 0x00008000 //required only for lcc-win32 (Aug 2002)
#endif
//=========================================================================================
//declare the Window procedure where all messages will be handled
LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam);
//=========================================================================================
//start the application; all win32 applications require a WinMain function
//that the windows operating system looks for as an entry point to that application
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
HWND hwnd; //the wnd handle
MSG Msg; //a simple structure for storing message information
HICON hIcon; //window icon
HCURSOR hCursor; //window cursor
//declare and initialise wnd registration information variables
TCHAR chClassName[]=TEXT("SIMPLEWND");
WNDCLASSEX wcx; //this structure is used for storing information about the wnd 'class'
//use 'LoadImage' to load wnd class icon and cursor as it supercedes the obsolete functions
//'LoadIcon' and 'LoadCursor', although these functions will still work. Because the icon and
//cursor are loaded from system resources ie they are shared, it is not necessary to free the
//image resources with either 'DestroyIcon' or 'DestroyCursor'.
hIcon=(HICON)LoadImage(0,IDI_APPLICATION,IMAGE_ICON,0,0,LR_SHARED);
hCursor=(HCURSOR)LoadImage(0,IDC_ARROW,IMAGE_CURSOR,0,0,LR_SHARED);
wcx.cbSize = sizeof(WNDCLASSEX); //byte size of WNDCLASSEX struct
wcx.style = CS_HREDRAW|CS_VREDRAW; //ensure wnd is always redrawn
wcx.lpfnWndProc = (WNDPROC)WndProc; //pointer to the Window Procedure
wcx.cbClsExtra = 0; //Extra bytes for 'class' wnds
wcx.cbWndExtra = 0; //Extra bytes for this wnd
wcx.hInstance = hInstance; //Application instance
wcx.hIcon = hIcon; //Application icon
wcx.hCursor = hCursor; //Cursor for wnd
wcx.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); //Background wnd colour
wcx.lpszMenuName = NULL; //Name of wnd menu
wcx.lpszClassName = chClassName; //Name of this wnd 'class'
wcx.hIconSm = NULL; //Icon in top-left corner of wnd
//Register the wnd class with the Windows system
if (!RegisterClassEx(&wcx))
{
//Registration has failed so inform the user
MessageBox( NULL,
TEXT("Failed to register wnd class"),
TEXT("ERROR"),
MB_OK|MB_ICONERROR);
return FALSE;
}
//create wnd of the 'class' just registered
hwnd=CreateWindowEx(0, //more or 'extended' styles
chClassName, //the 'class' of window to create
TEXT("Simple Window"), //the window title
WS_OVERLAPPEDWINDOW, //window style: how it looks
GetSystemMetrics(SM_CXSCREEN)/4, //window position: left
GetSystemMetrics(SM_CYSCREEN)/4, //window position: top
GetSystemMetrics(SM_CXSCREEN)/2, //window width
GetSystemMetrics(SM_CYSCREEN)/2, //window height
NULL, //parent window handle
NULL, //handle to this windows's menu
hInstance, //application instance
NULL); //user defined information
if (!hwnd)
{
//wnd creation has failed so inform the user
MessageBox( NULL,
TEXT("Failed to create wnd"),
TEXT("ERROR"),
MB_OK|MB_ICONERROR);
return FALSE;
}
//Display the wnd
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
//start message loop
while (GetMessage(&Msg,NULL,0,0)>0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
//=========================================================================================
LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
switch (Message)
{
case WM_DESTROY:
PostQuitMessage(0); //signal end of application
return 0;
default:
return DefWindowProc(hwnd,Message,wParam,lParam); //let system deal with msg
}
}
//=========================================================================================
[7533 byte] By [
wolfcry044] at [2007-11-20 11:55:57]

# 1 Re: GUI compiles in Dev C++ but not VC++
Please make your mind: it doesn't compile or it doesn't run? Please list the errors that you get, if any.
cilu at 2007-11-11 4:02:04 >

# 2 Re: GUI compiles in Dev C++ but not VC++
It doesn't compile. This particular program compiles fine in Dev C++ but not in VC++. The others don't even compile in either of them.
Here's the errors I get in VC++ when I try to compile the above program:
1>-- Build started: Project: window, Configuration: Release Win32 --
1>Compiling...
1>window.cpp
1>.\window.cpp(26) : error C2146: syntax error : missing ';' before identifier 'CALLBACK'
1>.\window.cpp(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(26) : error C2146: syntax error : missing ';' before identifier 'WndProc'
1>.\window.cpp(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(26) : error C2065: 'HWND' : undeclared identifier
1>.\window.cpp(26) : error C2146: syntax error : missing ')' before identifier 'hwnd'
1>.\window.cpp(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(26) : error C2059: syntax error : ')'
1>.\window.cpp(30) : error C2146: syntax error : missing ';' before identifier 'WinMain'
1>.\window.cpp(30) : error C2065: 'HINSTANCE' : undeclared identifier
1>.\window.cpp(30) : error C2146: syntax error : missing ')' before identifier 'hInstance'
1>.\window.cpp(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(30) : error C2059: syntax error : ')'
1>.\window.cpp(31) : error C2143: syntax error : missing ';' before '{'
1>.\window.cpp(31) : error C2447: '{' : missing function header (old-style formal list?)
1>.\window.cpp(101) : error C2146: syntax error : missing ';' before identifier 'CALLBACK'
1>.\window.cpp(101) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(101) : error C2086: 'int LRESULT' : redefinition
1> .\window.cpp(26) : see declaration of 'LRESULT'
1>.\window.cpp(101) : error C2146: syntax error : missing ';' before identifier 'WndProc'
1>.\window.cpp(101) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(101) : error C2086: 'int CALLBACK' : redefinition
1> .\window.cpp(26) : see declaration of 'CALLBACK'
1>.\window.cpp(101) : error C2146: syntax error : missing ')' before identifier 'hwnd'
1>.\window.cpp(101) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(101) : error C2374: 'WndProc' : redefinition; multiple initialization
1> .\window.cpp(26) : see declaration of 'WndProc'
1>.\window.cpp(101) : error C2059: syntax error : ')'
1>.\window.cpp(102) : error C2143: syntax error : missing ';' before '{'
1>.\window.cpp(102) : error C2447: '{' : missing function header (old-style formal list?)
# 3 Re: GUI compiles in Dev C++ but not VC++
It doesn't compile. This particular program compiles fine in Dev C++ but not in VC++. The others don't even compile in either of them. First, what type of project did you create?
Second, what version of Visual C++ are you using? I had no trouble creating an empty Win32 project, and adding the code you posted. It compiled and executed with no problems on Visual Studio 2005.
Regards,
Paul McKenzie
# 4 Re: GUI compiles in Dev C++ but not VC++
I tried windows 32 consol application as well as new blank project. Consol application came with errors and blank project would compile but no .exe would form.
I'm using 2005 express edition.
# 5 Re: GUI compiles in Dev C++ but not VC++
I tried windows 32 consol applicationNo. You should select Win32 Project, not console.
Even if you did choose console, you should have gotten no errors compiling the code (the linker would give you an error, saying that main() is an unresolved external).
Regards,
Paul McKenzie
# 6 Re: GUI compiles in Dev C++ but not VC++
I don't see win 32 project in the list.
# 7 Re: GUI compiles in Dev C++ but not VC++
I've never used Visual C++ Express, so I don't know what it does or doesn't have.
Create a console program, and go to the properties for the project. The Linker setting for System/SubSystem should be "Windows", not Console. Also, as my last post was edited, compiling this program should have produced no errors.
Regards,
Paul McKenzie
# 8 Re: GUI compiles in Dev C++ but not VC++
I set it to windows and compiled it and it still gives me the following errors:
1>-- Build started: Project: window, Configuration: Release Win32 --
1>Compiling...
1>window.cpp
1>.\window.cpp(4) : error C2146: syntax error : missing ';' before identifier 'CALLBACK'
1>.\window.cpp(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(4) : error C2146: syntax error : missing ';' before identifier 'WndProc'
1>.\window.cpp(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(4) : error C2065: 'HWND' : undeclared identifier
1>.\window.cpp(4) : error C2065: 'UINT' : undeclared identifier
1>.\window.cpp(4) : error C2065: 'WPARAM' : undeclared identifier
1>.\window.cpp(4) : error C2065: 'LPARAM' : undeclared identifier
1>.\window.cpp(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(4) : error C2078: too many initializers
1>.\window.cpp(7) : error C2146: syntax error : missing ';' before identifier 'zhInstance'
1>.\window.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(9) : error C2146: syntax error : missing ';' before identifier 'WinMain'
1>.\window.cpp(9) : error C2146: syntax error : missing ')' before identifier 'hInstance'
1>.\window.cpp(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(9) : error C2059: syntax error : ')'
1>.\window.cpp(9) : error C2143: syntax error : missing ';' before '{'
1>.\window.cpp(9) : error C2447: '{' : missing function header (old-style formal list?)
1>.\window.cpp(57) : error C2146: syntax error : missing ';' before identifier 'CALLBACK'
1>.\window.cpp(57) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(57) : error C2086: 'int LRESULT' : redefinition
1> .\window.cpp(4) : see declaration of 'LRESULT'
1>.\window.cpp(57) : error C2146: syntax error : missing ';' before identifier 'WndProc'
1>.\window.cpp(57) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(57) : error C2086: 'int CALLBACK' : redefinition
1> .\window.cpp(4) : see declaration of 'CALLBACK'
1>.\window.cpp(57) : error C2146: syntax error : missing ')' before identifier 'hwnd'
1>.\window.cpp(57) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(57) : error C2374: 'WndProc' : redefinition; multiple initialization
1> .\window.cpp(4) : see declaration of 'WndProc'
1>.\window.cpp(57) : error C2059: syntax error : ')'
1>.\window.cpp(57) : error C2143: syntax error : missing ';' before '{'
1>.\window.cpp(57) : error C2447: '{' : missing function header (old-style formal list?)
1>Build log was saved at "file://c:\Documents and Settings\Wolfcry044\My Documents\Visual Studio 2005\Projects\window\window\Release\BuildLog.htm"
1>window - 31 error(s), 0 warning(s)
# 9 Re: GUI compiles in Dev C++ but not VC++
I set it to windows and compiled it and it still gives me the following errors:
Start simple.
Compile this one line file:
#include <windows.h>
Does this compile with no errors?
If it does, then move on:
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam);
Does this compile? If it doesn't then there is something happening where those definitions are being wiped out, since all of those definitions such as LPARAM, WPARAM, etc, are defined by including <windows.h>
Regards,
Paul McKenzie
# 10 Re: GUI compiles in Dev C++ but not VC++
Doesn't work with that either. What do I do to fix the definitions?
Here's what I get with that small bit of code:
1>-- Build started: Project: window, Configuration: Release Win32 --
1>Compiling...
1>window.cpp
1>.\window.cpp(3) : error C2146: syntax error : missing ';' before identifier 'CALLBACK'
1>.\window.cpp(3) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(3) : error C2146: syntax error : missing ';' before identifier 'WndProc'
1>.\window.cpp(3) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(3) : error C2065: 'HWND' : undeclared identifier
1>.\window.cpp(3) : error C2146: syntax error : missing ')' before identifier 'hwnd'
1>.\window.cpp(3) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\window.cpp(3) : error C2059: syntax error : ')'
1>Build log was saved at "file://c:\Documents and Settings\Wolfcry044\My Documents\Visual Studio 2005\Projects\window\window\Release\BuildLog.htm"
1>window - 8 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
# 11 Re: GUI compiles in Dev C++ but not VC++
I tried windows 32 consol application as well as new blank project. Consol application came with errors and blank project would compile but no .exe would form.
I'm using 2005 express edition.
That's the problem. Express does not come with windows SDK. Please refer to this FAQ for more: http://www.dev-archive.com/forum/showthread.php?t=428064.
cilu at 2007-11-11 4:12:18 >

# 12 Re: GUI compiles in Dev C++ but not VC++
I installed Microsoft Platform SDK for windows server 2003 R2 and the correct folders are pointed in the compiler. Is that the right SDK?