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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Multi Document Templates in MFC DLLs

Hi

I have an application which reads in its Document templates
from MFC shared dlls. In one of the documents I have an embeded
excel sheet. From my main app I need to be able to get the dispatch
for the new cntritem. The cntritem.cpp file has method GetDispatch()
which returns the dispatch of the excel embeded worksheet.

How can I get the main app to access this information?
is it possible?

As the main app has no prior knowledge of the template contents
then how can it get access to this method.

Would I be better just to incorporate the document template as
part of the main app? I think this may be easier.

Anybody got any suggestions, had the same problem?

Thanks in advance
Mark
0
mjwilliamson
Asked:
mjwilliamson
  • 6
  • 4
1 Solution
 
williamcampbellCommented:


 You can iterate thru the templates.

POSITION pos = AfxGetApp ()->GetFirstDocTemplatePosition ();
if ( pos )
{
  CDocTemplate* pTemplate =
AfxGetApp ()->GetNextDocTemplate ( pos );
     POSITION tPos = pTemplate->GetFirstDocPosition ();
     if ( tPos )
     {
            CDocument* pDoc = pTemplate->GetNextDoc ( tPos );
         if ( pDoc )
         {
             // CHECK YOU DOC TYPE HERE
             if ( pDoc->IsKindOf ( YOURDOC ) )
             {
          POSITION pos = pDoc->GetFirstViewPosition ();
             while ( pView = pDoc->GetNextView ( pos ) )
             IDispatch *pDispatch = pView->GetDispatch ();
             }
            }
         }
}
 
0
 
williamcampbellCommented:


 You can iterate thru the templates.

POSITION pos = AfxGetApp ()->GetFirstDocTemplatePosition ();
if ( pos )
{
  CDocTemplate* pTemplate =
AfxGetApp ()->GetNextDocTemplate ( pos );
     POSITION tPos = pTemplate->GetFirstDocPosition ();
     if ( tPos )
     {
            CDocument* pDoc = pTemplate->GetNextDoc ( tPos );
         if ( pDoc )
         {
             // CHECK YOU DOC TYPE HERE
             if ( pDoc->IsKindOf ( YOURDOC ) )
             {
          POSITION pos = pDoc->GetFirstViewPosition ();
             while ( pView = pDoc->GetNextView ( pos ) )
             IDispatch *pDispatch = pView->GetDispatch ();
             }
            }
         }
}
 
0
 
mjwilliamsonAuthor Commented:
thanks wc

dll setup

COleExcelApp
COleExcelDoc
COleExcelView
COleExcelCntrItem

what i am stuck with is that GetDispatch() is
a member of COleExcelCntrItem() (I just followed
example on MSDN). So I can't call GetDispatch()
cause main doesn't know about it - ?

I feel like I'm stuck in a maze with no exit!

I've tried to create a new COleClientItem from
the COleDocument retrieved from the Doctemplates
but can't seem to get to the m_lpObject, so I guess
you must have to derive a class for access to that.

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
mjwilliamsonAuthor Commented:
I should also add that each doc template is read
in from different dlls.
0
 
williamcampbellCommented:

 Can you derive a class from COleExcelView theat has a new function GetExcelCntrItem()?
0
 
williamcampbellCommented:

 Can you derive a class from COleExcelView theat has a new function GetExcelCntrItem()?
0
 
williamcampbellCommented:

 Once the templates are read in and added to the template manager is should be ok to access them from the code I sent you earlier.

0
 
mjwilliamsonAuthor Commented:
thats the thing COleExcelView is in the dll
so I would have to include the h and cpp files
in the main app - which kind of defeats the purpose
of having it in the dll.

Then any updates I make to the View class for
dll then the main app will have to be recompiled
- do you agree?

I am suspecting this is the only way.
0
 
williamcampbellCommented:

  Once you add the new function to COleExecView you can get the view from the doc and the doc from the template.

   in main app

   #include "COleExecView.h"

   POSITION pos = pDoc->GetFirstViewPosition ();
   COleExecView *pView = (ColeExecView*)pDoc->GetNextView ( pos ) )

   COleExecCntrItem* pCntr = pView->GetCntrItem ();

   Did you write the EXecl DLL?  

 
 
0
 
mjwilliamsonAuthor Commented:
yes i wrote the dll but i wanted to be able to
keep the dll source seperate, but that was maybe
a little ambitious. Obviously there has to be
some knowledge do perform this task so your answer
is good. thanks wc
0

Featured Post

[Webinar] 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.

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