Sign in to follow this  
rsewar2

MFC: How do I access my document class from my cwinapp class?

Recommended Posts

Thought I was on the right track here (from the initialisation of my cwinapp derived class): CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CChatDoc), RUNTIME_CLASS(CMainFrame), // main SDI frame window RUNTIME_CLASS(CChatView)); AddDocTemplate(pDocTemplate); POSITION p = pDocTemplate->GetFirstDocPosition(); gamedoc = (CChatDoc*)pDocTemplate->GetNextDoc(p); The two final lines are supposed to get a pointer to the first document as a cdocument and cast it to my own document class (Cchatdoc) and then give this to gamedoc, which is a pointer to my document class. However whenever I try to access anything through the pointer I'm getting access violations, which act as though I'm using a null pointer, which suggests that I'm not getting my document class properly. Surely this must be a fairly standard thing to do. any ideas? thanks!

Share this post


Link to post
Share on other sites
Its been a while since I used MFC but I dont' think that, at that point, any documents have been created yet. It memory serves, that happens a little later. Like during command line reading (of all places) - New is the default action or something.

Move your get document code down a ways and I bet it works.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this