   Few Quick Easy Questions
  Hello Everybody, I have an assortment of easy questions that I am not clear on (some of them elude me completely). So here I go in no particular order:First here is my "profile":C++(DevC),all these questions are from a windows app....I think that should cover it.Questions:1. What is the difference between these two?-#include <blah>-#include "blah" //does this one look in the Root directory of my project?2.This is a nifty macro for getting a keyboard key:#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)   I understand the "Bit Twiddling", but the 0x8000 throws me off for these reasons:-is it in Hex? (im almost positive but i need that last bit of confidence :) )-Why do I have to put 0x before the Hex and what does it mean/do?-there is 8000 which means 16 bits correct? How am I supposed to know how many bits there are in different functions so I can "twiddle" with them. (funny word)3.what does the (int) before LOWORD do in this code?  does it create a variable or just let the compiler know that its going to need room for an int? How do I know when I need to put (type) before something. I use it later (HBRUSH) and I dont know why. ( and that bothers me )case WM_MOUSEMOVE:{    MOUSEX = (int)LOWORD(lparam); MOUSEY = (int)HIWORD(lparam);  return 0; }break; 4.Should HINSTANCE in WinMain() be Global?  Sometimes I get errors and I can fix them by making it Global; instinctively I feel I am doing something wrong.5.(last one :)) I return this from WinMain :return(msg.wParam);-Why?-(assumption)error handling? I know this is a jumble of random ?'s but they seemed simple but elusive for me.  I Tried to format this post so it would be easy to answer.And as always, any and all help is greatly appreciated.   
  1) First "blah" looks in the current directory before trying the standard include path. <blah> does not.2) It's in hexadecimal. That's what 0x means. The variable is at least 16 bit wide, yes, but how much precisely depends on the definition of GetAsyncKeyState and possibly the compiler/computer you are using.3) It's a C-style cast. It converts the value to an int.4) No. Pass it as a parameter to whichever function needs it instead.5) The return value from main() (or here WinMain()) is passed back to the operating system or process that executed the program, and can be checked for in scripts (or .BAT files). For example if you were to do, in another program, int blah = system("MyProgram.exe");, the return value would be placed in blah.   ;Quote:Original post by CG_KNOWLEDGEHello Everybody, I have an assortment of easy questions that I am not clear on (some of them elude me completely). So here I go in no particular order:First here is my "profile":C++(DevC),all these questions are from a windows app....I think that should cover it.Questions:1. What is the difference between these two?-#include <blah>-#include "blah" //does this one look in the Root directory of my project?<> = GENERAL"" = PROJECTDIR2.This is a nifty macro for getting a keyboard key:*** Source Snippet Removed ***I understand the "Bit Twiddling", but the 0x8000 throws me off for these reasons:-is it in Hex? (im almost positive but i need that last bit of confidence :) )YES-Why do I have to put 0x before the Hex and what does it mean/do?MEANS HEX, MIGHT BE EASIER FOR SEVERAL COMPUTER VALUES FOR NOTATION-there is 8000 which means 16 bits correct? How am I supposed to know how many bits there are in different functions so I can "twiddle" with them. (funny word)CHECKS FOR A SPECIFIC KEY IN THE KEYBOARDHANDLER. BY LOGICAL AND'ING YOU CAN FIND THE STATUS. IF THE HIGHEST BIT IS FLAGGED THAT MEANS A PRESSED ELSE AN UNPRESSED KEY. RETURNS A SHORT WHICH IS 16-BIT.3.what does the (int) before LOWORD do in this code?  does it create a variable or just let the compiler know that its going to need room for an int? How do I know when I need to put (type) before something. I use it later (HBRUSH) and I dont know why. ( and that bothers me )TYPECAST'ING, VARIABLES MUST OF THE SAME TYPE. IF YOU KNOW THE CONTENTS OF THE VARIABLE BUT IT ISN'T THE TYPE YOU CAN MAKE IT BY TYPECAST'ING.*** Source Snippet Removed ***4.Should HINSTANCE in WinMain() be Global?  Sometimes I get errors and I can fix them by making it Global; instinctively I feel I am doing something wrong.YOU MEAN THE ARGUMENT IN THE FUNCTION? THIS IS SENT BY WINDOWS.5.(last one :)) I return this from WinMain :return(msg.wParam);-Why?-(assumption)error handling? YES. RETURNS THE MESSAGES LAST SENT. IF SOMETHING WENT WRONG YOU WILL PROBABLY GET A NON-ZERO VALUE.I know this is a jumble of random ?'s but they seemed simple but elusive for me.  I Tried to format this post so it would be easy to answer.And as always, any and all help is greatly appreciated.get a look here:http://www.falloutsoftware.com/tutorials/win/win1.htm   ;  2."bit-twiddling" operators such as | and & work with individual bits, so it makes sense to use binary. But binary numbers like 100001001110100 have so many digits that they're difficult to read, write or remember. 0x8000 is hexadecimal for the binary number 1000000000000000. The 0x in front just indicates that the number is hexadecimal and not normal decimal number. The reason for using hex instead of decimal is because hex is much easier to convert to and from binary in your head.   ;Quote:Original post by CG_KNOWLEDGE1. What is the difference between these two?-#include <blah>-#include "blah" //does this one look in the Root directory of my project?The first notation is used for header files residing in one of the include directories set in your IDE. I'm not familiar with DevC, but it probably contains some subdirectories of the IDE's install directory. You can also add your own folders.The latter is a relative path to a file, say a header file in the same or lower directory than your project. Although, as long as you get the path right, the file could be anywhere on your system.Quote:2.This is a nifty macro for getting a keyboard key:I understand the "Bit Twiddling", but the 0x8000 throws me off for these reasons:-is it in Hex? (im almost positive but i need that last bit of confidence :) )Yes.Quote:-Why do I have to put 0x before the Hex and what does it mean/do?This is to indicate it's a hexadecimal number. If you'd write 8000 without the 0x, it would mean 8000 as a decimal number.Quote:-there is 8000 which means 16 bits correct? How am I supposed to know how many bits there are in different functions so I can "twiddle" with them. (funny word)The number of bits depends on the size of a variable, no on how may of them are set. Use sizeof() to find out the size of variable type.Quote:3.what does the (int) before LOWORD do in this code?  does it create a variable or just let the compiler know that its going to need room for an int? How do I know when I need to put (type) before something. I use it later (HBRUSH) and I dont know why. ( and that bothers me )It will cast it to an int. In this case, your compiler will probably throw a warning if you don't. Apparently, MOUSEX is an int.Quote:4.Should HINSTANCE in WinMain() be Global?  Sometimes I get errors and I can fix them by making it Global; instinctively I feel I am doing something wrong.I don't see what you mean. HINSTANCE is a type, not a variable you declared.Quote:5.(last one :)) I return this from WinMain :return(msg.wParam);-Why?-(assumption)error handling? This is how Windows works. An application will return a integer indicating how the program finished (were there any errors or not?). You could just return 0, but this is a better way of doing it. Notice the (int) again, the compiler expects an integer as return value. :)Quote:I know this is a jumble of random ?'s but they seemed simple but elusive for me.  I Tried to format this post so it would be easy to answer.And as always, any and all help is greatly appreciated.I'd say follow a couple tutorial on (Windows) C++ programming, or even better, but a book.I typed this up all pretty quickly, I hope I have made things a little clearer. :)   ;  Thanks Everyone for the response. I want to get one more thing clear however.About my 3rd ?, the one about (int).I've read an entire Cpp book and didn't run into it.(makes sense I guess considering it was from C?)1.How does it work exactly?2.Performance-wise is there anything i should be worried about when using it?and just to solidify my understanding of it, 3.Is this a good situation to use it in?://///////////////////////////////(GetTickCount() returns a DWORD)int a;a = (int)GetTickCount();/////////////////////////////////4. How would I use it with Strings/char[?];Thankx for all the help, plus(Ratings)- everyone was comprehensive;  Shouts out to the Mo-town! One of my buddies in college was from Modesto. Quote:Original post by CG_KNOWLEDGEAbout my 3rd ?, the one about (int).I've read an entire Cpp book and didn't run into it.(makes sense I guess considering it was from C?)1.How does it work exactly?2.Performance-wise is there anything i should be worried about when using it?and just to solidify my understanding of it, 3.Is this a good situation to use it in?://///////////////////////////////(GetTickCount() returns a DWORD)int a;a = (int)GetTickCount();/////////////////////////////////4. How would I use it with Strings/char[?];A typecast tells the compiler to treat the value as a different type than what it was originally declared to be. The cast doesn't change the original variable or the receiving variable, it really just a syntax only converter. Looking closer at the example that you gaveMOUSEX = (int)LOWORD(lparam);LOWORD is a preprocessor macro that look like this#define LOWORD(l) (((WORD) (l)) & 0xFFFF)It uses a bit mask to change any of the bits above 0xFFFF to zero while preserving the values of the first 16 bits. Then it casts those remaining bits as a WORD (aka a short). This function would be more appearant if the mask had used a complete 32 bits, eg. 0x0000FFFF. You can review what the bitwise AND does to get a feel for how that works. The outer cast, (int), tells the compiler to treat the value masked by the macro as an integer so that it can be stored in MOUSEX. Presumeably MOUSEX is an int variable. Variable names aren't usually all caps as it makes them look like typedefs or macros, whose names usually are always in all caps (macros at least). Typecasting in C++ is different than in C, which might explain why you didn't find anything about it in your C++ book. As far as effecting performance goes, a typecast is a part of syntax. It's effects are produced at compile time not run time. Should the result from GetTickCount be cast as an int? I think not. The result from GetTickCount will never be negative so I don't see the purpose to casting it to a signed integer. As far as casting strings goes, there are times were you might want to cast a const string to a non const string so that you can manipulate the string - more likely the opposite - cast a non const string as a const to prevent the compiler from complaining when you pass a non const string as an argument to a function that wants a const string. In other situations, pointers to blocks of raw memory are often cast as pointers to char so that the data can be examined byte by byte. In regard to your original question number 4, you can use GetModuleHandle(NULL) to supply the HINSTANCE value for the current running process. A HINSTANCE and an HMODULE are basically the same thing. If you examine the typedefs for them you'll find they are both pointers to void (ie. void *). If you examine the value of the HINSTANCE parameter from WinMain and compare it to the result from GetModuleHandle(NULL), you find they are both the same and will very likely find their value to be 0x00400000. That is the address at which the program file itself is mapped into the address space of the process. HINSTANCE was a Win 3.11 term that has carried over into 32 bit windows. Microsoft introduced HMODULE with 32 bit Windows, but HINSTANCE has deep roots and still persists.And in regard to hexadecimal numbers, they are used because they are compact and because they can easily be related back to the actual bits that make up the underlying number. In a hexidecimal number, each digit represents 4 bits (aka "nibble") and two digits 8 bits or a byte.  0x01 -   1 -   0000-0001 0x02 -   2 -   0000-0010 0x04 -   4 -   0000-0100 0x08 -   8 -   0000-1000 0x0A -  10 -   0000-1010 0x10 -  16 -   0001-0000 0x20 -  32 -   0010-0000 0x40 -  64 -   0100-0000 0x64 - 100 -   0110-0100 0x80 - 128 -   1000-0000 0x81 - 129 -   1000-0001 0x82 - 130 -   1000-0010 0x83 - 131 -   1000-0011 0x84 - 132 -   1000-0100... 0xFF - 255 -   1111-11110x100 - 256 - 1-0000-0000Notice how the decimal numbers expand into the next "place" at different points in the procession? That's because 10 isn't a power of two and 16 is. Anyway...   