[vtkusers] object factories

Bill Hoffman bill.hoffman at kitware.com
Tue Aug 8 09:03:00 EDT 2000


Hi Wolfram,

There are no examples of object factories that use the dll feature in vtk
right now.  There is a linked in version in 
graphics/examplesCxx/ObjectFactory.cxx.

However, I have attached a factory that overrides the vtkOutputWindow,
and prints all of the text to a Word document using COM.

The API for ObjectFactory has changed some since the Users Guide was 
written.  Although the examples in the book will still work, there
are now easier ways to override a class.

You can now just register your class with your factory by name, and
not override the CreateObject function.  Something like this:

  this->RegisterOverride("vtkOutputWindow",
                           "vtkWordOutputWindow",
                           "OLE Word Window",
                           1,
                           vtkObjectFactoryCreatevtkWordOutputWindow);


Here is the word output example .cxx file. (the .h and project is
attached in a tar gz file.  To build the project you will need to
find these files and put them in the project directory: MSO97.DLL MSWORD8.OLB VBEEXT1.OLB):


// vtkWordOutputWindow.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "vtkWordOutputWindow.h"
#include "vtkVersion.h"


BOOL APIENTRY DllMain( HANDLE hModule, 
                        DWORD  ul_reason_for_call, 
                        LPVOID lpReserved
                                          )
{
     switch (ul_reason_for_call)
         {
                 case DLL_PROCESS_ATTACH:
                   CoInitialize(NULL);
                 case DLL_THREAD_ATTACH:
                 case DLL_THREAD_DETACH:
                 case DLL_PROCESS_DETACH:
                         break;
     }
     return TRUE;
}


void vtkWordOutputWindow::PrintSelf(vtkOstream& os, vtkIndent indent)
{
   vtkOutputWindow::PrintSelf(os, indent);
   os << indent <<  "vtkWordOutputWindow " << endl;
}


// This is the constructor of a class that has been exported.
// see vtkWordOutputWindow.h for the class definition
vtkWordOutputWindow::vtkWordOutputWindow()
{ 
    try
      {

      HRESULT hr = m_pWord.CreateInstance(__uuidof(Word::Application));
      if(hr != 0)
        throw _com_error(hr);
      
      m_pWord->Visible = VARIANT_TRUE;
      m_pDoc = m_pWord->Documents->Add();
      }
    catch (_com_error& ComError)
      {
      cerr << ComError.ErrorMessage() << endl;
      }
}

void vtkWordOutputWindow::DisplayText(const char* text)
{
   m_pDoc->Content->InsertAfter(text);
}

VTK_CREATE_CREATE_FUNCTION(vtkWordOutputWindow);

vtkWordOutputWindowFactory::vtkWordOutputWindowFactory()
{
    this->RegisterOverride("vtkOutputWindow",
                           "vtkWordOutputWindow",
                           "OLE Word Window",
                           1,
                           vtkObjectFactoryCreatevtkWordOutputWindow);
}


extern "C" VTKWORDOUTPUTWINDOW_API vtkObjectFactory* vtkLoad()
{
   return new vtkWordOutputWindowFactory;
}


const char* vtkWordOutputWindowFactory::GetVTKSourceVersion()
{
   return VTK_SOURCE_VERSION;
}

const char* vtkWordOutputWindowFactory::GetDescription()
{
   return "vtk debug output to Word via OLE factory";
}


At 07:26 AM 8/8/00 -0500, Wolfram H Volpi wrote:
>Are there any examples of an implemented object factory that overrides a
>vtk class? 
>
>I read the February 2000 vtk User's Guide, section 9.5 Object Factories.
>There seems to be a contradiction between the documentation and the
>example factories.
>
>"How To Write A Factory", page 206, says you must implement CreatObject(). 
>"How To Install A Factory", page 207, says a dynamically loaded factory
>must have vtkLoad(). 
>
>The last sentence refers to examples vtkGraphicsFactory and
>vtkImageFactory.  But neither example implements the two functions
>specified above. 
>
>Does anyone have an example of a dynamically loaded vtk object factory
>with a DLL that over rides a class?
>
>Thank you,
>Wolfv
>
>
>
>_______________________________________________
>This is the private VTK discussion list. 
>Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/vtkusers 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wordout.tgz
Type: application/octet-stream
Size: 3354 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20000808/40300da8/attachment.obj>


More information about the vtkusers mailing list