Public Group

# Novice Programer - Need help with Windows code

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

## Recommended Posts

Hey everyone, Im new here and I want to get into game programing. I know C/C++ pretty well and I've been reading up on getting into game development. I guess that Tetris is the 1st program I should try but im confused on a few things. I dont understand the windows coding at all. Certain things like:
HINSTANCE hInst;		        // current instance
TCHAR szTitle[MAX_LOADSTRING];		//The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];	// the main window class name

I dont know where this comes from, and how its used. (The above code comes from a win32 application off Visual C++ EE. There is more but i didnt want to include 6 pages of code.) If someone could point me in the right direction with understanding the windows code it would be much apprecaited. Any other advice you wanna throw in is always welcome:)

##### Share on other sites
Since you are just starting out, you might want to look into Borland C++ Builder. It is a visual compiler for C++ from the same company that makes Delphi, and it can save you a huge amount of code, especially on small projects.

Best part is that you can focus on game logic rather than buttons and windows.

It works with all the big libraries too (DirectX, OpenGL)

I think there is a free trial on Borland.com, you can get student versions on eBay for about \$50, or just look for it.

##### Share on other sites
You probably should get yourself a copy of Programming Windows by Charles Petzold. Followed by Advanced Windows by Jeff Richter. Newer editions of this book have been retitled "Programming Applications for Microsoft Windows." There are sufficient differences between editions - and the older edition (in the link) is cheap enough - that it might even be worth getting a copy of both editions.

Ok. So let's see.

HINSTANCE hInst; // current instance

This variable holds the address where the executable file (exe) was loaded (mapped actually) into the address space of the current process. The HINSTANCE type is quite old, dating to the earliest days of in Windows. In newer code you'll find reference to the HMODULE type, which is the same thing as HINSTANCE, except broadened to include dlls. Underneath the hood, the HINSTANCE is used to references various resources stored at offsets in the executable file (or dll as the case may be). The previous hinstance argument of WinMain is useless on 32 bit windows. It's a left over from the days of 16 bit windows.

TCHAR szTitle[MAX_LOADSTRING]; //The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

TCHAR is defined as char or wchar_t depending on whether UNICODE is defined. Using this allows you to write code that will work successfully either way. There are typically two forms of Win32 API functions that accept strings, the A form - for ANSI - and the W form - for wide char. So when you use a function in your code like GetModuleFileName, the preprocessor selects the A or W form of the function name depending on whether or not UNICODE is defined.

These might also help.

Unraveling Strings in Visual C++
Cheat Sheet: Unicode-enabling Microsoft C/C++ Source Code

And here are a couple of other links that might be helpful to you.

theForger's Win32 API Tutorial
Win32 Programming
Windows API Tutorial

##### Share on other sites
Thanks for the quick response guys. It was just what I was looking for.

##### Share on other sites
While your question is already more than fully answered [grin] I would just like to add that all those 'confusing' types are really nothing more than simple typedefs. If you have Visual C++ (2005) you can even open the 'code definition window' which will show you exactly where and how something is defined. All you need to do is put the cursor somewhere in the word 'HINSTANCE' and you'll see how it's defined. HINSTANCE isn't a really good example as it's made from another macro which doesn't lead to much clarity, but it'll work for all 'strange' types.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634046
• Total Posts
3015219
×