Click here to Skip to main content
15,910,303 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMultiple application instances-how prevent multiple file instances or file overwrite Pin
lctrncs12-Dec-06 10:41
lctrncs12-Dec-06 10:41 
AnswerRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
Mark Salsbery12-Dec-06 11:29
Mark Salsbery12-Dec-06 11:29 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
lctrncs13-Dec-06 7:48
lctrncs13-Dec-06 7:48 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
Mark Salsbery13-Dec-06 8:27
Mark Salsbery13-Dec-06 8:27 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
lctrncs14-Dec-06 10:57
lctrncs14-Dec-06 10:57 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
lctrncs14-Dec-06 11:00
lctrncs14-Dec-06 11:00 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
Mark Salsbery14-Dec-06 11:34
Mark Salsbery14-Dec-06 11:34 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
lctrncs14-Dec-06 13:06
lctrncs14-Dec-06 13:06 
THANK YOU!

I wonder if the problem stems from the flat file database I have hanging off the doc/view.

CODE FOR CreateFile call etc.


From StudyPartnerDoc.cpp file
/////////////////////////////////////////////////////////////////////////////
/////////////////// OnOpenDocument //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

BOOL CStudyPartnerDoc::OnOpenDocument(LPCTSTR lpszPathName)

{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;

//Get a pointer to the view
POSITION pos = GetFirstViewPosition();
CStudyPartnerView* pView = dynamic_cast<cstudypartnerview*>( GetNextView(pos) );

//Tell the view that its got a new data set
if (pView)
pView->NewDataSet();


/////////////////////////////////////////////////////////////
// Attempts to prevent file overwrite when multiple copies of app open the same file

///*
//CreateFile and dwsharedmode to prevent make file read only when one instance is using it

//opens the file - but "access denied" passed through to program on save after First Chance Exception

m_hFileLock = CreateFile(
lpszPathName,
GENERIC_WRITE|GENERIC_READ, // access (read-write) mode
//0, //attempt to use "query device attributes without accessing the device."
0,// share mode
NULL,// pointer to security descriptor
OPEN_EXISTING,// how to create
FILE_ATTRIBUTE_NORMAL,// file attributes
NULL); // handle to file with attributes to copy

//FILE ATTRIBUTES TRIALS
//FILE_ATTRIBUTE_NORMAL - crash on save
//FILE_ATTRIBUTE_TEMPORARY - access denied
//FILE_FLAG_WRITE_THROUGH - First Chance Exception on save
//FILE_ATTRIBUTE_HIDDEN



DestroyDialog(); //Ensure that the Study Dialog is closed

return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
/////////////////// OnSaveDocument //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

BOOL CStudyPartnerDoc::OnSaveDocument(LPCTSTR lpszPathName)

{
if (!CDocument::OnSaveDocument(lpszPathName))

return FALSE;

////////////////////////////////////////////////////
// Close the file handle opened for CreateFile and dwShareMode

CloseHandle( m_hFileLock );

return TRUE;
}

////////////////////////////////////////////////////
////////////////////////////////////////////////////
////////////////////////////////////////////////////
////////////////////////////////////////////////////


//From doc.h file

class CStudyPartnerDoc : public CRichEditDoc
{
//protected: etc...

public:
// MFC Overrides
BOOL OnOpenDocument(LPCTSTR lpszPathName);
BOOL OnSaveDocument(LPCTSTR lpszPathName);
HANDLE m_hFileLock;
//etc.
}




Thanks again!

Mark Salsbery wrote:
That always reminds me of "Cup-o-Joe", an evangelist on the worldwide live broadcast of the
rollout/introduction of Windows 95 (I think).


Cup-o-Joe? LoL. Never heard of him. Microsoft and the other two companies tied up in the project kept us pretty busy with classes (and not quite true statements) etc. right up until the second they turned on the phones. I will have to check this out a bit.






"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
Mark Salsbery14-Dec-06 13:36
Mark Salsbery14-Dec-06 13:36 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
lctrncs14-Dec-06 14:18
lctrncs14-Dec-06 14:18 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
Mark Salsbery14-Dec-06 16:12
Mark Salsbery14-Dec-06 16:12 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
lctrncs15-Dec-06 8:05
lctrncs15-Dec-06 8:05 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
Mark Salsbery15-Dec-06 8:50
Mark Salsbery15-Dec-06 8:50 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
lctrncs18-Dec-06 6:01
lctrncs18-Dec-06 6:01 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
Mark Salsbery18-Dec-06 7:39
Mark Salsbery18-Dec-06 7:39 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
lctrncs18-Dec-06 11:51
lctrncs18-Dec-06 11:51 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
Mark Salsbery15-Dec-06 8:59
Mark Salsbery15-Dec-06 8:59 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
Mark Salsbery14-Dec-06 16:18
Mark Salsbery14-Dec-06 16:18 
AnswerRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
Stephen Hewitt12-Dec-06 12:03
Stephen Hewitt12-Dec-06 12:03 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
lctrncs13-Dec-06 6:09
lctrncs13-Dec-06 6:09 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
lctrncs13-Dec-06 7:45
lctrncs13-Dec-06 7:45 
GeneralRe: Multiple application instances-how prevent multiple file instances or file overwrite Pin
Stephen Hewitt13-Dec-06 10:15
Stephen Hewitt13-Dec-06 10:15 
QuestionTab Control and GroupBox...Anybody? Pin
damir_tk12-Dec-06 9:29
damir_tk12-Dec-06 9:29 
AnswerRe: Tab Control and GroupBox...Anybody? Pin
led mike12-Dec-06 9:37
led mike12-Dec-06 9:37 
GeneralRe: Tab Control and GroupBox...Anybody? Pin
damir_tk12-Dec-06 11:29
damir_tk12-Dec-06 11:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.