I'm writing a program using C++ under Windows that needs to synchronize write ac开发者_StackOverflowcess to a file via a local network. I was thinking to use the following approach:
//Create or open it using 0 for sharing mode
HANDLE hFile = CreateFile(L"\\\\server\\share\\path\\file", GENERIC_READ | GENERIC_WRITE, 0, , OPEN_ALWAYS, , ,);
if(hFile == INVALID_HANDLE_VALUE && ::GetLastError() == ERROR_SHARING_VIOLATION)
{
//Try again later
}
Can someone confirm that it's a workable solution?
精彩评论