Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-31
8
Medium Priority
?
187 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

580 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