?
Solved

Get a pointer to the Document class from another (unrelated) class

Posted on 2003-03-31
8
Medium Priority
?
186 Views
Last Modified: 2013-11-20
Hi,
I have a class derived from CAsyncSocket that I'm using to do all sorts of silliness. I need a pointer to the document class that I can use from within this class. I can't use the GetDocument that's in the view class since this is distinct from that, but a method similar to that would be ideal.
One method that has been pointed out is the use of the AfxGetApp() function, but this returns a pointer to a CWinApp object rather than to the Document class; so... can someone help me with either casting this into a pointer to the Doc (casting is not something I have gotten understood yet), or show me some other method of getting hold of the Doc class?
Thanks in advance.
0
Comment
Question by:chrisedgington
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8239748

POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition ();
if ( pos )
{
CDocTemplate* pTemplate = AfxGetApp ().GetNextDocTemplate ( pos );
 POSITION tPos = pTemplate->GetFirstDocPosition ();
 if ( tPos )
 {
   CMyDoc* = (CMyDoc*)GetNextDoc ( tPos );
 }
}
0
 

Author Comment

by:chrisedgington
ID: 8240664
Thanks, this is a good start. I should mention though that it is only a single document app so I only really need the first lines of that code.
Using that then, I get a POSITION object (pos) that points to the Document; but this doesn't enable me to actually use it as a pointer to the Document-i.e I can't use pos-> and see a nice little list of all the stuff in the Document class. Any comments on how this can be transformed into a pointer of type CMyDoc* rather than a position object?
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8240698

Yes you get the doc this way

CMyDoc* pDoc = (CMyDoc*)GetNextDoc ( tPos );

Sorry I forgot the pDoc vaiable name

pDoc->...list of stuff..



0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:chrisedgington
ID: 8241024
It's throwing up errors at me now, the cheeky darn thing.
Here's what I have:
POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition ();
if ( pos )
{
CDocTemplate* pTemplate = AfxGetApp()->GetNextDocTemplate (pos);
POSITION tPos = pTemplate->GetFirstDocPosition();
CBSDoc* pDoc = (CBSDoc*)GetNextDoc( tPos );
}

I removed the if(tPos) in case that stuffed things up, it being single document and all. Still-it says that GetNextDoc is an undeclared identifier. My program is called BS-that's how comes I've changed the name.
Any ideas?

Cheers
0
 
LVL 12

Accepted Solution

by:
williamcampbell earned 200 total points
ID: 8241231
change
CBSDoc* pDoc = (CBSDoc*)GetNextDoc( tPos );
to
CBSDoc* pDoc = (CBSDoc*)pTemplate->GetNextDoc( tPos );
0
 

Author Comment

by:chrisedgington
ID: 8245573
You sir, are the man.
Cheers.
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8247505

 thx for points :)
0
 

Author Comment

by:chrisedgington
ID: 8247569
Thanks for the answer :p
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question