예제 #1
0
static void hb_hrbExit( PHRB_BODY pHrbBody )
{
   if( pHrbBody->fExit )
   {
      if( hb_vmRequestReenter() )
      {
         HB_ULONG ul;

         pHrbBody->fExit = HB_FALSE;
         pHrbBody->fInit = HB_TRUE;

         for( ul = 0; ul < pHrbBody->ulSymbols; ul++ )
         {
            if( ( pHrbBody->pSymRead[ ul ].scope.value & HB_FS_INITEXIT ) == HB_FS_EXIT )
            {
               hb_vmPushSymbol( pHrbBody->pSymRead + ul );
               hb_vmPushNil();
               hb_vmProc( 0 );
               if( hb_vmRequestQuery() != 0 )
                  break;
            }
         }

         hb_vmRequestRestore();
      }
   }
}
예제 #2
0
파일: eval.c 프로젝트: hernad/harbour-core
PHB_ITEM hb_itemDoC( const char * szFunc, HB_ULONG ulPCount, ... )
{
   PHB_ITEM pResult = NULL;

   HB_TRACE( HB_TR_DEBUG, ( "hb_itemDoC(%s, %lu, ...)", szFunc, ulPCount ) );

   if( szFunc )
   {
      PHB_DYNS pDynSym = hb_dynsymFindName( szFunc );

      if( pDynSym )
      {
         if( hb_vmRequestReenter() )
         {
            hb_vmPushSymbol( pDynSym->pSymbol );
            hb_vmPushNil();
            if( ulPCount )
            {
               HB_ULONG ulParam;
               va_list va;
               va_start( va, ulPCount );
               for( ulParam = 1; ulParam <= ulPCount; ulParam++ )
                  hb_vmPush( va_arg( va, PHB_ITEM ) );
               va_end( va );
            }
            hb_vmProc( ( HB_USHORT ) ulPCount );
            pResult = hb_itemNew( hb_stackReturnItem() );
            hb_vmRequestRestore();
         }
      }
   }

   return pResult;
}
예제 #3
0
/* Control handler function */
static VOID WINAPI hbwin_SvcControlHandler( DWORD fdwControl )
{
    if( s_pHarbourControlFunc )
    {
        if( hb_vmRequestReenterExt() )
        {
            hb_vmPushEvalSym();
            hb_vmPush( s_pHarbourControlFunc );
            hb_vmPushNumInt( ( HB_MAXINT ) fdwControl );
            hb_vmSend( 1 );
            hb_vmRequestRestore();
        }
        else
            HB_TRACE( HB_TR_DEBUG, ( "HVM stack not available" ) );
        return;
    }

    switch( fdwControl )
    {
    case SERVICE_CONTROL_STOP:
        s_ServiceStatus.dwWin32ExitCode = 0;
        s_ServiceStatus.dwCurrentState  = SERVICE_STOPPED;
        break;

    case SERVICE_CONTROL_SHUTDOWN:
        s_ServiceStatus.dwWin32ExitCode = 0;
        s_ServiceStatus.dwCurrentState  = SERVICE_STOPPED;
        break;

    default:
        return;
    }

    SetServiceStatus( s_hStatus, &s_ServiceStatus );  /* Report current status */
}
예제 #4
0
파일: core.c 프로젝트: AmericoBalboa/core
static mxml_type_t type_cb( mxml_node_t * node )
{
   HB_CBS_VAR * pCbs = ( HB_CBS_VAR * ) hb_stackTestTSD( &s_cbs_var );

   if( pCbs != NULL )
   {
      PHB_ITEM pCallback = pCbs->type_cb;

      if( pCallback && hb_vmRequestReenter() )
      {
         int iResult;

         hb_vmPushEvalSym();
         hb_vmPush( pCallback );
         mxml_node_push( node, 0 );

         hb_vmSend( 1 );

         iResult = hb_parnidef( -1, MXML_TEXT );

         hb_vmRequestRestore();
         return ( mxml_type_t ) iResult;
      }
   }
   return MXML_TEXT;
}
예제 #5
0
파일: pem.c 프로젝트: Rossine/harbour-core
static int hb_ssl_pem_password_cb( char * buf, int size, int rwflag, void * userdata )
{
   int retsize = 0;

   if( size > 0 && userdata && hb_vmRequestReenter() )
   {
      hb_vmPushEvalSym();
      hb_vmPush( ( PHB_ITEM ) userdata );
      hb_vmPushLogical( rwflag );
      hb_vmSend( 1 );

      buf[ 0 ] = '\0';

      retsize = ( int ) hb_parclen( -1 );

      if( retsize > 0 )
      {
         if( retsize > size )
            retsize = size;

         memcpy( buf, hb_parc( -1 ), retsize );
      }

      hb_vmRequestRestore();
   }

   return retsize;
}
예제 #6
0
파일: core.c 프로젝트: AmericoBalboa/core
static int custom_load_cb( mxml_node_t * node, const char * data )
{
   HB_CUSTOM_CBS_VAR * pCCbs = ( HB_CUSTOM_CBS_VAR * ) hb_stackTestTSD( &s_custom_cbs_var );

   if( node != NULL && pCCbs != NULL && data != NULL )
   {
      PHB_ITEM pCallback = pCCbs->load_cb;

      if( pCallback && hb_vmRequestReenter() )
      {
         int iResult;

         hb_vmPushEvalSym();
         hb_vmPush( pCallback );
         mxml_node_push( node, 0 );
         hb_itemPutC( hb_stackAllocItem(), data );

         hb_vmSend( 2 );

         iResult = hb_parnidef( -1, 1 );

         hb_vmRequestRestore();
         return iResult;
      }
   }
   return 1;
}
예제 #7
0
파일: core.c 프로젝트: AmericoBalboa/core
static char * custom_save_cb( mxml_node_t * node )
{
   HB_CUSTOM_CBS_VAR * pCCbs = ( HB_CUSTOM_CBS_VAR * ) hb_stackTestTSD( &s_custom_cbs_var );

   if( node != NULL && pCCbs != NULL )
   {
      PHB_ITEM pCallback = pCCbs->save_cb;

      if( pCallback && hb_vmRequestReenter() )
      {
         char * pszResult;
         const char * pszText;
         void *       hText;

         hb_vmPushEvalSym();
         hb_vmPush( pCallback );
         mxml_node_push( node, 0 );

         hb_vmSend( 1 );

         pszText   = hb_parstr_utf8( -1, &hText, NULL );
         pszResult = pszText ? strdup( pszText ) : NULL;
         hb_strfree( hText );

         hb_vmRequestRestore();
         return pszResult;
      }
   }
   return NULL;
}
예제 #8
0
파일: core.c 프로젝트: AmericoBalboa/core
static const char * save_cb( mxml_node_t * node, int where )
{
   HB_CBS_VAR * pCbs = ( HB_CBS_VAR * ) hb_stackTestTSD( &s_cbs_var );

   if( node != NULL && pCbs != NULL )
   {
      PHB_ITEM pCallback = pCbs->save_cb;

      if( pCbs->hText )
      {
         hb_strfree( pCbs->hText );
         pCbs->hText = NULL;
      }

      if( pCallback && hb_vmRequestReenter() )
      {
         const char * pszResult;

         hb_vmPushEvalSym();
         hb_vmPush( pCallback );
         mxml_node_push( node, 0 );
         hb_vmPushInteger( where );
         hb_vmSend( 2 );

         pszResult = hb_itemGetStrUTF8( hb_param( -1, HB_IT_ANY ), &pCbs->hText, NULL );

         hb_vmRequestRestore();

         return pszResult;
      }
   }
   return NULL;
}
예제 #9
0
파일: core.c 프로젝트: AmericoBalboa/core
static void sax_cb( mxml_node_t * node, mxml_sax_event_t event, void * data )
{
   HB_CBS_VAR * pCbs = ( HB_CBS_VAR * ) hb_stackTestTSD( &s_cbs_var );

   if( node != NULL && pCbs != NULL )
   {
      PHB_ITEM pCallback = pCbs->sax_cb;

      if( pCallback && hb_vmRequestReenter() )
      {
         HB_USHORT uPCount = 2;

         hb_vmPushEvalSym();
         hb_vmPush( pCallback );
         mxml_node_push( node, 0 );
         hb_vmPushInteger( ( int ) ( event + 1 ) );

         if( data != NULL )
         {
            hb_vmPush( ( PHB_ITEM ) data );
            uPCount++;
         }
         hb_vmSend( uPCount );

         hb_vmRequestRestore();
      }
   }
}
예제 #10
0
static VOID WINAPI hbwin_SvcMainFunction( DWORD dwArgc, LPTSTR * lpszArgv )
{
    s_ServiceStatus.dwServiceType             = SERVICE_WIN32;
    s_ServiceStatus.dwCurrentState            = SERVICE_START_PENDING;
    s_ServiceStatus.dwControlsAccepted        = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
    s_ServiceStatus.dwWin32ExitCode           = 0;
    s_ServiceStatus.dwServiceSpecificExitCode = 0;
    s_ServiceStatus.dwCheckPoint              = 0;
    s_ServiceStatus.dwWaitHint                = 0;

    s_hStatus = RegisterServiceCtrlHandler( s_lpServiceName, ( LPHANDLER_FUNCTION ) hbwin_SvcControlHandler );

    if( s_hStatus != ( SERVICE_STATUS_HANDLE ) 0 )
    {
        if( s_pHarbourEntryFunc != NULL )
        {
            if( hb_vmRequestReenterExt() )
            {
                DWORD i;
                int iArgCount = 0;

                if( ! s_pHarbourControlFunc )
                {
                    /* We report the running status to SCM. */
                    s_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
                    SetServiceStatus( s_hStatus, &s_ServiceStatus );
                }

                hb_vmPushEvalSym();
                hb_vmPush( s_pHarbourEntryFunc );

                for( i = 1; i < dwArgc; ++i )
                {
                    PHB_ITEM pItem = hb_stackAllocItem();

                    HB_ITEMPUTSTR( pItem, lpszArgv[ i ] );
                    if( hb_cmdargIsInternal( hb_itemGetCPtr( pItem ), NULL ) )
                        hb_stackPop();
                    else
                        ++iArgCount;
                }

                hb_vmSend( ( HB_USHORT ) iArgCount );

                hb_vmRequestRestore();
            }
            else
                HB_TRACE( HB_TR_DEBUG, ( "HVM stack not available" ) );
        }
        else
            HB_TRACE( HB_TR_DEBUG, ( "Harbour service entry function not found" ) );
    }
    else
        HB_TRACE( HB_TR_DEBUG, ( "Error registering service" ) );
}
예제 #11
0
static void hb_zebra_draw_codeblock_callback( void * pDrawBlock, double dX, double dY, double dWidth, double dHeight )
{
   if( pDrawBlock && HB_IS_BLOCK( pDrawBlock ) && hb_vmRequestReenter() )
   {
      hb_vmPushEvalSym();
      hb_vmPush( ( PHB_ITEM ) pDrawBlock );
      hb_vmPushDouble( dX, HB_DEFAULT_DECIMALS );
      hb_vmPushDouble( dY, HB_DEFAULT_DECIMALS );
      hb_vmPushDouble( dWidth, HB_DEFAULT_DECIMALS );
      hb_vmPushDouble( dHeight, HB_DEFAULT_DECIMALS );
      hb_vmSend( 4 );
      hb_vmRequestRestore();
   }
}
예제 #12
0
파일: ssl.c 프로젝트: xharbour/core
static void hb_ssl_msg_callback( int write_p, int version, int content_type, const void * buf, size_t len, SSL * ssl, void * userdata )
{
   HB_SYMBOL_UNUSED( ssl );

   if( userdata && hb_vmRequestReenter() )
   {
      hb_vmPushEvalSym();
      hb_vmPush( ( PHB_ITEM ) userdata );
      hb_vmPushLogical( write_p );
      hb_vmPushInteger( version );
      hb_vmPushInteger( content_type );
      hb_vmPushString( ( const char * ) buf, ( HB_SIZE ) len );
      hb_vmSend( 4 );

      hb_vmRequestRestore();
   }
}
예제 #13
0
파일: hbxml2.c 프로젝트: emazv72/hbcontrib
static void xml_errorHandler( void * unused, xmlErrorPtr pError )
{

   if( ! unused && pError && pHandler )
   {

      /*
                HB_TRACE( HB_TR_ERROR, ( "libxml2 error: file=%s domain=%d code=%d message=%s line=%d col=%d s1=%s s2=%s s3=%s",
                               pError->file,
                               pError->domain,
                               pError->code,
                               pError->message,
                               pError->line,
                               pError->int2,
                               pError->str1,
                               pError->str2,
                               pError->str3 ) );
       */

      /* codeblock */


      PHB_ITEM pCallback = pHandler->pErrorBlock;
    
      if( HB_IS_BLOCK( pCallback ) )
      {        
         if( hb_vmRequestReenter() )
         {
           
            //int iResult;

            hb_vmPushEvalSym();
            hb_vmPush( pCallback );
            hb_vmPushPointer( pError );

            hb_vmSend( 1 );

            //iResult = hb_parni( -1 );

            hb_vmRequestRestore();
         }
      }


   }
}
예제 #14
0
static void hb_hrbInit( PHRB_BODY pHrbBody, int iPCount, PHB_ITEM * pParams )
{
   if( pHrbBody->fInit )
   {
      if( hb_vmRequestReenter() )
      {
         HB_ULONG ul;
         HB_BOOL fRepeat, fClipInit = HB_TRUE;
         int i;

         pHrbBody->fInit = HB_FALSE;
         pHrbBody->fExit = HB_TRUE;

         do
         {
            fRepeat = HB_FALSE;
            ul = pHrbBody->ulSymbols;
            while( ul-- )
            {
               /* Check INIT functions */
               if( ( pHrbBody->pSymRead[ ul ].scope.value & HB_FS_INITEXIT ) == HB_FS_INIT )
               {
                  if( strcmp( pHrbBody->pSymRead[ ul ].szName, "CLIPINIT$" ) ?
                      ! fClipInit : fClipInit )
                  {
                     hb_vmPushSymbol( pHrbBody->pSymRead + ul );
                     hb_vmPushNil();
                     for( i = 0; i < iPCount; i++ )
                        hb_vmPush( pParams[ i ] );
                     hb_vmProc( ( HB_USHORT ) iPCount );
                     if( hb_vmRequestQuery() != 0 )
                        break;
                  }
                  else if( fClipInit )
                     fRepeat = HB_TRUE;
               }
            }
            fClipInit = HB_FALSE;
         }
         while( fRepeat && hb_vmRequestQuery() == 0 );

         hb_vmRequestRestore();
      }
   }
}
예제 #15
0
static HRESULT STDMETHODCALLTYPE classCreateInstance( IClassFactory * lpThis,
                                                      IUnknown * punkOuter,
                                                      REFIID riid,
                                                      void ** ppvObj )
{
   HRESULT hr;

   HB_SYMBOL_UNUSED( lpThis );

   *ppvObj = NULL;

   if( punkOuter )
      hr = CLASS_E_NOAGGREGATION;
   else
   {
      PHB_ITEM pAction = NULL;
      HB_BOOL fGuids = HB_FALSE;

      if( s_pAction )
      {
         if( HB_IS_EVALITEM( s_pAction ) )
         {
            if( hb_vmRequestReenter() )
            {
               hb_vmPushEvalSym();
               hb_vmPush( s_pAction );
               hb_vmProc( 0 );
               pAction = hb_itemNew( hb_stackReturnItem() );
               hb_vmRequestRestore();
            }
         }
         else if( HB_IS_HASH( s_pAction ) )
         {
            if( s_fHashClone )
               pAction = hb_itemClone( s_pAction );
            else if( ! s_pMsgHash && s_hashWithNumKeys( s_pAction ) )
               fGuids = HB_TRUE;
         }
      }
      hr = s_createHbOleObject( riid, ppvObj, pAction, fGuids );
   }
   return hr;
}
예제 #16
0
파일: core.c 프로젝트: AmericoBalboa/core
static void error_cb( const char * pszErrorMsg )
{
   HB_ERROR_CB_VAR * pError_cb = ( HB_ERROR_CB_VAR * ) hb_stackTestTSD( &s_error_cb_var );

   if( pError_cb != NULL )
   {
      PHB_ITEM pCallback = pError_cb->error_cb;

      if( pCallback && hb_vmRequestReenter() )
      {
         hb_vmPushEvalSym();
         hb_vmPush( pCallback );
         hb_itemPutC( hb_stackAllocItem(), pszErrorMsg );

         hb_vmSend( 1 );
         hb_vmRequestRestore();
      }
   }
}
예제 #17
0
파일: win_commdlg.c 프로젝트: emazv72/core
static UINT_PTR CALLBACK CCHookProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
   UINT_PTR res;
   HB_BOOL  fInit = HB_FALSE;
   PHB_ITEM pBlock;

   if( msg == WM_INITDIALOG )
   {
      CHOOSECOLOR * cc = ( CHOOSECOLOR * ) lParam;
      SetProp( hWnd, _HB_CHOOSECOLOR_CB_PROP_, hb_itemNew( ( PHB_ITEM ) cc->lCustData ) );
      fInit = HB_TRUE;
   }

   if( ( pBlock = ( PHB_ITEM ) GetProp( hWnd, _HB_CHOOSECOLOR_CB_PROP_ ) ) != NULL &&
       hb_vmRequestReenter() )
   {
      PHB_ITEM pWnd = hbwapi_itemPut_HANDLE( NULL, hWnd );
      PHB_ITEM pMsg = hb_itemPutNInt( NULL, msg );
      PHB_ITEM pLPa = hb_itemPutNInt( NULL, wParam );
      PHB_ITEM pWPa = hb_itemPutNInt( NULL, lParam );

      hb_evalBlock( pBlock, pWnd, pMsg, pLPa, pWPa );

      res = ( UINT_PTR ) hbwapi_par_RESULT( -1 );

      hb_itemRelease( pWnd );
      hb_itemRelease( pMsg );
      hb_itemRelease( pLPa );
      hb_itemRelease( pWPa );

      if( msg == WM_NCDESTROY )
      {
         RemoveProp( hWnd, _HB_CHOOSECOLOR_CB_PROP_ );
         hb_itemRelease( pBlock );
      }

      hb_vmRequestRestore();
   }
   else
      res = 0;

   return fInit ? 1 : res;
}
예제 #18
0
파일: eval.c 프로젝트: hernad/harbour-core
PHB_ITEM hb_itemDo( PHB_ITEM pItem, HB_ULONG ulPCount, ... )
{
   PHB_ITEM pResult = NULL;

   HB_TRACE( HB_TR_DEBUG, ( "hb_itemDo(%p, %lu, ...)", pItem, ulPCount ) );

   if( pItem )
   {
      PHB_SYMB pSymbol = NULL;

      if( HB_IS_STRING( pItem ) )
      {
         PHB_DYNS pDynSym = hb_dynsymFindName( pItem->item.asString.value );

         if( pDynSym )
         {
            pSymbol = pDynSym->pSymbol;
            pItem = NULL;
         }
      }
      else if( HB_IS_SYMBOL( pItem ) )
      {
         pSymbol = pItem->item.asSymbol.value;
         pItem = NULL;
      }
      else if( HB_IS_BLOCK( pItem ) )
      {
         pSymbol = &hb_symEval;
      }

      if( pSymbol )
      {
         if( hb_vmRequestReenter() )
         {
            hb_vmPushSymbol( pSymbol );
            if( pItem )
               hb_vmPush( pItem );
            else
               hb_vmPushNil();

            if( ulPCount )
            {
               HB_ULONG ulParam;
               va_list va;
               va_start( va, ulPCount );
               for( ulParam = 1; ulParam <= ulPCount; ulParam++ )
                  hb_vmPush( va_arg( va, PHB_ITEM ) );
               va_end( va );
            }
            if( pItem )
               hb_vmSend( ( HB_USHORT ) ulPCount );
            else
               hb_vmProc( ( HB_USHORT ) ulPCount );

            pResult = hb_itemNew( hb_stackReturnItem() );
            hb_vmRequestRestore();
         }
      }
   }

   return pResult;
}
예제 #19
0
파일: toolbar.c 프로젝트: emazv72/core
static void hb_gt_wvw_TBMouseEvent( PWVW_WIN wvw_win, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
   POINT xy, colrow;
   SHORT keyCode  = 0;
   SHORT keyState = 0;

   PWVW_GLO wvw = hb_gt_wvw();

   HB_SYMBOL_UNUSED( hWnd );
   HB_SYMBOL_UNUSED( wParam );

   if( message == WM_MOUSEMOVE || message == WM_NCMOUSEMOVE )
   {
      if( ! wvw_win->MouseMove )
         return;
   }

   xy.x = LOWORD( lParam );
   xy.y = HIWORD( lParam );

   colrow = hb_gt_wvw_TBGetColRowFromXY( wvw_win, xy.x, xy.y );

   hb_gt_wvw_SetMouseX( wvw_win, colrow.x );
   hb_gt_wvw_SetMouseY( wvw_win, colrow.y );

   switch( message )
   {
      case WM_LBUTTONDBLCLK:
         keyCode = K_LDBLCLK;
         break;

      case WM_RBUTTONDBLCLK:
         keyCode = K_RDBLCLK;
         break;

      case WM_LBUTTONDOWN:
      {
         HWND hWndFocus = GetFocus();

         if( hb_gt_wvw_GetControlClass( wvw_win, hWndFocus ) > 0 )
            SetFocus( hWnd );

         keyCode = K_LBUTTONDOWN;
         break;
      }

      case WM_RBUTTONDOWN:
         keyCode = K_RBUTTONDOWN;
         break;

      case WM_LBUTTONUP:
         keyCode = K_LBUTTONUP;
         break;

      case WM_RBUTTONUP:

         if( wvw_win->hPopup )
         {
            int nPopupRet;
            GetCursorPos( &xy );
            nPopupRet = ( int ) TrackPopupMenu( wvw_win->hPopup, TPM_CENTERALIGN + TPM_RETURNCMD, xy.x, xy.y, 0, hWnd, NULL );
            if( nPopupRet )
               hb_gt_wvw_AddCharToInputQueue( nPopupRet );
            return;
         }
         else
         {
            keyCode = K_RBUTTONUP;
            break;
         }

      case WM_MBUTTONDOWN:
         keyCode = K_MBUTTONDOWN;
         break;

      case WM_MBUTTONUP:
         keyCode = K_MBUTTONUP;
         break;

      case WM_MBUTTONDBLCLK:
         keyCode = K_MDBLCLK;
         break;

      case WM_MOUSEMOVE:
         keyState = ( SHORT ) wParam;

         if( keyState == MK_LBUTTON )
            keyCode = K_MMLEFTDOWN;
         else if( keyState == MK_RBUTTON )
            keyCode = K_MMRIGHTDOWN;
         else if( keyState == MK_MBUTTON )
            keyCode = K_MMMIDDLEDOWN;
         else
            keyCode = K_MOUSEMOVE;
         break;

      case WM_MOUSEWHEEL:
         keyState = HIWORD( wParam );

         if( keyState > 0 )
            keyCode = K_MWFORWARD;
         else
            keyCode = K_MWBACKWARD;

         break;

      case WM_NCMOUSEMOVE:
         keyCode = K_NCMOUSEMOVE;
         break;
   }

   if( wvw->a.pSymWVW_TBMOUSE && keyCode != 0 && hb_vmRequestReenter() )
   {
      hb_vmPushDynSym( wvw->a.pSymWVW_TBMOUSE );
      hb_vmPushNil();
      hb_vmPushInteger( wvw_win->nWinId );
      hb_vmPushInteger( keyCode );
      hb_vmPushInteger( colrow.y );
      hb_vmPushInteger( colrow.x );
      hb_vmPushInteger( keyState );
      hb_vmDo( 5 );

      hb_vmRequestRestore();
   }

   hb_gt_wvw_AddCharToInputQueue( keyCode );
}
예제 #20
0
파일: c_activex.c 프로젝트: migsoft/core
//------------------------------------------------------------------------------
// IEventHandler's Invoke()
// self is where the action happens
// self function receives events (by their ID number) and distributes the processing
// or them or ignores them
static ULONG STDMETHODCALLTYPE Invoke( IEventHandler *self, DISPID dispid, REFIID riid,
   LCID lcid, WORD wFlags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *pexcepinfo,
   UINT *puArgErr )
{
   PHB_ITEM pItem;
   int iArg, i;
   PHB_ITEM pItemArray[32]; // max 32 parameters?
   PHB_ITEM *pItems;
   ULONG ulRefMask = 0;
   ULONG ulPos;
   PHB_ITEM Key;

   Key = hb_itemNew( NULL );

   // We implement only a "default" interface
   if ( !IsEqualIID( riid, &IID_NULL ) )
      return( DISP_E_UNKNOWNINTERFACE );

   HB_SYMBOL_UNUSED(lcid);
   HB_SYMBOL_UNUSED(wFlags);
   HB_SYMBOL_UNUSED(result);
   HB_SYMBOL_UNUSED(pexcepinfo);
   HB_SYMBOL_UNUSED(puArgErr);

   // delegate work to somewhere else in PRG
   //***************************************

#ifdef __USEHASHEVENTS

   if ( hb_hashScan( ((MyRealIEventHandler* ) self)->pEvents, hb_itemPutNL( Key, dispid ),
      &ulPos ) )
   {
      PHB_ITEM pArray = hb_hashGetValueAt( ((MyRealIEventHandler* ) self)->pEvents, ulPos );

#else

   ulPos = hb_arrayScan( ((MyRealIEventHandler* ) self)->pEvents, hb_itemPutNL( Key, dispid ),
      NULL, NULL, 0
   #ifdef __XHARBOUR__
      , 0
   #endif
      );

   if ( ulPos )
   {
      PHB_ITEM pArray = hb_arrayGetItemPtr( ((MyRealIEventHandler* ) self)->pEventsExec, ulPos );

#endif

      PHB_ITEM pExec  = hb_arrayGetItemPtr( pArray, 01 );

      if ( pExec )
      {
         hb_vmRequestReenter();

         switch ( hb_itemType( pExec ) )
         {
            case HB_IT_BLOCK:
            {
               hb_vmPushSymbol( &hb_symEval );
               hb_vmPush( pExec );
               break;
            }
            case HB_IT_STRING:
            {
               PHB_ITEM pObject = hb_arrayGetItemPtr( pArray, 2 );
               hb_vmPushSymbol( hb_dynsymSymbol( hb_dynsymFindName( hb_itemGetCPtr( pExec ) ) ) );

               if ( HB_IS_OBJECT( pObject ) )
                  hb_vmPush( pObject );
               else
                  hb_vmPushNil();
               break;
            }
            case HB_IT_POINTER:
            {
               hb_vmPushSymbol( hb_dynsymSymbol( ( (PHB_SYMB) pExec ) -> pDynSym ) );
               hb_vmPushNil();
               break;
            }
         }

         iArg = params->cArgs;
         for( i = 1; i<= iArg; i++ )
         {
            pItem = hb_itemNew(NULL);
            hb_oleVariantToItem( pItem, &(params->rgvarg[iArg-i]) );
            pItemArray[i-1] = pItem;
            // set bit i
            ulRefMask |= ( 1L << (i-1) );
         }

         if( iArg )
         {
            pItems = pItemArray;
            hb_itemPushList( ulRefMask, iArg, &pItems );
         }

         // execute
         hb_vmDo( (USHORT) iArg );

         // En caso de que los parametros sean pasados por referencia
         for( i=iArg; i > 0; i-- )
         {
            if( ( (&(params->rgvarg[iArg-i]))->n1.n2.vt & VT_BYREF ) == VT_BYREF )
            {
               switch( (&(params->rgvarg[iArg-i]))->n1.n2.vt )
               {
                  //case VT_UI1|VT_BYREF:
                  //   *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pbVal) = va_arg(argList,unsigned char*);  //pItemArray[i-1]
                  //   break;
                  case VT_I2|VT_BYREF:
                     *((&(params->rgvarg[iArg-i]))->n1.n2.n3.piVal)    = (short)          hb_itemGetNI(pItemArray[i-1]);
                     break;
                  case VT_I4|VT_BYREF:
                     *((&(params->rgvarg[iArg-i]))->n1.n2.n3.plVal)    = (long)           hb_itemGetNL(pItemArray[i-1]);
                     break;
                  case VT_R4|VT_BYREF:
                     *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pfltVal)  = (float)          hb_itemGetND(pItemArray[i-1]);
                     break;
                  case VT_R8|VT_BYREF:
                     *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pdblVal)  = (double)         hb_itemGetND(pItemArray[i-1]);
                     break;
                  case VT_BOOL|VT_BYREF:
                     *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pboolVal) =  (VARIANT_BOOL)  ( hb_itemGetL( pItemArray[i-1] ) ? 0xFFFF : 0 );
                     break;
                  //case VT_ERROR|VT_BYREF:
                  //   *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pscode) = va_arg(argList, SCODE*);
                  //   break;
                  case VT_DATE|VT_BYREF:
                     *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pdate)    = (DATE) (double) (hb_itemGetDL(pItemArray[i-1])-2415019 );
                     break;
                  //case VT_CY|VT_BYREF:
                  //   *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pcyVal) = va_arg(argList, CY*);
                  //   break;
                  //case VT_BSTR|VT_BYREF:
                  //   *((&(params->rgvarg[iArg-i]))->n1.n2.n3.pbstrVal = va_arg(argList, BSTR*);
                  //   break;
                  //case VT_UNKNOWN|VT_BYREF:
                  //   pArg->ppunkVal = va_arg(argList, LPUNKNOWN*);
                  //   break;
                  //case VT_DISPATCH|VT_BYREF:
                  //   pArg->ppdispVal = va_arg(argList, LPDISPATCH*);
                  //   break;
               } // EOF switch( (&(params->rgvarg[iArg-i]))->n1.n2.vt )
            } // EOF if( (&(params->rgvarg[iArg-i]))->n1.n2.vt & VT_BYREF == VT_BYREF )
         } // EOF for( i=iArg; i > 0; i-- )

         hb_vmRequestRestore();
      } // EOF if ( pExec )
   }  // EOF If Scan

   hb_itemRelease( Key );

   return S_OK;
}  // EOF invoke

//------------------------------------------------------------------------------
// Here's IEventHandler's VTable. It never changes so we can declare it static
static const IEventHandlerVtbl IEventHandler_Vtbl = {
   QueryInterface,
   AddRef,
   Release,
   GetTypeInfoCount,
   GetTypeInfo,
   GetIDsOfNames,
   Invoke
};

//------------------------------------------------------------------------------
// constructor
// params:
// device_interface        - refers to the interface type of the COM object (whose event we are trying to receive).
// device_event_interface  - indicates the interface type of the outgoing interface supported by the COM object.
//                           This will be the interface that must be implemented by the Sink object.
//                           is essentially derived from IDispatch, our Sink object (self IEventHandler)
//                           is also derived from IDispatch.

typedef IEventHandler device_interface;

// Hash  // SetupConnectionPoint( oOle:hObj, @hSink, hEvents )             -> nError
// Array // SetupConnectionPoint( oOle:hObj, @hSink, aEvents, aExecEvent ) -> nError

HB_FUNC( SETUPCONNECTIONPOINT )
{
   IConnectionPointContainer*  pIConnectionPointContainerTemp = NULL;
   IUnknown*                   pIUnknown = NULL;
   IConnectionPoint*           m_pIConnectionPoint;
   IEnumConnectionPoints*      m_pIEnumConnectionPoints;
   HRESULT                     hr; //,r;
   IID                         rriid;
   register IEventHandler *    selfobj;
   DWORD                       dwCookie = 0;

   device_interface*           pdevice_interface = (device_interface*) HB_PARNL( 1 );
   MyRealIEventHandler*        pThis;

   // Allocate our IEventHandler object (actually a MyRealIEventHandler)
   // intentional misrepresentation of size

   selfobj = ( IEventHandler *) GlobalAlloc( GMEM_FIXED, sizeof( MyRealIEventHandler ) );

   if ( ! selfobj )
   {
      hr = E_OUTOFMEMORY;
   }
   else
   {
      // Store IEventHandler's VTable in the object
      selfobj->lpVtbl = (IEventHandlerVtbl *) &IEventHandler_Vtbl;

      // Increment the reference count so we can call Release() below and
      // it will deallocate only if there is an error with QueryInterface()
      ((MyRealIEventHandler *) selfobj)->count = 0;

      //((MyRealIEventHandler *) selfobj)->device_event_interface_iid = &riid;
      ((MyRealIEventHandler *) selfobj)->device_event_interface_iid = IID_IDispatch;

      // Query self object itself for its IUnknown pointer which will be used
      // later to connect to the Connection Point of the device_interface object.
      hr = selfobj->lpVtbl->QueryInterface( selfobj, &IID_IUnknown, (void**) (void *) &pIUnknown );
      if ( hr == S_OK && pIUnknown )
      {
         // Query the pdevice_interface for its connection point.
         hr = pdevice_interface->lpVtbl->QueryInterface( pdevice_interface,
            &IID_IConnectionPointContainer, (void**) (void *) &pIConnectionPointContainerTemp );

         if ( hr == S_OK && pIConnectionPointContainerTemp )
         {
            // start uncomment
            hr = pIConnectionPointContainerTemp->lpVtbl->EnumConnectionPoints( pIConnectionPointContainerTemp, &m_pIEnumConnectionPoints );

            if ( hr == S_OK && m_pIEnumConnectionPoints )
            {
               do
               {
                  hr = m_pIEnumConnectionPoints->lpVtbl->Next( m_pIEnumConnectionPoints, 1, &m_pIConnectionPoint , NULL);
                  if( hr == S_OK )
                  {
                     if ( m_pIConnectionPoint->lpVtbl->GetConnectionInterface( m_pIConnectionPoint, &rriid ) == S_OK )
                     {
                        break;
                     }
                  }

               } while( hr == S_OK );
               m_pIEnumConnectionPoints->lpVtbl->Release(m_pIEnumConnectionPoints);
            }
            // end uncomment

            //hr = pIConnectionPointContainerTemp ->lpVtbl->FindConnectionPoint(pIConnectionPointContainerTemp ,  &IID_IDispatch, &m_pIConnectionPoint);
            pIConnectionPointContainerTemp->lpVtbl->Release( pIConnectionPointContainerTemp );
            pIConnectionPointContainerTemp = NULL;
         }

         if ( hr == S_OK && m_pIConnectionPoint )
         {
            //OutputDebugString("getting iid");
            //Returns the IID of the outgoing interface managed by self connection point.
            //hr = m_pIConnectionPoint->lpVtbl->GetConnectionInterface(m_pIConnectionPoint, &rriid );
            //OutputDebugString("called");

            if( hr == S_OK )
            {
               ((MyRealIEventHandler *) selfobj)->device_event_interface_iid = rriid;
            }
            else
               OutputDebugString("error getting iid");

            //OutputDebugString("calling advise");
            hr = m_pIConnectionPoint->lpVtbl->Advise( m_pIConnectionPoint, pIUnknown, &dwCookie );
            ((MyRealIEventHandler *) selfobj)->pIConnectionPoint = m_pIConnectionPoint;
            ((MyRealIEventHandler *) selfobj)->dwEventCookie = dwCookie;
         }

         pIUnknown->lpVtbl->Release(pIUnknown);
         pIUnknown = NULL;
      }
   }

   if( selfobj )
   {
      pThis = (MyRealIEventHandler *) selfobj;

#ifndef __USEHASHEVENTS
      pThis->pEventsExec = hb_itemNew( hb_param( 4, HB_IT_ANY ) );
#endif

      pThis->pEvents = hb_itemNew( hb_param( 3, HB_IT_ANY ) );
      HB_STORNL2( (LONG_PTR) pThis, 2 );
   }

   HWNDret( hr );
}

//------------------------------------------------------------------------------
HB_FUNC( SHUTDOWNCONNECTIONPOINT )
{
   MyRealIEventHandler *self = ( MyRealIEventHandler * ) HB_PARNL( 1 );
   if( self->pIConnectionPoint )
   {
      self->pIConnectionPoint->lpVtbl->Unadvise( self->pIConnectionPoint, self->dwEventCookie );
      self->dwEventCookie = 0;
      self->pIConnectionPoint->lpVtbl->Release( self->pIConnectionPoint );
      self->pIConnectionPoint = NULL;
   }
}

//------------------------------------------------------------------------------
HB_FUNC( RELEASEDISPATCH )
{
   IDispatch * pObj;
   pObj = ( IDispatch * ) HWNDparam( 1 );
   pObj->lpVtbl->Release( pObj );
}
예제 #21
0
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, PVOID pvReserved )
#endif
{
   static HB_BOOL s_fInit = HB_FALSE;
   BOOL fResult = TRUE;

   HB_SYMBOL_UNUSED( pvReserved );

   switch( dwReason )
   {
      case DLL_PROCESS_ATTACH:
         s_hInstDll = ( HINSTANCE ) hInstance;
         s_lLockCount = s_lObjectCount = 0;
         s_IClassFactoryObj.lpVtbl = ( IClassFactoryVtbl * )
                                     &IClassFactory_Vtbl;

         DisableThreadLibraryCalls( ( HMODULE ) hInstance );

         s_fInit = ! hb_vmIsActive();
         if( s_fInit )
            hb_vmInit( HB_FALSE );

         hb_oleInit();

         if( ! s_fServerReady )
         {
            PHB_DYNS pDynSym = hb_dynsymFind( "DLLMAIN" );

            if( pDynSym && hb_dynsymIsFunction( pDynSym ) &&
                hb_vmRequestReenter() )
            {
               hb_vmPushDynSym( pDynSym );
               hb_vmPushNil();
               hb_vmProc( 0 );
               hb_vmRequestRestore();
            }
         }
         fResult = s_fServerReady ? TRUE : FALSE;
         break;

      case DLL_PROCESS_DETACH:
         s_fServerReady = HB_FALSE;
         if( s_pAction )
         {
            hb_itemRelease( s_pAction );
            s_pAction = NULL;
         }
         if( s_pMsgHash )
         {
            hb_itemRelease( s_pMsgHash );
            s_pMsgHash = NULL;
         }
         if( s_fInit )
         {
            hb_vmQuit();
            s_fInit = HB_FALSE;
         }
         break;
   }

   return fResult;
}
예제 #22
0
static INT_PTR CALLBACK hb_wvt_gtDlgProcModal( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
   PHB_GTWVT _s      = hb_wvt_gtGetWVT();
   INT_PTR   lReturn = 0;

   if( _s )
   {
      int      iIndex, iType;
      PHB_ITEM pFunc  = NULL;
      int      iFirst = ( int ) lParam;

      if( iFirst > 0 && iFirst <= ( int ) HB_SIZEOFARRAY( _s->hDlgModal ) )
      {
         _s->hDlgModal[ iFirst - 1 ] = hDlg;
         SendMessage( hDlg, WM_INITDIALOG, 0, 0 );
         return lReturn;
      }

      iType = 0;

      for( iIndex = 0; iIndex < ( int ) HB_SIZEOFARRAY( _s->hDlgModal ); iIndex++ )
      {
         if( _s->hDlgModal[ iIndex ] != NULL && _s->hDlgModal[ iIndex ] == hDlg )
         {
            if( _s->pFuncModal[ iIndex ] != NULL )
            {
               pFunc = _s->pFuncModal[ iIndex ];
               iType = _s->iTypeModal[ iIndex ];
            }
            break;
         }
      }

      if( pFunc )
      {
         switch( iType )
         {
            case 1: /* Function Name */
               if( hb_vmRequestReenter() )
               {
                  hb_vmPushDynSym( ( PHB_DYNS ) pFunc );
                  hb_vmPushNil();
                  hbwapi_vmPush_HANDLE( hDlg );
                  hb_vmPushNumInt( message );
                  hb_vmPushNumInt( wParam );
                  hb_vmPushNumInt( lParam );
                  hb_vmDo( 4 );
                  lReturn = ( INT_PTR ) hbwapi_par_RESULT( -1 );
                  hb_vmRequestRestore();
               }
               break;

            case 2: /* Block */
               /* eval the codeblock */
               if( HB_IS_EVALITEM( pFunc ) )
               {
                  if( hb_vmRequestReenter() )
                  {
                     hb_vmPushEvalSym();
                     hb_vmPush( pFunc );
                     hbwapi_vmPush_HANDLE( hDlg );
                     hb_vmPushNumInt( message );
                     hb_vmPushNumInt( wParam );
                     hb_vmPushNumInt( lParam );
                     hb_vmSend( 4 );
                     lReturn = ( INT_PTR ) hbwapi_par_RESULT( -1 );
                     hb_vmRequestRestore();
                  }
               }
               else
               {
                  /* TODO: internal error: missing codeblock */
               }
               break;
         }

         switch( message )
         {
            case WM_COMMAND:
               switch( LOWORD( wParam ) )
               {
                  case IDOK:
                     EndDialog( hDlg, IDOK );
                     lReturn = 0;
                     break;

                  case IDCANCEL:
                     EndDialog( hDlg, IDCANCEL );
                     lReturn = 0;
                     break;
               }
               break;

#if ! defined( HB_OS_WIN_CE )
            case WM_NCDESTROY:
#else
            case WM_DESTROY:
#endif
               if( _s->pFuncModal[ iIndex ] != NULL && _s->iTypeModal[ iIndex ] == 2 )
                  hb_itemRelease( ( PHB_ITEM ) _s->pFuncModal[ iIndex ] );
               _s->hDlgModal[ iIndex ]  = NULL;
               _s->pFuncModal[ iIndex ] = NULL;
               _s->iTypeModal[ iIndex ] = 0;
               lReturn = 0;
               break;
         }
      }
   }

   return lReturn;
}