Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Lock file with win32 api?

Posted on 2005-05-07
2
Medium Priority
?
1,078 Views
Last Modified: 2013-11-13
Hi

I want to lock a file using the win32 api so that no one else can read/write to it until I have released the lock.

Note, I'm only looking for API functions.

-Mike
0
Comment
Question by:nerdmike
2 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 375 total points
ID: 13951897
Just have to use CreateFile() with proper attributes:

HANDLE hFile = CreateFile("somefile", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

The 3rd argument (0) will avod to share it for read or write.
0
 

Author Comment

by:nerdmike
ID: 13952970
Is there a way to make it block until the file is available?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Progress
Starting up a Project

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question