I'm tired of C++

Started by
33 comments, last by demonkoryu 18 years, 5 months ago
I'm so frustrated...I wish a could make someone come to my house and make my c++ compiler work! I have Borland 5.5 and Dev 4.9.9.2 but none of the source code from my c++ book works! I can't make a blank window without a million errors! Please help before I kill myself.
Advertisement
What error messages are you getting?
Stupid stuff like "undefined symbol in function 1"
Perhaps more importantly, what book were you tricked into getting?
You may be programming, not on a computer, but on a large, sedentary, and confused German Shepherd. That won't work. Make sure that the thing you're programming on has a keyboard (computer!) and not a shaggy coat (dog!).

If you are indeed programming on a computer, post the EXACT code you're using and the EXACT error messages and we can help you.
Quote:Original post by Evil Booger
Stupid stuff like "undefined symbol in function 1"


Are you making a windows program (with buttons and everything), or a console program? You will get undefined symbol errors if you try to make a program using the Win32 API if you don't create a windows project. In dev-C++ I believe you can do it like this:

project->project options-> and under "type" choose Win32 GUI.

Edit: OOps, that's undefined external. Ignore me.
A couple...well more like 3 "Sams Programming C++ in 24 hours"; "Directx Programming in 21 days"; "Programming Role Playing Games with Directx."
Here's the code:


//////////////////////////////////////////////////////
// BasicWindowsApp.cpp
//////////////////////////////////////////////////////

#include <windows.h>

// Function prototypes.
LRESULT WINAPI WndProc(HWND hWnd, UINT msg,
WPARAM wParam, LPARAM lParam);
void RegisterWindowClass(HINSTANCE hInstance);
void CreateAppWindow(HINSTANCE hInstance);
WPARAM StartMessageLoop();

// Global variables.
HWND g_hWnd;


//////////////////////////////////////////////////////
// WinMain()
//////////////////////////////////////////////////////
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, INT)
{
RegisterWindowClass(hInstance);
CreateAppWindow(hInstance);
ShowWindow(g_hWnd, SW_SHOWDEFAULT);
UpdateWindow(g_hWnd);
INT result = StartMessageLoop();
return result;
}

//////////////////////////////////////////////////////
// WndProc()
//////////////////////////////////////////////////////
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
return 0;

case WM_DESTROY:
PostQuitMessage( 0 );
return 0;

case WM_PAINT:
ValidateRect(g_hWnd, NULL);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}

//////////////////////////////////////////////////////
// RegisterWindowClass()
//////////////////////////////////////////////////////
void RegisterWindowClass(HINSTANCE hInstance)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "WinApp";
wc.hIconSm = NULL;

RegisterClassEx(&wc);
}

//////////////////////////////////////////////////////
// CreateAppWindow()
//////////////////////////////////////////////////////
void CreateAppWindow(HINSTANCE hInstance)
{
g_hWnd = CreateWindowEx(
NULL,
"WinApp",
"Basic Windows Application",
WS_OVERLAPPEDWINDOW,
100,
100,
648,
514,
GetDesktopWindow(),
NULL,
hInstance,
NULL);
}

//////////////////////////////////////////////////////
// StartMessageLoop()
//////////////////////////////////////////////////////
WPARAM StartMessageLoop()
{
MSG msg;
while(1)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// Use idle time here.
}
}
return msg.wParam;
}
Cool. And the exact error message? (BTW: in the future, if you post your code between [ source] and [ /source] tags (remove the spaces) it will be formatted nicely.)
It compiles perfectly for me, using Dev-C++ 4.9.9.2 .

This topic is closed to new replies.

Advertisement