Re: Trying to Retrieve a List of Active Serial/Com Ports



In article <1182459800.336445.92790@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
<kudruu@xxxxxxxxx> wrote:

Here is the definition for HANDLE:
#ifdef STRICT
typedef void *HANDLE;
#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef
struct name##__ *name
#else
typedef PVOID HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
#endif
typedef HANDLE *PHANDLE;

So HANDLE is a void* or a PVOID, which I would -guess- is just
another name for a void* . Either way, HANDLE is probably a pointer.

(HANDLE)fd[0] = CreateFile( comPort,
GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );

And earlier you told us int fd[2], so fd[0] is an int. You are
trying to store a pointer in an int. The conversion between
pointer and int is implementation specified in C, and need not be
meaningful at all. On most systems, a pointer is wider than an int,
so even if the implementation specified that it's a bitwise copy,
you'd be losing bits out of the pointer; the converted value would
probably never be usable as a pointer again.

The moral: don't try to store a HANDLE in an int.
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
.



Relevant Pages