• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1044
  • Last Modified:

OpenDocumentFile(NULL) keeps crashing!

Hi,

I just want to open a new instance of my document class! But everytime I try OpenDocumentFile(NULL);, I get a big crash because that function is trying to parse the input of the function, accessing element [0] when there is none!

Where should I call OpenDocumentFile(NULL) from to create a new instance of the document? Right now I am calling it from an instance of a CMDIChildWnd window. This window has a list ctrl in it, when I double click an item, I am calling OpenDocumentFile().

Is that wrong? What should I do?

Also, is it possible to pass some initialization parameters to the document class? Otherwise I will have to have the document class searching around for its data!


Thanks!
0
BazookaJoeZone
Asked:
BazookaJoeZone
  • 3
  • 3
1 Solution
 
Jaime OlivaresSoftware ArchitectCommented:
Try with:
theApp.OnFileNew();
0
 
BazookaJoeZoneAuthor Commented:
That function is protected, I added a public override to it but it is just an empty function body that does nothing when called.
0
 
Jaime OlivaresSoftware ArchitectCommented:
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
BazookaJoeZoneAuthor Commented:
Thanks jaime. The second article is what I needed, it works well.

For the second part of my question, have you found any good methods of passing a struct for example to the new document coming into being while calling OpenDocumentFile()?
0
 
Jaime OlivaresSoftware ArchitectCommented:
OpenDocumentFile() returns you a pointer to a generic CDocument
You just have to cast it to your document class and call some initialization method for it, something like this:

    CMyApp* pApp = (CMyApp*)AfxGetApp();
    CMyDocClass *pDoc =(CMyDocClass *) pApp->m_pDocTemplate->OpenDocumentFile(NULL);
    pDoc->YourInitializeFunction(some_struct_pointer);
0
 
BazookaJoeZoneAuthor Commented:
Thanks a lot jaime, you've been really helpful.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now