Oh, I see. Here's how to fix that on Windows:
1. Consider using FindFirstFile(fileName, &findData) and FindClose(), then examine findData.dwFileAttributes to get the file attributes. This gets attributes without opening the file or using a file handle, it can't encounter a sharing violation on open/locked files. CreateFile is also a notoriously slow API because of the amount of work it has to do, so using FindFirstFile might even yield a performance boost.
2. If for some reason #1 is undesirable, another option could be to try using FILE_READ_ATTRIBUTES for the dwDesiredAccess parameter in a call to CreateFile (instead of using the broader GENERIC_READ). Using FILE_WRITE_ATTRIBUTES certainly allows setting attributes on a readonly file, because the readonly attribute applies to content, not to metadata. I don't know for sure if this approach will work (#1 definitely works), but it might be symmetrical, it might allow opening the metadata portion of a locked file.
CreateFile(fileName, FILE_READ_ATTRIBUTES, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);