-
May 13th, 2005, 02:56 AM
#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.
-
May 13th, 2005, 03:21 AM
#2
Re: HANDLE, DWORD, etc please help newbie
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!
-
May 13th, 2005, 03:51 AM
#3
Re: HANDLE, DWORD, etc please help newbie
-
May 13th, 2005, 03:59 AM
#4
Re: HANDLE, DWORD, etc please help newbie
Just include windows.h and everything will be fine.
-
May 13th, 2005, 04:00 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|