DispatchObject.cpp

00001 
00002 #include <objbase.h>
00003 #include <QApplication>
00004 #include <QUuid>
00005 #include <QStringList>
00006 
00007 #include "DispatchObject.h"
00008 
00009 LONG DispatchObject::m_dispatchObjects = 0;
00010 
00011 HRESULT __stdcall DispatchObject::QueryInterface( const IID & iid, void ** ppv )
00012 {
00013   /*
00014   ** This is probably totally unnecessary since the Windows COM subsystem
00015   **  called us, and it's totally extremely unlikely that Windows is
00016   **  going to call us and not give us a pointer.  But, check it anyway.
00017   **
00018   */
00019   if( !ppv ) 
00020     return( E_FAIL );
00021 
00022   /*
00023   ** Check the ID requested against known ID numbers for the Class 
00024   **  Factory.
00025   **
00026   */
00027   if( ::IsEqualIID( iid, IID_IUnknown  ) ||
00028       ::IsEqualIID( iid, IID_IDispatch ) )
00029   {
00030     /*
00031     ** The ID he requested from is good.  So, we can give him a pointer
00032     **  to us (which is what he requested).  Go ahead and cast this pointer
00033     **  to the IDispatch type to be sure everything is laid out
00034     **  properly.  In other words, the .this. pointer might be ok, but if
00035     **  we cast .this. to a .IDispatch. then we're sure it's ok.
00036     **
00037     */
00038     *ppv = (IDispatch*) this;
00039 
00040     /*
00041     ** Increment the reference counter to us.
00042     **
00043     */
00044     AddRef();
00045 
00046     /*
00047     ** Let him know the result was successful.
00048     **
00049     */
00050     return( S_OK );
00051 
00052   } // endif( ..valid ID requested.. )
00053 
00054   /*
00055   ** Something not working out as planned.
00056   **
00057   */
00058   return( E_NOINTERFACE );
00059 
00060 }
00061 
00062 ULONG __stdcall DispatchObject::AddRef()
00063 {
00064   ::InterlockedIncrement(&m_ref);
00065 //  qDebug( "Dispatch::AddRef(%ld)", m_ref );
00066   return( m_ref );
00067 }
00068 
00069 ULONG __stdcall DispatchObject::Release()
00070 {
00071   ::InterlockedDecrement( &m_ref );
00072 
00073 //  qDebug( "Dispatch::Release(%ld)", m_ref );
00074 
00075   if( m_ref == 0 )
00076   {
00077     delete this;
00078     return 0;
00079   }
00080 
00081   return( m_ref );
00082 }
00083 
00084 LONG __stdcall DispatchObject::GetTypeInfoCount( UINT * o_count )
00085 {
00086   if( !o_count ) return( E_FAIL );
00087   o_count = 0;
00088   return( S_OK );
00089 }
00090 
00091 LONG __stdcall DispatchObject::GetTypeInfo( UINT, LCID, ITypeInfo** )
00092 {
00093   return( E_FAIL );
00094 }
00095 
00096 HRESULT __stdcall DispatchObject::GetIDsOfNames( const IID & iid, BSTR * arrayNames, UINT countNames, LCID, DISPID * arrayDispIDs )
00097 {
00098   QStringList names;
00099   for( UINT i=0; i<countNames; i++ )
00100     names.append( QString().fromWCharArray(arrayNames[i]) );
00101 
00102   qDebug( "DispatchObject::GetIDsOfNames(%d,%s)", countNames, qPrintable(names.join(",")) );
00103 
00104   arrayDispIDs[0] = 5;
00105 
00106   return( S_OK );
00107 }
00108 
00109 HRESULT __stdcall DispatchObject::Invoke( DISPID dispidMember, const IID & iid, LCID lcid, WORD wFlags, DISPPARAMS * pDispParams, VARIANT * pvr, EXCEPINFO * pExcepInfo, UINT * pArgErr )
00110 {
00111   qDebug( "DispatchObject::Invoke(%ld)", dispidMember );
00112   return( S_OK );
00113 }
00114 
00115 DispatchObject::DispatchObject()
00116 {
00117   /*
00118   ** Set our reference to 1 since we are returning a reference to ourself.
00119   **
00120   */
00121   m_ref = 1;
00122   m_dispatchObjects++;
00123   qDebug( "DispatchObject::DispatchObject(%ld)", m_dispatchObjects );
00124 }
00125 
00126 DispatchObject::~DispatchObject()
00127 {
00128   m_dispatchObjects--;
00129   qDebug( "DispatchObject::~DispatchObject(%ld)", m_dispatchObjects );
00130 
00131 //  if( Count() == 0 )
00132 //    exit(0);
00133 }
00134 
00135 LONG DispatchObject::Count()
00136 {
00137   return( m_dispatchObjects );
00138 }
00139 
00140 




~ ~ ~ ~ ~ ~
Don't create Texas sized problems...
Comment your Code!
~ ~ ~ ~ ~ ~
Author: Mark Petryk
Lorimark Solutions, LLC