Sign in to follow this  
Evil Booger

I'm tired of C++

Recommended Posts

Evil Booger    100
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.

Share this post


Link to post
Share on other sites
Sneftel    1788
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.

Share this post


Link to post
Share on other sites
Drakkcon    612
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.

Share this post


Link to post
Share on other sites
Evil Booger    100
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;
}

Share this post


Link to post
Share on other sites
Sneftel    1788
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.)

Share this post


Link to post
Share on other sites
Evil Booger    100
C:\Documents and Settings\DC Jones\Desktop\BasicWindowsApp.cpp In function `void CreateAppWindow(HINSTANCE__*)':

and

[Linker error] undefined reference to `GetStockObject@4'


is what I get using Dev C++ 4.9.9.2
How did you set yours up?

Share this post


Link to post
Share on other sites
crazykid48x    100
Dude, start with "Sams Programming C++ in 24 hours". then slowly work your way up to the other two books. as for your error you need to click file->new project and choose a windows aplication, then it should work, if not you need the devpak. Go to tools->check for updates and find a windows32 API devpak there.

Share this post


Link to post
Share on other sites
Roboguy    794
Quote:
Original post by skyfire
i make sure i have the proper devpaks installed before i start up a project. you can get all sorts of devpaks from devpaks.org.


He's using Borland, not MingW

Share this post


Link to post
Share on other sites
Drakkcon    612
He still needs to choose some kind of "windows app" check. This will include the proper files (kernel32.lib, gdi.lib, etc.) That undefined reference is because he isn't linking all the libraries he needs to be linking.

Share this post


Link to post
Share on other sites
Mxz    504
As a general rule, you should avoid books with titles along the lines of "Learn yourself a C++ guru in 24 visual hours!". The reason being, you cannot really learn C++ in a year, nevermind 24 hours.

Share this post


Link to post
Share on other sites
smonahan    138
Quote:
Original post by Mxz
As a general rule, you should avoid books with titles along the lines of "Learn yourself a C++ guru in 24 visual hours!". The reason being, you cannot really learn C++ in a year, nevermind 24 hours.



Heck, a year is even too short. I've been programming in C++ for 6 years and I have a degree and I still have a lot to learn.

Share this post


Link to post
Share on other sites
aaroncox1234    298
Quote:
Original post by smonahan
Quote:
Original post by Mxz
As a general rule, you should avoid books with titles along the lines of "Learn yourself a C++ guru in 24 visual hours!". The reason being, you cannot really learn C++ in a year, nevermind 24 hours.



Heck, a year is even too short. I've been programming in C++ for 6 years and I have a degree and I still have a lot to learn.


Then clearly you've never read "Learn yourself a C++ guru in 24 visual hours!".

Share this post


Link to post
Share on other sites
Vexorian    152
Quote:
Original post by Roboguy
Quote:
Original post by skyfire
i make sure i have the proper devpaks installed before i start up a project. you can get all sorts of devpaks from devpaks.org.


He's using Borland, not MingW


He tried in both borland's and dev-cpp (See first post)

And seriously, no one is going to force you to go c++, but if you ever find a problem be more specific from the start

I think that your issue is that you started with windows stuff too fast? you could have started with console things. Like hello word.

Books are overrated, there is nothing better than an online manual, wiki, articles + forums, well those are my 2 cents.


Quote:
As a general rule, you should avoid books with titles along the lines of "Learn yourself a C++ guru in 24 visual hours!". The reason being, you cannot really learn C++ in a year, nevermind 24 hours.


I learned cpp in 1 month, I think that we should say that there is no rule like "you cannot learn c++ in a learn" nor "you must learn c++ in a month" it all depends on the learning guy.

(PS: I had knowledge of many other languages before starting cpp that might be the reason of my speed)

Share this post


Link to post
Share on other sites
dbzprogrammer    100
You can learn different levels of C++ in so much time. No one person has learned the entire "C++" because you would have to know every library and everything. Learning the language could take about a month. Understanding it, a few more. Knowing C++, about a year. Becoming a intermediate, 3 years. There's no exact way to learn it, and you won't learn in it in a set amount of time. If you friend learned a part in 8 months, it could take you only 3! So have fun...

Share this post


Link to post
Share on other sites
Spoonbender    1258
Quote:
Original post by Evil Booger
Well I just thought it would be a good place to start.


Nothing wrong with that. But you should start out with simple console applications, and stay away from windowed apps, graphics and anything else until you have a firm grasp on the language.
I know it doesn't look as exciting, but on the upside, you'll actually understand what you're doing, and you'll be able to fix the errors you get. [wink]

As for your problem, do you have the Windows SDK installed? Otherwise it won't be able to find the Win32 functions you call.

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