Special Types in C++
Results 1 to 3 of 3

Thread: Special Types in C++

  1. #1
    Senior Member
    Join Date
    Dec 2004
    Posts
    107

    Question Special Types in C++

    Hello Everyone,

    I'm trying to learn C++ in depth. I should say I've programmed in Java for a few years now (throughout college, 5+ years hehe), so I'm not new to programming and programming concepts.

    However, I keep stumbling into problems and riddles in C++. For example, can anyone explain what are those special all-uppercase variable types, like WORD, WSAData, SOCKET, DSWORD, etc, where they come from, how are they defined (macros??).... Intuitively they make sense, but when time comes for me to use them, why should I use type SOCKET instead of int?

    If anyone can shed some light on this, I will be forever thankful.

    -ik

  2. #2
    well, the types you are explaining are part of the windows API's.
    Windows API's are functions that are written by microsoft and which a programmer can use so that it becomes easier to write programs for Windows.
    most of the time you need to include the windows.h headerfile to use these functions.

    suppose you have the windows API OpenProcess():
    syntaxis:
    Code:
    HANDLE OpenProcess(
      DWORD dwDesiredAccess,
      BOOL bInheritHandle,
      DWORD dwProcessId
    );
    as you can see here , the function returns a HANDLE.
    a HANDLE here is a handle to the process that is opened, which can be used again in another API.

    it is not a real C variable, but more of a structure which is pre-defined in the header file, which allows the programmer to define his own types of variables (sort of).

    you can check the msdn site for more info here, or if you google for Windows API you can find several tutorials like this one.

    i hope this clears things up. the variables you are using are defined before, some examples:
    HANDLE <variable>
    LUID <variable>
    TOKEN_PRIVILEGES <variable>
    PROCESSENTRY32 <name of structure>

  3. #3
    Senior Member
    Join Date
    Dec 2004
    Posts
    107
    Thanks for the reply WS. I was not aware this is just a part of a Windows API. For the sake of portability, I will try to stay away from this these special variable types whenever I can.

    It's kind of interesting how sockaddr_in is defined as SOCKADDR_IN... it doesn't seem to make life any easier, though, to be fair, all uppercase letters tell me (as a Java programmer) that it's a variable defined somewhere else.

    In any case, your reply along with White Eskimo's tutorial on preprocessors (http://www.antionline.com/showthread...hreadid=249061) sheds plenty of light on this.

    Thank you once again,

    -ik
    Alright Brain, you don\'t like me, and I don\'t like you. But let\'s just do this, and I can get back to killing you with beer.
    -- Homer S.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides