HANDLE, DWROD please help newbiew
-
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.
-
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.
DWORD is just a typedef for unsigned long:
typedef unsigned long DWORD;
HANDLE is just a typedef for void*typedef void *HANDLE;
handle is a kind of pointer to the windows objects, like bitmaps, brush, etc. http://www.priyank.in/ -
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.
Hello, Try:
#include <windows.h>
ans see the magic that can do! About those types, they are all typedefs by microsoft. All the types that have 'WORD' in their name, are somekind of an int: WORD = 2 bytes unsigned integer, DWORD = 4 bytes unsigned integer and QWORD (Quad WORD) is left as a exercise... The HANDLE object is a void* pointer to a system object that is managed by windows. The more windows programming you do, the more you see those objects. Once you learn how to read the MS conventions (try the hongarian notation) some of those names become more easy to read. For example: LPCTSTR becomes something like: Long Pointer Constant T (unicode, when defined) STRing, where T comes from the macro _T that you use to make unicode strings if you do a unicode build. I hope that things are more clear now. Good luck on your quest! I also got the blogging virus..[^] -
DWORD is just a typedef for unsigned long:
typedef unsigned long DWORD;
HANDLE is just a typedef for void*typedef void *HANDLE;
handle is a kind of pointer to the windows objects, like bitmaps, brush, etc. http://www.priyank.in/Priyank Bolia wrote: HANDLE is just a typedef for void* typedef void *HANDLE; not always: see WINNT.H