From: Dave Cullen on
I have an MFC dll that opens serial ports via CreateFile. Will the comport
handles be released when the calling program terminates, or do I need to
call CloseHandle before exiting?

Thanks


From: Scott McPhillips [MVP] on
"Dave Cullen" <nospam(a)mail.com> wrote in message
news:OKp0D5ntIHA.4376(a)TK2MSFTNGP06.phx.gbl...
>I have an MFC dll that opens serial ports via CreateFile. Will the comport
>handles be released when the calling program terminates, or do I need to
>call CloseHandle before exiting?


You should definitely CloseHandle before exiting. There have been cases on
some versions of Windows where leaving the port open makes it inaccessible
after the program closes.

--
Scott McPhillips [VC++ MVP]

From: Victor Bazarov on
Dave Cullen wrote:
> I have an MFC dll that opens serial ports via CreateFile. Will the comport
> handles be released when the calling program terminates, or do I need to
> call CloseHandle before exiting?

I don't know the exact answer to your first question (although I suspect
the answer is 'yes'), but here is the rule of thumb I use: always close
all files and all handles you open (and own) as soon as they are not
needed any longer.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask