///////////////////////////////////////////////////////////////////////////////
//winmain.cpp //
// //
//Hello, World! //
// //
//Copyright (C) 2002, John de Michele //
//Based on hellowin.c in Petzold, 5E //
///////////////////////////////////////////////////////////////////////////////
//-------------------------------Includes------------------------------------//
#include <windows.h>
//------------------------------Prototypes-----------------------------------//
LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
//-------------------------------Functions-----------------------------------//
///////////////////////////////////////////////////////////////////////////////
//WinMain() //
// //
//Main Windows function. //
// //
///////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iShowCmd) {
static TCHAR szAppName[] = TEXT("Hello, World!");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass)) {
MessageBox(NULL, TEXT("This program requires Windows NT!"), szAppName, MB_ICONERROR);
return (0);
}
hwnd = CreateWindow (szAppName, //window class name
TEXT("Hello World!"), //window caption
WS_OVERLAPPEDWINDOW, //window style
CW_USEDEFAULT, //initial x position
CW_USEDEFAULT, //initial y position
CW_USEDEFAULT, //initial x size
CW_USEDEFAULT, //initial y size
NULL, //parent window handle
NULL, //window menu handle
hInstance, //program instance handle
NULL); //creation parameters
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
///////////////////////////////////////////////////////////////////////////////
//WinProc() //
// //
//Windows message processing. //
// //
///////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch (message) {
case WM_CREATE: {
PlaySound(TEXT("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC);
return (0);
break;
}
case WM_PAINT: {
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, ▭);
DrawText(hdc, TEXT("Hello, World!"), -1, ▭, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hwnd, &ps);
return (0);
break;
}
case WM_DESTROY: {
PostQuitMessage(0);
return (0);
break;
}
default: {
return DefWindowProc(hwnd, message, wParam, lParam);
break;
}
}; //switch
}
///////////////////////////////////////////////////////////////////////////////
//End winmain.cpp //
///////////////////////////////////////////////////////////////////////////////
Problems with VC++7/ .Net
Hey all --
Ok, I'm trying to get VC++ 7 to compile this simple (?) Windows program:
VC++ 7 builds this without any errors, but when I try to link it, I get this linker error:
error LNK2001: unresolved external symbol _WinMainCRTStartup
Here is my linker command line:
/OUT:"Debug/Wintest.exe" /INCREMENTAL /NOLOGO /DEBUG /PDB:"Debug/Wintest.pdb" /SUBSYSTEM:WINDOWS /MACHINE:IX86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib winmm.lib
Any ideas?
John.
[edited by - JohnAD on August 28, 2002 11:15:07 PM]
[edited by - JohnAD on August 28, 2002 11:15:25 PM]
try changing SUBSYSTEM:WINDOWS to SUBSYSTEM:WIN32
but then again i dont know what im talking about so dont listen to me
but then again i dont know what im talking about so dont listen to me
There doesn''t appear to be a SUBSYSTEM:WIN32 option. When I tried changing SUBSYTEM to WIN32 it went back to WINDOWS.
John.
John.
Well, at this point it seems like the only option is to reinstall. I''m going to have to do that with my VS 6 as well, which started this problem in the first place.
John.
John.
How did you create this project in the first place? Theres a wizard that sets up a boilerplate Win32 app for you.
"PL/I and Ada started out with all the bloat, were very daunting languages, and got bad reputations (deservedly). C++ has shown that if you slowly bloat up a language over a period of years, people don''t seem to mind as much."
James Hague
"PL/I and Ada started out with all the bloat, were very daunting languages, and got bad reputations (deservedly). C++ has shown that if you slowly bloat up a language over a period of years, people don''t seem to mind as much."
James Hague
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Arild Fines:
Yes, I know. I created a blank Win32 Windows app, and then copied the winmain.cpp text from the file that I had it in. I guess I can try what is automatically generated when I get home from work, but at this point I''m very frustrated.
John.
Yes, I know. I created a blank Win32 Windows app, and then copied the winmain.cpp text from the file that I had it in. I guess I can try what is automatically generated when I get home from work, but at this point I''m very frustrated.
John.
I can get Visual C++ 6.0 to give me that error if I go into the Project Settings, go to the Link tab, select the Input category and check Ignore all default libraries. Make sure that setting is not checked.
If that doesn''t help, you could try explicitly linking with libc.lib.
If that doesn''t help, you could try explicitly linking with libc.lib.
When using the Windows calculator program, always remember to clear any values from memory before exiting to prevent burn-in.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement