File locking

i am working on a device runnin on linux....i have configured the samba server in the device such that my windows PC can access a shared folder in the device. Also in the device i am runnin some programs which access the files in this shared folder. What i want to know is whether there is any way i can lock the files in the shared folder when these programs access them, such that my windows PC cannot delete the files or modify them while it is bein used. I read somewher tht the only way is to change the file permissions, but the problem is tht the folder is shared with full rights -777 , and it has to be so for what i am working on...so even if i change the file permission of the particular file it is of no use...
Is there any way to get around this problem..the programs i am runnin are written in C..it would be helpful if some solution can be given which can be implemented in C itself because i can just fuse it into programs then....

refer the flock manual.
flock is a system call to lock files.