?
Solved

Multi Document Templates in MFC DLLs

Posted on 2003-03-18
10
Medium Priority
?
260 Views
Last Modified: 2013-11-20
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
Comment
Question by:mjwilliamson
[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
  • 6
  • 4
10 Comments
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8160434


 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
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8160442


 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
 

Author Comment

by:mjwilliamson
ID: 8160539
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mjwilliamson
ID: 8160556
I should also add that each doc template is read
in from different dlls.
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8160569

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

Expert Comment

by:williamcampbell
ID: 8160570

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

Expert Comment

by:williamcampbell
ID: 8160577

 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
 

Author Comment

by:mjwilliamson
ID: 8160631
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
 
LVL 12

Accepted Solution

by:
williamcampbell earned 500 total points
ID: 8160673

  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
 

Author Comment

by:mjwilliamson
ID: 8160709
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

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

770 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