CImage::LoadImage() - preventing conflicts
Posted on 2006-05-25
I have an app that resides on two client computers (PC's), each having a mapped drive to a location where each app saves images to. They both talk to the same access database and place images into the same folder.
Generally it's working, except when both client apps end up trying to view the same image file at the same time.
I use this to load an image into an HBITMAP:
m_hbmImage = (HBITMAP)::LoadImage(NULL, sPath,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION | LR_LOADFROMFILE);
How can I "wrap that" (or modify the paramaters some way I'm not aware of) so that if one client hasn't completed it's call to LoadImage on sPath, the other app won't try to until it's done?
I have a few ideas, not sure what's best or most appropriate.
One idea is to have a field "locked" in the database, and have each app lock/unlock before and after it loads, and check for a locked image first. That seems resource intensive, couldn't windows somehow tell if if a file is being accessed?
I also thought perhaps a Mutex or something, but that's for threads, and this is merely networked apps.
Can I somehow check the windows file attributes to see if it's being accessed?