Jump to content
  • Advertisement
Sign in to follow this  
rsewar2

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

This topic is 4642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Of course! Moved the code down about two lines (past OnFileNew();) and it worked straight away - thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!