CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2005
    Posts
    1

    HANDLE, DWORD, etc please help newbie

    Hello gurus,

    Please be patient with a newbie.

    Everywhere I look on the web I see code with these strange vriable types written in capitals like "DWORD" or "HANDLE". Pleople just declare them without having a class of type dword or handle. When I try to use such code, ofcourse the compiler says:

    'DWORD' : undeclared identifier

    I am trying to use a function called CreateFile which has the attributes:

    HANDLE CreateFile(
    LPCTSTR lpFileName,
    DWORD dwDesiredAccess,
    DWORD dwShareMode,
    LPSECURITY_ATTRIBUTES lpSecurityAttributes,
    DWORD dwCreationDispostion,
    DWORD dwFlagsAndAttributes,
    HANDLE hTemplateFile
    );

    It return type is "HANDLE". What the? Theres no such thing. Is it an int?

    MSDN says that "dwDesiredAcess" has to be either 0, GENERIC_READ or GENERIC_WRITE. Is GENERIC_READ a string or what?

    When I try to use the the function. ie:

    hComm = CreateFile(portname,
    GENERIC_READ | GENERIC_WRITE,
    0,
    0,
    OPEN_EXISTING,
    0,
    0);

    The compiler says:

    'GENERIC_READ' : undeclared identifier.

    Look, this is a basic question that has porbably been answered elsewhere? But what am I supposed to search for? "variable types written in CAPITALS"?

    Pleas help.

  2. #2
    Join Date
    Sep 2004
    Location
    A Planet Called Earth... :-)
    Posts
    835

    Cool Re: HANDLE, DWORD, etc please help newbie

    Quote Originally Posted by majster
    Everywhere I look on the web I see code with these strange vriable types written in capitals like "DWORD" or "HANDLE". Pleople just declare them without having a class of type dword or handle. When I try to use such code, ofcourse the compiler says:

    'DWORD' : undeclared identifier

    Well, the story goes like this....

    Data types.

    Types like int, float, bool, ect..., IF you are using C++ are the C++ library provided datatypes, IF you are using C then.... blah blah blah

    The above types like DWORD, HANDLE, LPSTR, LPCSTR, ect... are all windows datatypes.
    They are defined in WinDef.h.
    In your project you usually include another header - windows.h. In windows.h some header files are included, including WinDef.h.
    Since ur complier is complaining, it is because it is not finding the definition of DWORD, the header is not included.


    As for an HANDLE, "windows objects" can be refered to by an HANDLE.
    For eg: if the operating system creates an window, it returns an HANDLE which you can to refer to the window for later use, it never returns the object itself (or reference).
    Indirect manipulation of the object!

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: HANDLE, DWORD, etc please help newbie

    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    May 2005
    Posts
    121

    Re: HANDLE, DWORD, etc please help newbie

    Just include windows.h and everything will be fine.

  5. #5
    Join Date
    Nov 2004
    Posts
    155

    Re: HANDLE, DWORD, etc please help newbie

    Hi Newbie,

    HANDLE is a 32-bit integer that is used as a handle. There are number of handle types, but they are all the same size as HANDLE. All handle type begin with an H.
    HWND is a 32 bit integer used as a window handle.

    BYTE is an 8 bit unsigned character.
    WORD is a 16 bit unsigned short integer.
    DWORD is an unsigned long integer.
    UINT is a 32 bit unsigned integer
    LONG is another name for long.
    BOOL is an integer type.
    LPSTR is a pointer to a string.
    LPCTSTR is a const pointer to a string.
    Life Is Nothing But One's Belief
    Don't Forget That All People Are Waiting For Your Reply
    If you're pleased the answer, at least you should say "Thanks"

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured