Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Tac-Tics

Why is C++ so confusing?

This topic is 5993 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I really understand Java easily. But there''s something about learning the more complex parts of C++ I don''t get. I''m trying to figure out Windows programming and graphics and stuff, but I''m having a much more difficult time doing so. So here are my questions.... In windows programming, why do they use all those abstract class names like HWND, LPCTSTR, and WNDCLASSEX? I don''t get it. Anyway, is there any documentation on what each of those classes actually are? I know a lot of times it''s more helpful to learn "hands-on", finding out what each expression does as you progress.... but it''d be nice to know why so many of these objects are set to NULL in creating a window. If not formal documentation, is there any place that explains the basic "jist" of all of those classes? Also, I keep hearing the word library being flashed around everywhere. Are there any good tutorials out there on how libraries work in C++? As I understand it, libraries just provide more classes and functions for you to use, but how are they different from *.h files? What are DLL''s (and why did they destroy my old computer)? And I how do I link libraries to my programs? Keep in mind I have Borland''s C++ compiler, so I can''t just go to some fancy menu and click "add library" =-) After that, how do I start working with DirectX. I understand it''s a general purpose API for graphics, sound, and input. How do I get it and how to I use it in my programs? I have a book on it, but it works with Visual C++ and mentions libraries several times (thus explaining my previous question). I just need to know how to get started with it. Any help would be *extremely* appreciated. In fact, I may construct a shrine out of soap in your honor if your respond =-) I really want to start working with C++ as well as with Java, but I need some help. "I''''m not evil... I just use the power of good in evil ways."

Share this post


Link to post
Share on other sites
Advertisement
Those structs are made by the windows.h file...
a HWND is a - Handle to a WiNDow (Yeah its cryptic I agree)
WNDCLASSEX is an extended window class (for making windows which
are up to date
and LPCSTR is a Long pointer to a string of some sort

If you know Hungarian notation things are a little easier but
not that much heh...

a lib is basically a compiled .h file you can use.

And as far as the other questions well you need many books hehe

-=Lohrno

Share this post


Link to post
Share on other sites
First off HWND LPCTSTR are not classes and WNDCLASSEX is a struct.

HWND is a four byte value that acts as an ID for a window you''re working with. LPCTSTR is a double pointer to a character (don''t quote me on that one). And WNDCLASSEX is just a set of parameters for your window. If you don''t have MSDN and plan on seriously doing development under windows then I suggest getting it.

You do understandt he concept of using .h and .cpp files right? .h Files are for prototypes for functions/classes and the .cpp files are where the function is implemented. Just remember as a starting c++ coder that you can not allocate any memory within a .h file. Just tell the compiler how the memory looks (if that doesn''t make any sense then sorry).

Ok libraries are precompiled .cpp files. This is so you can distribute code without revieling source. you use the .h files just like you would a regular one. DLLS are dynamicaly linked. Instead of compiling the .lib files into your project you use a precompiled .dll file and the you call functions within the dll. For more info on this topic do a search on this site or google. .lib files are similar to .class files (isn''t that how you distribute code in java?). I''m trying to reference Java stuff for you but I don''t know very much java, just the basics of it. To link a lib in your project you need to put it in your make file if you''re using a command line compiler. For information on make files do a search on google.

If you want to start working with DX I suggest you study as much code as you can. There is a site deticated to it at nexe.gamedev.net (link on main page). In the DX sdk there are help files along with samples. The code is very messy, but once you get the jist of it you can implement your own stuff. Also I would like to point out that using either openGL or dx you need to have a firm knowledge in 3d basics. I also suggest that if you''re going to use DX to know pointers like the back of your hand because DX uses COM which relies heavily on double pointers etc.

Good Luck,
Give me an email if you need any more help.
-ecko

-----------------------------------------------------------
"People who usualy use the word pedantic usualy are pedantic!"-me

Share this post


Link to post
Share on other sites
Maybe you shouldn''t try to learn Win32-- you should learn C++. Example: I''ve been coding in C++ for over a year now, and I still don''t know Win32. I know some that I remember from LaMothe''s Windows book, but that is all and that is not much.

Simple as that.

As to how confusing it is, well, you get used to it.

Share this post


Link to post
Share on other sites
quote:
Original post by Tac-Tics
In windows programming, why do they use all those abstract class names like HWND, LPCTSTR, and WNDCLASSEX? I don''t get it. Anyway, is there any documentation on what each of those classes actually are? I know a lot of times it''s more helpful to learn "hands-on", finding out what each expression does as you progress.... but it''d be nice to know why so many of these objects are set to NULL in creating a window. If not formal documentation, is there any place that explains the basic "jist" of all of those classes?



Ahh... HWND, LPCTSTR... et cetera et cetera et cetera...

That''s just Microsoft''s fault. They use a stupid naming convention called Hungarion Notation-- which accounts for their confusing structure/object names. Don''t ask why they honestly thought it was a good idea... I don''t know.

And if you''re a beginner, use Allegro or SDL-- I refuse to suggest Directx to beginners when even many professionals don''t like using it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I know it''s scary for beginners, but it''s great when you get used to it. For an experienced programmer, it makes things easy because you can pretty much figure out the function by just looking at the prototype.

And remember, the Win32 API is written in C NOT C++.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
And remember, the Win32 API is written in C NOT C++.


If you want a C++ style of coding, use MFC. There is also OWL (the one Borland makes; not Microsoft) but they are essentially the same thing. MFC is just a wrapper of the win32 code except for some of the advanced things it ofers like document-view architecture and some of the data types they provide. I have a fair amount of experience with MFC and win32 never OWL, so I couldn''t tell you which one is more suited for coding games in.

When I do program for Windows I use the win32 API for games and MFC for regular apps. Games don''t need a large amount of interfacing with the OS, so win32 is simple and efficient for that; MFC is good for apps since it usually reduces coding time and has some fairly nifty features. I''ve been coding on Linux/FreeBSD for a while, so I haven''t messed with Windows too much lately.

I generally code in OpenGL, so I can''t help you out too much with Direct3D (unless of course you want some math to do all that 3D stuff; then I could help you; I sure am glad Mathematics isn''t Operating System specific )

Anyways, Good Luck

Share this post


Link to post
Share on other sites
MSDN!!!

that''s where you can find the official documentation from microsoft. And it''s avaiable online:

http://msdn.microsoft.com/

Also you can download the microsoft platform sdk''s from there which will contain everything you need to program for windows and also directx and some other libraries.
It contains both the headers, libs and documentation to do it.

Also it helps to sort out a couple of things in the microsoft naming conventions:

Everything that starts with H are a handle to an object (not exactly the same as pointers)
Everything that starts with LP is a pointer, sometimes only P.
Everything that has C after the type is constant.
And here''s the deal with strings:
TSTR = tchar string (unicode if unicode is defined, and multibyte if multibyte is defined.)
STR = regular string.
WSTR = wide (unicode) string.

So here''s some examples:
HWND = Handle to a window
LPCTSTR = Pointer to a Constant Tchar STRing.

Share this post


Link to post
Share on other sites
quote:
Original post by Floppy
I have a fair amount of experience with MFC and win32 never OWL, so I couldn''t tell you which one is more suited for coding games in.


Neither. Heh. Keep away from MFC as much as possible, hell, don''t even bother using it unless that''s the only way to do something (in which case, it''s probably a bad thing that you want to do anyways).

As for DirectX, heh, it''s quite overwhelming at first, even for people who''ve been programming for years. Still, unlike what was said earlier:

quote:
Original post by Some Guy
when even many professionals don''t like using it.


That really only applies to DirectX 5 and older. Nowadays, the only issues with DirectX is the lack of DirectDraw in DX 9, and the fact that the DirectX APIs are Windows only. Still, for a beginner, try SDL, says a friend of mine. I''ve never used it myself, though, so don''t hold me to his advice.


Chris ''coldacid'' Charabaruk <ccharabaruk@meldstar.com> <http://www.meldstar.com/~ccharabaruk/>
Meldstar Studios <http://www.meldstar.com/> - Creation, cubed.

This message double ROT-13 encrypted for additional security.

Share this post


Link to post
Share on other sites
LPCSTR is a "Linear Pointer to a Constant STRing", so that''s "const char *" to you. It''s shorter to type and the usage is clearer (the char pointer could be any data, not just a string).

I find all-uppercase types a bit messy to read, although you could probably improve things slightly by enabling syntax colouring for these types as though they were reserved words. Still, it''s usually quite easy to figure out what kind of parameters they are. All Windows handles start with H, and the names are pretty descriptive (HMENU, HFONT, HPEN, HDC, HMODULE, HWND, HINSTANCE). No confusion there, as long as you know what menus, fonts, pens, device contexts, modules, windows and instances are...

The Borland compiler most probably doesn''t support this, but I like the MSVC way:
#pragma comment (lib, "mylibrary.lib")
Of course, that''s not portable, but it does ensure that when you re-use code (in MSVC) you don''t have to check all the code for the necessary libraries and add those to your project link settings.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!