Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with 'CreateFile' i Win32.api

1 view
Skip to first unread message

Henrik Nilsson

unread,
Aug 16, 1999, 3:00:00 AM8/16/99
to
I hope that this is the right NG for this question, otherwise please inform
me.

My problem is that I want to create a handle til a com-port, in ordre to
query the status of the particular port, without taking control over the
port.

I order to query the port-status, I have to obtain a handle to the port
with the Cratefile function. According to the dokumentation on MSDN, the
code should be this:

retval = CreateFile("COM2", 0, 0, Null, OPEN_EXISTING, 0, Null)

This line results in error 94, 'Invalid use of Null'

What am I doing wrong?

Please help.

henrik_...@norddata.dk


Icabod

unread,
Aug 16, 1999, 3:00:00 AM8/16/99
to
In article <01bee7e8$69b2b160$fbaba3c1@ndtcp164>,

"Henrik Nilsson" <henrik_...@norddata.dk> wrote:
> I hope that this is the right NG for this question, otherwise please
> inform me.

don't think this is quite the right newsgroup (really you want an api
group, methinks -- not sure of any offhand). unless of course you're
writing this for a driver. either way...


> I order to query the port-status, I have to obtain a handle to the
> port with the Cratefile function. According to the dokumentation on
> MSDN, the code should be this:
> retval = CreateFile("COM2", 0, 0, Null, OPEN_EXISTING, 0, Null)
> This line results in error 94, 'Invalid use of Null'

hmm. off the top of my head... is this a direct cut-n-paste from your
code??? if so, it's prolly the capitalisation of "Null"... change the
code so it reads
retval = CreateFile("COM2", 0, 0, NULL, OPEN_EXISTING, 0, NULL);
^^^^ ^^^^
of course, if this is already the case, and it wasn't a cut-n-paste,
then i have no idea what's wrong.

g'luck,
'bod


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Felix Kasza [MVP]

unread,
Aug 16, 1999, 3:00:00 AM8/16/99
to
Henrik,

> retval = CreateFile("COM2", 0, 0, Null, OPEN_EXISTING, 0, Null)

Are you using VB? If so, "Null" probably means something other than "0".
When a Win32 API expects a pointer and you want to pass what C calls a
NULL pointer, you need a numeric zero.

--

Cheers,

Felix.

If you post a reply, kindly refrain from emailing it, too.
Note to spammers: fel...@mvps.org is my real email address.
No anti-spam address here. Just one comment: IN YOUR FACE!

Scott McPhillips

unread,
Aug 16, 1999, 3:00:00 AM8/16/99
to
Henrik Nilsson wrote:
>
> I hope that this is the right NG for this question, otherwise please inform
> me.
>
> My problem is that I want to create a handle til a com-port, in ordre to
> query the status of the particular port, without taking control over the
> port.
>
> I order to query the port-status, I have to obtain a handle to the port
> with the Cratefile function. According to the dokumentation on MSDN, the
> code should be this:
>
> retval = CreateFile("COM2", 0, 0, Null, OPEN_EXISTING, 0, Null)
>
> This line results in error 94, 'Invalid use of Null'
>
> What am I doing wrong?
>
> Please help.
>
> henrik_...@norddata.dk

You need
CreateFile("COM2", GENERIC_READ | GENERIC_WRITE, NULL, NULL, OPEN_EXISTING, 0,
NULL)

There is no way to query the port status except to try and open it for I/O.

Icabod

unread,
Aug 17, 1999, 3:00:00 AM8/17/99
to

> > retval = CreateFile("COM2", 0, 0, Null, OPEN_EXISTING, 0, Null)

> You need


> CreateFile("COM2", GENERIC_READ | GENERIC_WRITE, NULL, NULL,
> OPEN_EXISTING, 0, NULL)

> There is no way to query the port status except to try and open it
> for I/O.


not according to the api info (unless there's something in
MSDN/Knowledgebase that says otherwise). in the api info, it says of
setting the second parameter to '0'...
"Specifies device query access to the object. An application can
query device attributes without accessing the device."

so, according to this, querying is possible without read/write access
-- but then i haven't check the knowledgebase, so...

cheer,

0 new messages