Re: Access Denied problem with CreateFile
From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 07/23/04
- Next message: Joseph M. Newcomer: "Re: Peeking at Window Messages"
- Previous message: Joseph M. Newcomer: "Re: Crash when reading a CString out of a CArchive"
- In reply to: vinay: "Access Denied problem with CreateFile"
- Next in thread: Kurt Grittner: "Re: Access Denied problem with CreateFile"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 23 Jul 2004 17:11:59 -0400
Well, it means access is denied. You have already opened the handle somewhere, and a
subsequent attempt to open COM1 will fail with an access denied error.
Setting the handle to NULL doesn't close the handle, and it sounds like you are not
closing the handle.
I believe serial ports always ignore dwShareMode, and it is impossible to open them other
than exclusive anyway.
I don't believe the handle is closed. Note that if you duplicate the handle, pass it down
to a process as inherited, etc., then the COM1 port will not be available until ALL
handles are closed.
Put a breakpoint at your CloseHandle, and make sure that (a) you are calling it and (b) it
succeeds. Most people don't notice or care that CloseHandle is a boolean function. But if
you ARE callilng it, and are not using duplication or inheritance, make sure that the
CloseHandle is really succeeding. For example, write
VERIFY(CloseHandle(h));
and examine, in a watch-window, the value
@ERR,hr
which will give you the last error code for the current thread, and its textual
explanation.
joe
On 23 Jul 2004 07:05:39 -0700, vinaymathew80@yahoo.com (vinay) wrote:
>Hallo,
>I have a problem when using the CreateFile function to access the COM
>port.In my application i create a dialog box.When the initdialog
>function is called i initialise the port and then do the other things
>that i have to with the port. It works fine. The funny part is that
>once i close this dialog box and open it again without closing the
>entire application the CreatFile function returns ACCESS_DENIED
>error.But if i close the entire application and then restart it
>everythin is fine.I have a class that accesses the serial port.This
>class also uses threads to access the port.But when the dialog box is
>closed the thread is killed and the handle to the COM port is also set
>back to NULL.However the CreateFile still returns ACCESS_DENIED
>error.I read in the MSDN manuals that
>
>"Set of bit flags that specifies how the object can be shared. If
>dwShareMode is 0, the object cannot be shared. Subsequent open
>operations on the object will fail, until the handle is closed"
>
>I have used dwShareMode as 0 since its a COM port.However subsequent
>open operations return ACCESS_DENIED inspite of the fact that the
>handle to the com port is closed.
>Has anyone had a problem like this before ......its really taking me a
>lot of time and i cant figure it out at all.
>thanx in advance and regards
>vinay
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Next message: Joseph M. Newcomer: "Re: Peeking at Window Messages"
- Previous message: Joseph M. Newcomer: "Re: Crash when reading a CString out of a CArchive"
- In reply to: vinay: "Access Denied problem with CreateFile"
- Next in thread: Kurt Grittner: "Re: Access Denied problem with CreateFile"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|