Using open and then LockFile for a file

Hi all,

I’m porting a Unix application to Windows. Im using M$ VC++ compiler.
My problem is that on Unix the file locking mechanism is done using
the fcntl() function that doesn’t exist on Windows. I know that on
Windows I can do this using CreateFile() to get the HANDLE to a file
and then this handle can be used in LockFile() for locking the file.

But, I would like to open the file using open() function, which
returns an “int” and then for using the LockFile() I need a HANDLE to
the file, so my question is: is there a function that can transform
the “int” returned by open() into a HANDLE that then can be used in
LockFile() ?

Thanks in advance,
vc

vcotirlea@hotmail.com (vc) writes:

I’m porting a Unix application to Windows. Im using M$ VC++
compiler. My problem is that on Unix the file locking mechanism is
done using the fcntl() function that doesn’t exist on Windows. I
know that on Windows I can do this using CreateFile() to get the
HANDLE to a file and then this handle can be used in LockFile() for
locking the file.

What about File#flock?

···


matt

On 12 Feb 2003 01:36:03 -0800, vcotirlea@hotmail.com (vc) wrote in
comp.lang.c++:

Hi all,

I’m porting a Unix application to Windows. Im using M$ VC++ compiler.
My problem is that on Unix the file locking mechanism is done using
the fcntl() function that doesn’t exist on Windows. I know that on
Windows I can do this using CreateFile() to get the HANDLE to a file
and then this handle can be used in LockFile() for locking the file.

But, I would like to open the file using open() function, which
returns an “int” and then for using the LockFile() I need a HANDLE to
the file, so my question is: is there a function that can transform
the “int” returned by open() into a HANDLE that then can be used in
LockFile() ?

Thanks in advance,
vc

Please don’t post non-standard stuff like this to comp.lang.c++ in the
future. If it is not part of the C++ language, as defined by the ISO
standard, it is off-topic here.

···


Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c comp.lang.c Frequently Asked Questions
comp.lang.c++ C++ FAQ
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

Please don’t post non-standard stuff like this to comp.lang.c++ in the
future. If it is not part of the C++ language, as defined by the ISO
standard, it is off-topic here.

If it’s off-topic on comp.lang.c++, it’s
WAY off-topic on comp.lang.ruby… :wink:

Cheers,
Hal

···

----- Original Message -----
From: “Jack Klein” jackklein@spamcop.net
Newsgroups:
comp.os.ms-windows.programmer.win32,comp.lang.ruby,comp.lang.c++,microsoft.p
ublic.dotnet.languages.vc
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, February 12, 2003 7:46 PM
Subject: Re: Using open and then LockFile for a file