示例#1
0
static HRESULT STDMETHODCALLTYPE QueryInterface( IDispatch * lpThis,
                                                 REFIID riid, void ** ppRet )
{
   if( IsEqualIID( riid, HB_ID_REF( IID_IUnknown ) ) ||
       IsEqualIID( riid, HB_ID_REF( IID_IDispatch ) ) )
   {
      *ppRet = ( void * ) lpThis;
      HB_VTBL( lpThis )->AddRef( HB_THIS( lpThis ) );
      return S_OK;
   }
   *ppRet = NULL;
   return E_NOINTERFACE;
}
示例#2
0
PHB_ITEM hb_oleAxControlNew( PHB_ITEM pItem, HWND hWnd )
{
   IUnknown *  pUnk  = NULL;
   IDispatch * pDisp = NULL;

   if( pItem )
      hb_itemClear( pItem );

   if( ! hb_oleAxInit() || ! s_pAtlAxGetControl )
   {
      hb_oleSetError( S_OK );
      hb_errRT_OLE( EG_UNSUPPORTED, 1010, 0, "ActiveX not initialized", HB_ERR_FUNCNAME );
   }
   else
   {
      HRESULT lOleError = ( *s_pAtlAxGetControl )( hWnd, &pUnk );

      if( lOleError == S_OK )
      {
         lOleError = HB_VTBL( pUnk )->QueryInterface( HB_THIS_( pUnk ) HB_ID_REF( IID_IDispatch ), ( void ** ) ( void * ) &pDisp );

         if( lOleError == S_OK )
            pItem = hb_oleItemPut( pItem, pDisp );

         HB_VTBL( pUnk )->Release( HB_THIS( pUnk ) );
      }

      hb_oleSetError( lOleError );

      if( lOleError != S_OK )
         hb_errRT_OLE( EG_ARG, 1011, ( HB_ERRCODE ) lOleError, NULL, HB_ERR_FUNCNAME );
   }

   return pItem;
}
示例#3
0
static HB_BOOL s_objItemToVariant( VARIANT * pVariant, PHB_ITEM pItem )
{
   void * pvObj;

   VariantClear( pVariant );

   if( s_createHbOleObject( HB_ID_REF( IID_IDispatch ), &pvObj,
                            hb_itemNew( pItem ), HB_FALSE ) == S_OK )
   {
      V_VT( pVariant ) = VT_DISPATCH;
      V_DISPATCH( pVariant ) = ( IDispatch * ) pvObj;
      return HB_TRUE;
   }
   return HB_FALSE;
}
示例#4
0
/* OLE InProc DLL server API
 */
STDAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, void ** ppv )
{
   HRESULT hr;

   if( IsEqualCLSID( rclsid, HB_ID_REF( s_IID_IHbOleServer ) ) )
   {
      hr = classQueryInterface( ( IClassFactory * ) ( void * ) &s_IClassFactoryObj, riid, ppv );
   }
   else
   {
      *ppv = NULL;
      hr = CLASS_E_CLASSNOTAVAILABLE;
   }

   return hr;
}
示例#5
0
static HRESULT STDMETHODCALLTYPE Invoke( IDispatch * lpThis, DISPID dispid, REFIID riid,
                                         LCID lcid, WORD wFlags, DISPPARAMS * pParams,
                                         VARIANT * pVarResult, EXCEPINFO * pExcepInfo,
                                         UINT * puArgErr )
{
   PHB_ITEM pAction;
   HRESULT hr;

   HB_SYMBOL_UNUSED( lcid );
   HB_SYMBOL_UNUSED( wFlags );
   HB_SYMBOL_UNUSED( pExcepInfo );
   HB_SYMBOL_UNUSED( puArgErr );

   if( ! IsEqualIID( riid, HB_ID_REF( IID_NULL ) ) )
      return DISP_E_UNKNOWNINTERFACE;

   hr = DISP_E_MEMBERNOTFOUND;

   pAction = ( ( ISink * ) lpThis )->pItemHandler;
   if( pAction )
   {
      PHB_ITEM pKey = hb_itemPutNL( hb_stackAllocItem(), ( long ) dispid );

      if( pAction && HB_IS_HASH( pAction ) )
      {
         pAction = hb_hashGetItemPtr( pAction, pKey, 0 );
         pKey = NULL;
      }

      if( pAction && hb_oleDispInvoke( NULL, pAction, pKey,
                                       pParams, pVarResult, NULL,
                                       ( ( ISink * ) lpThis )->uiClass ) )
         hr = S_OK;

      hb_stackPop();
   }

   return hr;
}
示例#6
0
static HRESULT STDMETHODCALLTYPE Invoke( IDispatch * lpThis, DISPID dispid, REFIID riid,
                                         LCID lcid, WORD wFlags, DISPPARAMS * pParams,
                                         VARIANT * pVarResult, EXCEPINFO * pExcepInfo,
                                         UINT * puArgErr )
{
   PHB_DYNS pDynSym;
   PHB_ITEM pAction;
   HB_USHORT uiClass = 0;

   HB_SYMBOL_UNUSED( lcid );
   HB_SYMBOL_UNUSED( pExcepInfo );
   HB_SYMBOL_UNUSED( puArgErr );

   if( ! IsEqualIID( riid, HB_ID_REF( IID_NULL ) ) )
      return DISP_E_UNKNOWNINTERFACE;

   pAction = ( ( IHbOleServer * ) lpThis )->pAction;
   if( ! pAction )
      pAction = s_pAction;

   if( pAction )
   {
      HB_BOOL fResult = HB_FALSE;

      if( s_pMsgHash )
      {
         if( ( wFlags & DISPATCH_METHOD ) != 0 ||
             ( ( wFlags & DISPATCH_PROPERTYGET ) != 0 && pParams->cArgs == 0 ) ||
             ( ( wFlags & DISPATCH_PROPERTYPUT ) != 0 && pParams->cArgs == 1 ) )
         {
            fResult = hb_oleDispInvoke( NULL, pAction,
                                        hb_hashGetKeyAt( s_pMsgHash, ( HB_SIZE ) dispid ),
                                        pParams, pVarResult, s_objItemToVariant, uiClass );
         }
      }
      else if( HB_IS_HASH( pAction ) )
      {
         PHB_ITEM pItem;

         if( ( ( IHbOleServer * ) lpThis )->fGuids )
         {
            PHB_ITEM pKey = hb_itemPutNL( hb_stackAllocItem(), ( long ) dispid );
            pItem = hb_hashGetItemPtr( pAction, pKey, 0 );
            hb_stackPop();
         }
         else
            pItem = hb_hashGetValueAt( pAction, ( HB_SIZE ) dispid );

         if( pItem )
         {
            if( HB_IS_EVALITEM( pItem ) )
            {
               if( ( wFlags & DISPATCH_METHOD ) != 0 )
               {
                  PHB_SYMB pSym = hb_itemGetSymbol( pItem );
                  fResult = hb_oleDispInvoke( pSym, pSym ? pAction : pItem, NULL,
                                              pParams, pVarResult,
                                              s_objItemToVariant, uiClass );
               }
            }
            else if( ( wFlags & DISPATCH_PROPERTYGET ) != 0 &&
                     pParams->cArgs == 0 )
            {
               if( pVarResult )
                  hb_oleItemToVariantEx( pVarResult, pItem, s_objItemToVariant );
               fResult = HB_TRUE;
            }
            else if( ( wFlags & DISPATCH_PROPERTYPUT ) != 0 &&
                     pParams->cArgs == 1 )
            {
               hb_oleVariantToItemEx( pItem, &pParams->rgvarg[ 0 ], uiClass );
               fResult = HB_TRUE;
            }
         }
      }
      else if( HB_IS_OBJECT( pAction ) )
      {
         pDynSym = hb_dispIdToDynsym( dispid );
         if( pDynSym && ( wFlags & DISPATCH_PROPERTYPUT ) != 0 )
         {
            if( pParams->cArgs == 1 )
            {
               char szName[ HB_SYMBOL_NAME_LEN + 1 ];
               szName[ 0 ] = '_';
               hb_strncpy( szName + 1, hb_dynsymName( pDynSym ), sizeof( szName ) - 2 );
               pDynSym = hb_dynsymFindName( szName );
            }
            else
               pDynSym = NULL;
         }
         if( pDynSym && hb_objHasMessage( pAction, pDynSym ) )
         {
            fResult = hb_oleDispInvoke( hb_dynsymSymbol( pDynSym ),
                                        pAction, NULL, pParams, pVarResult,
                                        s_objItemToVariant, uiClass );
         }
      }
      if( ! fResult )
         return DISP_E_MEMBERNOTFOUND;
   }
   else
   {
      pDynSym = hb_dispIdToDynsym( dispid );
      if( ! pDynSym )
         return DISP_E_MEMBERNOTFOUND;

      if( wFlags & DISPATCH_PROPERTYPUT )
      {
         if( pParams->cArgs == 1 && hb_dynsymIsMemvar( pDynSym ) )
         {
            PHB_ITEM pItem = hb_stackAllocItem();

            hb_oleVariantToItemEx( pItem, &pParams->rgvarg[ 0 ], uiClass );
            hb_memvarSetValue( hb_dynsymSymbol( pDynSym ), pItem );
            hb_stackPop();
            return S_OK;
         }
         else
            return DISP_E_MEMBERNOTFOUND;
      }
      else if( ( wFlags & DISPATCH_PROPERTYGET ) &&
               pParams->cArgs == 0 && hb_dynsymIsMemvar( pDynSym ) )
      {
         if( pVarResult )
         {
            PHB_ITEM pItem = hb_stackAllocItem();
            hb_memvarGet( pItem, hb_dynsymSymbol( pDynSym ) );
            hb_oleItemToVariantEx( pVarResult, pItem, s_objItemToVariant );
            hb_stackPop();
         }
         return S_OK;
      }
      else if( ( wFlags & DISPATCH_METHOD ) == 0 ||
               ! hb_dynsymIsFunction( pDynSym ) )
         return DISP_E_MEMBERNOTFOUND;
      else if( ! hb_oleDispInvoke( hb_dynsymSymbol( pDynSym ),
                                   NULL, NULL, pParams, pVarResult,
                                   s_objItemToVariant, uiClass ) )
         return DISP_E_MEMBERNOTFOUND;
   }

   return S_OK;
}
示例#7
0
static HRESULT STDMETHODCALLTYPE GetIDsOfNames( IDispatch * lpThis, REFIID riid,
                                                LPOLESTR * rgszNames,
                                                UINT cNames, LCID lcid,
                                                DISPID * rgDispId )
{
   HRESULT hr = S_OK;

   HB_SYMBOL_UNUSED( lcid );

   if( ! IsEqualIID( riid, HB_ID_REF( IID_NULL ) ) )
      hr = DISP_E_UNKNOWNINTERFACE;
   else if( ( ( IHbOleServer * ) lpThis )->fGuids )
      return E_NOTIMPL;
   else if( cNames > 0 )
   {
      char szName[ HB_SYMBOL_NAME_LEN + 1 ];
      DISPID dispid = 0;
      UINT ui;

      if( s_WideToAnsiBuffer( rgszNames[ 0 ], szName,
                              ( int ) sizeof( szName ) ) != 0 )
      {
         PHB_ITEM pAction;

         pAction = ( ( IHbOleServer * ) lpThis )->pAction;
         if( ! pAction )
            pAction = s_pAction;
         if( pAction )
         {
            if( s_pMsgHash )
            {
               HB_SIZE nPos = hb_hashGetCItemPos( s_pMsgHash, szName );

               if( nPos == 0 )
               {
                  PHB_ITEM pKey = hb_itemPutC( hb_stackAllocItem(), szName );
                  if( hb_hashAdd( s_pMsgHash, pKey, NULL ) )
                     hb_hashScan( s_pMsgHash, pKey, &nPos );
                  hb_stackPop();
               }
               dispid = ( DISPID ) nPos;
            }
            else if( HB_IS_HASH( pAction ) )
            {
               HB_SIZE nPos = hb_hashGetCItemPos( pAction, szName );

               if( nPos )
                  dispid = ( DISPID ) nPos;
            }
            else if( HB_IS_OBJECT( pAction ) )
            {
               PHB_DYNS pDynSym = hb_dynsymFindName( szName );

               if( pDynSym && hb_objHasMessage( pAction, pDynSym ) )
                  dispid = hb_dynsymToDispId( pDynSym );
            }
         }
         else
         {
            PHB_DYNS pDynSym = hb_dynsymFindName( szName );

            if( pDynSym && ( hb_dynsymIsFunction( pDynSym ) ||
                             hb_dynsymIsMemvar( pDynSym ) ) )
               dispid = hb_dynsymToDispId( pDynSym );
         }
      }

      for( ui = 0; ui < cNames; ++ui )
         rgDispId[ ui ] = DISPID_UNKNOWN;

      hr = DISP_E_UNKNOWNNAME;
      if( dispid )
      {
         rgDispId[ 0 ] = dispid;
         if( cNames == 1 )
            hr = S_OK;
      }
   }

   return hr;
}
示例#8
0
static HRESULT _get_default_sink( IDispatch * iDisp, const char * szEvent, IID * piid )
{
   ITypeInfo * iTI;
   ITypeInfo * iTISink;
   TYPEATTR *  pTypeAttr;
   HREFTYPE    hRefType;
   HRESULT     hr;
   int         iFlags, i;

   if( ! szEvent )
   {
      IProvideClassInfo2 * iPCI2;
      IProvideClassInfo *  iPCI;

      /* Method 1: using IProvideClassInfo2 */

      hr = HB_VTBL( iDisp )->QueryInterface( HB_THIS_( iDisp ) HB_ID_REF( IID_IProvideClassInfo2 ), ( void ** ) ( void * ) &iPCI2 );
      if( hr == S_OK )
      {
         HB_TRACE( HB_TR_DEBUG, ( "_get_default_sink IProvideClassInfo2 OK" ) );
         hr = HB_VTBL( iPCI2 )->GetGUID( HB_THIS_( iPCI2 ) GUIDKIND_DEFAULT_SOURCE_DISP_IID, piid );
         HB_VTBL( iPCI2 )->Release( HB_THIS( iPCI2 ) );

         if( hr == S_OK )
            return S_OK;
      }
      else
         HB_TRACE( HB_TR_DEBUG, ( "_get_default_sink IProvideClassInfo2 obtain error %08lX", hr ) );


      /* Method 2: using IProvideClassInfo and searching for default source in ITypeInfo */

      hr = HB_VTBL( iDisp )->QueryInterface( HB_THIS_( iDisp ) HB_ID_REF( IID_IProvideClassInfo ), ( void ** ) ( void * ) &iPCI );
      if( hr == S_OK )
      {
         HB_TRACE( HB_TR_DEBUG, ( "_get_default_sink IProvideClassInfo OK" ) );

         iTI = NULL;

         hr = HB_VTBL( iPCI )->GetClassInfo( HB_THIS_( iPCI ) & iTI );
         if( hr == S_OK )
         {
            pTypeAttr = NULL;

            hr = HB_VTBL( iTI )->GetTypeAttr( HB_THIS_( iTI ) & pTypeAttr );
            if( hr == S_OK )
            {
               for( i = 0; i < pTypeAttr->cImplTypes; i++ )
               {
                  hr = HB_VTBL( iTI )->GetImplTypeFlags( HB_THIS_( iTI ) i, &iFlags );
                  if( hr == S_OK && ( iFlags & IMPLTYPEFLAG_FDEFAULT ) && ( iFlags & IMPLTYPEFLAG_FSOURCE ) )
                  {
                     if( HB_VTBL( iTI )->GetRefTypeOfImplType( HB_THIS_( iTI ) i, &hRefType ) == S_OK &&
                         HB_VTBL( iTI )->GetRefTypeInfo( HB_THIS_( iTI ) hRefType, &iTISink ) == S_OK )
                     {
                        HB_TRACE( HB_TR_DEBUG, ( "_get_default_sink Method 2: default source is found" ) );

                        hr = HB_VTBL( iTISink )->GetTypeAttr( HB_THIS_( iTISink ) & pTypeAttr );
                        if( hr == S_OK )
                        {
                           *piid = pTypeAttr->guid;
                           HB_VTBL( iTISink )->ReleaseTypeAttr( HB_THIS_( iTISink ) pTypeAttr );

                           HB_VTBL( iTI )->ReleaseTypeAttr( HB_THIS_( iTI ) pTypeAttr );
                           HB_VTBL( iPCI )->Release( HB_THIS( iPCI ) );
                           return S_OK;
                        }
                     }
                  }
               }
               HB_VTBL( iTI )->ReleaseTypeAttr( HB_THIS_( iTI ) pTypeAttr );
            }
         }
         HB_VTBL( iPCI )->Release( HB_THIS( iPCI ) );
      }
      else
         HB_TRACE( HB_TR_DEBUG, ( "_get_default_sink IProvideClassInfo obtain error %08lX", hr ) );
   }


   /* Method 3: using CoClass */

   hr = HB_VTBL( iDisp )->GetTypeInfo( HB_THIS_( iDisp ) 0, LOCALE_SYSTEM_DEFAULT, &iTI );
   if( hr == S_OK )
   {
      ITypeLib * iTL = NULL;
      TYPEATTR * pTypeAttr2;

      hr = HB_VTBL( iTI )->GetContainingTypeLib( HB_THIS_( iTI ) & iTL, NULL );
      HB_VTBL( iTI )->Release( HB_THIS( iTI ) );

      if( hr == S_OK )
      {
         int iCount = HB_VTBL( iTL )->GetTypeInfoCount( HB_THIS( iTL ) );
         for( i = 0; i < iCount; i++ )
         {
            hr = HB_VTBL( iTL )->GetTypeInfo( HB_THIS_( iTL ) i, &iTI );
            if( hr == S_OK )
            {
               hr = HB_VTBL( iTI )->GetTypeAttr( HB_THIS_( iTI ) & pTypeAttr );
               if( hr == S_OK )
               {
                  if( pTypeAttr->typekind == TKIND_COCLASS )
                  {
                     int j;

                     for( j = 0; j < pTypeAttr->cImplTypes; j++ )
                     {
                        if( szEvent )
                        {
                           if( HB_VTBL( iTI )->GetRefTypeOfImplType( HB_THIS_( iTI ) j, &hRefType ) == S_OK &&
                               HB_VTBL( iTI )->GetRefTypeInfo( HB_THIS_( iTI ) hRefType, &iTISink ) == S_OK )
                           {
                              BSTR bstr;

                              hr = HB_VTBL( iTISink )->GetDocumentation( HB_THIS_( iTISink ) - 1, &bstr, NULL, NULL, NULL );
                              if( hr == S_OK )
                              {
                                 char str[ 256 ];
                                 int  iLen;

                                 iLen = WideCharToMultiByte( CP_ACP, 0, bstr, -1, str, sizeof( str ), NULL, NULL );
                                 if( iLen > 0 )
                                 {
                                    str[ iLen - 1 ] = '\0';
                                    if( ! strcmp( szEvent, str ) )
                                    {
                                       hr = HB_VTBL( iTISink )->GetTypeAttr( HB_THIS_( iTISink ) & pTypeAttr2 );
                                       if( hr == S_OK )
                                       {
                                          *piid = pTypeAttr2->guid;
                                          HB_VTBL( iTISink )->ReleaseTypeAttr( HB_THIS_( iTISink ) pTypeAttr2 );

                                          HB_VTBL( iTISink )->Release( HB_THIS( iTISink ) );
                                          HB_VTBL( iTI )->ReleaseTypeAttr( HB_THIS_( iTI ) pTypeAttr );
                                          HB_VTBL( iTI )->Release( HB_THIS( iTI ) );
                                          HB_VTBL( iTL )->Release( HB_THIS( iTL ) );
                                          return S_OK;
                                       }
                                    }
                                 }
                              }
                              HB_VTBL( iTISink )->Release( HB_THIS( iTISink ) );
                           }
                        }
                        else /* szEvent == NULL */
                        {
                           hr = HB_VTBL( iTI )->GetImplTypeFlags( HB_THIS_( iTI ) j, &iFlags );
                           if( hr == S_OK && ( iFlags & IMPLTYPEFLAG_FDEFAULT ) && ( iFlags & IMPLTYPEFLAG_FSOURCE ) )
                           {
                              if( HB_VTBL( iTI )->GetRefTypeOfImplType( HB_THIS_( iTI ) j, &hRefType ) == S_OK &&
                                  HB_VTBL( iTI )->GetRefTypeInfo( HB_THIS_( iTI ) hRefType, &iTISink ) == S_OK )
                              {
                                 hr = HB_VTBL( iTISink )->GetTypeAttr( HB_THIS_( iTISink ) & pTypeAttr2 );
                                 if( hr == S_OK )
                                 {
#if 0
/* Debug code. You can also comment out iFlags condition, to list more interfaces [Mindaugas] */
                                    BSTR bstr;
                                    char str[ 256 ];
                                    int  iLen;

                                    HB_VTBL( iTISink )->GetDocumentation( HB_THIS_( iTISink ) - 1, &bstr, NULL, NULL, NULL );
                                    iLen = WideCharToMultiByte( CP_ACP, 0, bstr, -1, str, sizeof( str ), NULL, NULL );
                                    str[ iLen - 1 ] = '\0';
                                    HB_TRACE( HB_TR_DEBUG, ( "_get_default_sink Method 3: iFlags=%d guid=%s class=%s", iFlags, GUID2String( &( pTypeAttr2->guid ) ), str ) );
#endif
                                    *piid = pTypeAttr2->guid;
                                    HB_VTBL( iTISink )->ReleaseTypeAttr( HB_THIS_( iTISink ) pTypeAttr2 );

                                    HB_VTBL( iTI )->ReleaseTypeAttr( HB_THIS_( iTI ) pTypeAttr );
                                    HB_VTBL( iTI )->Release( HB_THIS( iTI ) );
                                    HB_VTBL( iTL )->Release( HB_THIS( iTL ) );
                                    return S_OK;
                                 }
                              }
                           }
                        }
                     }
                  }
                  HB_VTBL( iTI )->ReleaseTypeAttr( HB_THIS_( iTI ) pTypeAttr );
               }
               HB_VTBL( iTI )->Release( HB_THIS( iTI ) );
            }
         }
         HB_VTBL( iTL )->Release( HB_THIS( iTL ) );
      }
   }
   return E_NOINTERFACE;
}