static HB_BOOL s_fileTimeGet( PHB_FILE_FUNCS pFuncs, const char * pszFileName, long * plJulian, long * plMillisec ) { PHB_IOUSR pIO = ( PHB_IOUSR ) pFuncs; HB_BOOL fResult; int iOffset; iOffset = ( int ) ( hb_stackTopOffset() - hb_stackBaseOffset() ); hb_vmPushNil(); hb_vmPushNil(); s_pushMethod( pIO, IOUSR_TIMEGET ); hb_vmPushString( pszFileName, strlen( pszFileName ) ); hb_xvmPushLocalByRef( ( HB_SHORT ) iOffset ); hb_xvmPushLocalByRef( ( HB_SHORT ) ( iOffset + 1 ) ); hb_vmDo( 3 ); fResult = hb_parl( -1 ); if( fResult ) { *plJulian = hb_itemGetNL( hb_stackItemFromBase( iOffset ) ); *plMillisec = hb_itemGetNL( hb_stackItemFromBase( iOffset + 1 ) ); } hb_stackPop(); hb_stackPop(); return fResult; }
static PHB_FILE s_fileOpen( PHB_FILE_FUNCS pFuncs, const char * pszName, const char * pszDefExt, HB_USHORT uiExFlags, const char * pPaths, PHB_ITEM pError ) { PHB_IOUSR pIO = ( PHB_IOUSR ) pFuncs; PHB_FILE pFile = NULL; PHB_ITEM pFileItm; s_pushMethod( pIO, IOUSR_OPEN ); hb_vmPushString( pszName, strlen( pszName ) ); if( pszDefExt ) hb_vmPushString( pszDefExt, strlen( pszDefExt ) ); else hb_vmPushNil(); hb_vmPushInteger( uiExFlags ); if( pPaths ) hb_vmPushString( pPaths, strlen( pPaths ) ); else hb_vmPushNil(); if( pError ) hb_vmPush( pError ); else hb_vmPushNil(); hb_vmDo( 5 ); pFileItm = hb_stackReturnItem(); if( ! HB_IS_NIL( pFileItm ) ) pFile = s_fileNew( pIO, hb_itemNew( pFileItm ) ); return pFile; }
HB_BOOL hbamf_is_cls_externalizable( HB_USHORT uiClass ) { PHB_DYNS pSymbol = hb_dynsymGet( "__CLSMSGTYPE" ); HB_BOOL result = HB_FALSE; /* as far as i know, there is no exported Harbour C level api for this */ if( uiClass && pSymbol ) { PHB_ITEM pRetCopy = hb_itemNew( NULL ); hb_itemMove( pRetCopy, hb_stackReturnItem() ); hb_vmPushDynSym( pSymbol ); hb_vmPushNil(); hb_vmPushInteger( uiClass ); hb_vmPushString( "EXTERNALIZABLE", 14 ); hb_vmDo( 2 ); if( hb_itemGetNI( hb_stackReturnItem() ) == HB_OO_MSG_CLASSDATA ) result = HB_TRUE; hb_itemMove( hb_stackReturnItem(), pRetCopy ); hb_itemRelease( pRetCopy ); } return result; }
static void hb_hrbInitStatic( PHRB_BODY pHrbBody ) { if( ! pHrbBody->fInit && ! pHrbBody->fExit ) { HB_ULONG ul; pHrbBody->fInit = HB_TRUE; /* Initialize static variables first */ for( ul = 0; ul < pHrbBody->ulSymbols; ul++ ) /* Check _INITSTATICS functions */ { if( ( pHrbBody->pSymRead[ ul ].scope.value & HB_FS_INITEXIT ) == HB_FS_INITEXIT ) { /* call (_INITSTATICS) function. This function assigns * literal values to static variables only. There is no need * to pass any parameters to this function because they * cannot be used to initialize static variable. */ /* changed to call VM execution instead of direct function address call * pHrbBody->pSymRead[ ul ].value.pFunPtr(); * [MLombardo] */ hb_vmPushSymbol( &( pHrbBody->pSymRead[ ul ] ) ); hb_vmPushNil(); hb_vmProc( 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(); } } }
LRESULT CALLBACK ControlWindowProcedure( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { PHB_ITEM pBlock = ( PHB_ITEM ) GetProp( hwnd, TEXT( "BLOCKCALLBACK" ) ); long lRet; if( pBlock ) { if( hb_itemType( pBlock ) == HB_IT_POINTER ) { hb_vmPushSymbol( hb_dynsymSymbol( ( ( PHB_SYMB ) pBlock )->pDynSym ) ); hb_vmPushNil(); } else { hb_vmPushEvalSym(); hb_vmPush( pBlock ); } hb_vmPushNumInt( ( HB_PTRUINT ) hwnd ); hb_vmPushInteger( msg ); hb_vmPushNumInt( ( HB_PTRUINT ) wParam ); hb_vmPushNumInt( ( HB_PTRUINT ) lParam ); hb_vmDo( 4 ); lRet = ( long ) hb_parnint( -1 ); return lRet; } return DefWindowProc( hwnd, msg, wParam, lParam ); }
static void hb_hrbDo( PHRB_BODY pHrbBody, int iPCount, PHB_ITEM * pParams ) { PHB_ITEM pRetVal = NULL; int i; hb_hrbInit( pHrbBody, iPCount, pParams ); /* May not have a startup symbol, if first symbol was an INIT Symbol (was executed already). */ if( pHrbBody->lSymStart >= 0 && hb_vmRequestQuery() == 0 ) { hb_vmPushSymbol( &pHrbBody->pSymRead[ pHrbBody->lSymStart ] ); hb_vmPushNil(); for( i = 0; i < iPCount; i++ ) hb_vmPush( pParams[ i ] ); hb_vmProc( ( HB_USHORT ) iPCount ); pRetVal = hb_itemNew( NULL ); hb_itemMove( pRetVal, hb_stackReturnItem() ); } if( pRetVal ) hb_itemReturnRelease( pRetVal ); }
static PHB_ITEM hbamf_cls_externalizable_instance( PHB_ITEM pClassFuncStr ) { PHB_DYNS pSymbol = hb_dynsymGet( hb_itemGetCPtr( pClassFuncStr ) ); if( pSymbol ) { PHB_ITEM pRetCopy = hb_itemNew( NULL ); PHB_ITEM pNewItem = hb_itemNew( NULL ); hb_itemMove( pRetCopy, hb_stackReturnItem() ); hb_vmPushDynSym( pSymbol ); hb_vmPushNil(); hb_vmDo( 0 ); hb_objSendMsg( hb_stackReturnItem(), "NEW", 0 ); hb_itemMove( pNewItem, hb_stackReturnItem() ); hb_itemMove( hb_stackReturnItem(), pRetCopy ); hb_itemRelease( pRetCopy ); if( pNewItem ) { if( ! HB_IS_OBJECT( pNewItem ) ) { hb_itemRelease( pNewItem ); pNewItem = NULL; } } return pNewItem; } return NULL; }
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; }
HB_USHORT hbgi_hb_clsNew(const char *szClassName, int nDatas, PHB_ITEM pSuperArray) { if (!s_pDyns__CLSNEW) { hbgihb_init(NULL); } hb_vmPushDynSym(s_pDyns__CLSNEW); hb_vmPushNil(); hb_vmPushString(szClassName, strlen(szClassName)); hb_vmPushNumInt(nDatas); if (!pSuperArray) { hb_vmPushNil(); } else { hb_vmPush(pSuperArray); } hb_vmProc(3); return hb_itemGetNI(hb_stackReturnItem()); }
PHB_ITEM hb_evalLaunch( PHB_EVALINFO pEvalInfo ) { PHB_ITEM pResult = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_evalLaunch(%p)", pEvalInfo ) ); if( pEvalInfo ) { PHB_ITEM pItem = pEvalInfo->pItems[ 0 ]; 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 ) { HB_USHORT uiParam = 0; hb_vmPushSymbol( pSymbol ); if( pItem ) hb_vmPush( pItem ); else hb_vmPushNil(); while( uiParam < pEvalInfo->paramCount ) hb_vmPush( pEvalInfo->pItems[ ++uiParam ] ); if( pItem ) hb_vmSend( uiParam ); else hb_vmProc( uiParam ); pResult = hb_itemNew( hb_stackReturnItem() ); } } return pResult; }
static char * sz_callhrb_i( char * szName, int iParam1 ) { PHB_DYNS pSym_onEvent = hb_dynsymFindName( szName ); if( pSym_onEvent ) { hb_vmPushSymbol( hb_dynsymSymbol( pSym_onEvent ) ); hb_vmPushNil(); hb_vmPushInteger( iParam1 ); hb_vmDo( 1 ); return (char *) hb_parc(-1); } else return ""; }
static char * sz_callhrb_sz( char * szName, char * szParam1 ) { PHB_DYNS pSym_onEvent = hb_dynsymFindName( szName ); if( pSym_onEvent ) { hb_vmPushSymbol( hb_dynsymSymbol( pSym_onEvent ) ); hb_vmPushNil(); hb_vmPushString( szParam1, strlen( szParam1 ) ); hb_vmDo( 1 ); return (char *) hb_parc(-1); } else return ""; }
/* * Call specific driver function to load any configuration needed... * 14/12/2008 - 20:05:26 */ static void SQLSYS_LOADINFO( const char *DriverName, SQLSYS_INFO *pStruct ) { PHB_DYNS pDynSym = hb_dynsymFind( DriverName ); if ( pDynSym && hb_dynsymIsFunction( pDynSym ) ) { HB_TRACE(HB_TR_DEBUG,(" SQLSYS_LOADINFO( '%s', %p ) ... (LOADing)", DriverName, pStruct )); hb_vmPushDynSym( pDynSym ); hb_vmPushNil(); hb_vmPushPointer( ( void * ) pStruct ); hb_vmDo( 1 ); } else { HB_TRACE(HB_TR_DEBUG,(" SQLSYS_LOADINFO( '%s', %p ) ... ERROR: DRIVER NOT FOUND!!! ###", DriverName, pStruct )); memset( pStruct, '\0', sizeof( SQLSYS_INFO ) ); } }
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(); } } }
PHB_ITEM hb_evalLaunch( PHB_EVALINFO pEvalInfo ) { HB_THREAD_STUB PHB_ITEM pResult = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_evalLaunch(%p)", pEvalInfo ) ); if( pEvalInfo ) { register USHORT uiParam = 1; if( HB_IS_STRING( pEvalInfo->pItems[ 0 ] ) ) { const char * ptr = pEvalInfo->pItems[ 0 ]->item.asString.value; hb_vmPushSymbol( hb_dynsymFindName( ptr )->pSymbol ); hb_vmPushNil(); while( uiParam <= pEvalInfo->paramCount ) hb_vmPush( pEvalInfo->pItems[ uiParam++ ] ); hb_vmDo( pEvalInfo->paramCount ); pResult = hb_itemNew( NULL ); hb_itemForwardValue( pResult, &( HB_VM_STACK.Return ) ); } else if( HB_IS_BLOCK( pEvalInfo->pItems[ 0 ] ) ) { hb_vmPushSymbol( &hb_symEval ); hb_vmPush( pEvalInfo->pItems[ 0 ] ); while( uiParam <= pEvalInfo->paramCount ) hb_vmPush( pEvalInfo->pItems[ uiParam++ ] ); hb_vmSend( pEvalInfo->paramCount ); pResult = hb_itemNew( NULL ); hb_itemForwardValue( pResult, &( HB_VM_STACK.Return ) ); } } return pResult; }
static void hb_pp_StdRules( PHB_ITEM ppItem ) { static HB_BOOL s_fInit = HB_TRUE; static PHB_DYNS s_pDynSym; if( s_fInit ) { s_pDynSym = hb_dynsymFind( "__PP_STDRULES" ); s_fInit = HB_FALSE; } if( s_pDynSym ) { hb_vmPushDynSym( s_pDynSym ); hb_vmPushNil(); hb_vmPush( ppItem ); hb_vmProc( 1 ); } }
/* NOTE: Same as hb_itemDo(), but even simpler, since the function name can be directly passed as a zero terminated string. [vszakats] */ PHB_ITEM hb_itemDoC( const char * szFunc, HB_SIZE ulPCount, ... ) { HB_THREAD_STUB PHB_ITEM pResult = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_itemDoC(%s, %hu, ...)", szFunc, ulPCount ) ); if( szFunc ) { PHB_DYNS pDynSym; pDynSym = hb_dynsymFindName( szFunc ); if( pDynSym ) { hb_vmPushState(); hb_vmPushSymbol( pDynSym->pSymbol ); hb_vmPushNil(); if( ulPCount ) { register 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_vmDo( ( USHORT ) ulPCount ); pResult = hb_itemNew( NULL ); hb_itemForwardValue( pResult, &( HB_VM_STACK.Return ) ); hb_vmPopState(); } } return pResult; }
static HB_BOOL s_fileAttrGet( PHB_FILE_FUNCS pFuncs, const char * pszFileName, HB_FATTR * pnAttr ) { PHB_IOUSR pIO = ( PHB_IOUSR ) pFuncs; HB_BOOL fResult; int iOffset; iOffset = ( int ) ( hb_stackTopOffset() - hb_stackBaseOffset() ); hb_vmPushNil(); s_pushMethod( pIO, IOUSR_ATTRGET ); hb_vmPushString( pszFileName, strlen( pszFileName ) ); hb_xvmPushLocalByRef( ( HB_SHORT ) iOffset ); hb_vmDo( 2 ); fResult = hb_parl( -1 ); if( fResult ) *pnAttr = ( HB_FATTR ) hb_itemGetNL( hb_stackItemFromBase( iOffset ) ); hb_stackPop(); return fResult; }
static void hbgi_hb_clsAddMsgNative(HB_USHORT uiClass, const char *szMessage, HB_USHORT uiType, HB_USHORT uiScope, PHB_ITEM pFuncOrOffset, PHB_ITEM pInit) { PHB_ITEM pInitCopy; HB_BOOL allocated = !pInit; pInitCopy = allocated ? hb_itemNew(NULL) : pInit; if (!s_pDyns__CLSADDMSG) { hbgihb_init(NULL); } hb_vmPushDynSym(s_pDyns__CLSADDMSG); hb_vmPushNil(); hb_vmPushNumInt(uiClass); hb_vmPushString(szMessage, strlen(szMessage)); hb_vmPush(pFuncOrOffset); hb_vmPushNumInt(uiType); hb_vmPush(pInitCopy); hb_vmPushNumInt(uiScope); hb_vmProc(6); if (allocated) { hb_itemRelease(pInitCopy); } }
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 ); }
/* NOTE: Same as hb_itemDoC(), but has additional second parameter which set the reference mask for 1-st 32/64 parametes [druzus] */ PHB_ITEM hb_itemDoCRef( char * szFunc, HB_SIZE ulRefMask, HB_SIZE ulPCount, ... ) { HB_THREAD_STUB PHB_ITEM pResult = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_itemDoCRef(%s, %hu, %hu, ...)", szFunc, ulRefMask, ulPCount ) ); if( szFunc ) { PHB_DYNS pDynSym; pDynSym = hb_dynsymFindName( szFunc ); if( pDynSym ) { hb_vmPushState(); hb_vmPushSymbol( pDynSym->pSymbol ); hb_vmPushNil(); if( ulPCount ) { PHB_ITEM pItemRefBuf[ sizeof( HB_SIZE ) * 8 ]; HB_ITEM itmRef; register HB_SIZE ulParam; HB_SIZE ulRef = 0; va_list va; PHB_ITEM * pRefBase; PHB_ITEM pParam; pRefBase = pItemRefBuf; /* initialize the reference item */ itmRef.type = HB_IT_BYREF; itmRef.item.asRefer.offset = -1; itmRef.item.asRefer.BasePtr.itemsbasePtr = &pRefBase; va_start( va, ulPCount ); for( ulParam = 0; ulParam < ulPCount; ulParam++ ) { pParam = va_arg( va, PHB_ITEM ); if( ulRefMask & ( 1L << ulParam ) ) { /* when item is passed by reference then we have to put * the reference on the stack instead of the item itself */ pItemRefBuf[ ulRef++ ] = pParam; itmRef.item.asRefer.value = ( LONG ) ulRef; /* hb_vmPush( &itmRef ); */ pParam = &itmRef; } hb_vmPush( pParam ); } va_end( va ); } hb_vmDo( ( USHORT ) ulPCount ); pResult = hb_itemNew( NULL ); hb_itemForwardValue( pResult, &( HB_VM_STACK.Return ) ); hb_vmPopState(); } } return pResult; }
BOOL hb_execFromArray( PHB_ITEM pFirst ) { register ULONG i; HB_SIZE ulLen; ULONG ulStart = 1; PHB_ITEM pArgs; PHB_ITEM pString; PHB_ITEM pSelf = NULL; PHB_DYNS pExecSym = NULL; PHB_SYMB pSymbol = NULL; if( pFirst == NULL || pFirst->type != HB_IT_ARRAY ) return FALSE; pString = hb_arrayGetItemPtr( pFirst, 1 ); pArgs = pFirst; if( HB_IS_OBJECT( pString ) && hb_arrayLen( pFirst ) >= 2 ) { pSelf = pString; pString = hb_arrayGetItemPtr( pFirst, 2 ); if( pString->type == HB_IT_STRING ) pExecSym = hb_dynsymFindName( pString->item.asString.value ); else if( pString->type == HB_IT_POINTER ) pSymbol = ( PHB_SYMB ) hb_itemGetPtr( pString ); ulStart = 3; } else if( pString->type == HB_IT_STRING ) { pExecSym = hb_dynsymFindName( pString->item.asString.value ); ulStart = 2; } else if( pString->type == HB_IT_POINTER ) { pSymbol = ( PHB_SYMB ) hb_itemGetPtr( pString ); ulStart = 2; } else if( HB_IS_BLOCK( pString ) ) { pSymbol = &hb_symEval; ulStart = 2; } if( pExecSym ) pSymbol = pExecSym->pSymbol; if( pSymbol == NULL ) return FALSE; hb_vmPushSymbol( pSymbol ); if( pSelf ) hb_vmPush( pSelf ); else hb_vmPushNil(); ulLen = hb_arrayLen( pArgs ); /* pushing the contents of the array */ for( i = ulStart; i <= ulLen; i++ ) hb_vmPush( hb_arrayGetItemPtr( pArgs, i ) ); if( pSelf ) hb_vmSend( ( USHORT ) ( ulLen - ulStart + 1 ) ); else hb_vmDo( ( USHORT ) ( ulLen - ulStart + 1 ) ); return TRUE; }
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; }
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; }
static void s_pushMethod( PHB_IOUSR pIO, int iMethod ) { hb_vmPushSymbol( pIO->prg_funcs[ iMethod - 1 ] ); hb_vmPushNil(); }
//------------------------------------------------------------------------------ // 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 ); }
PHB_ITEM hb_itemDo( PHB_ITEM pItem, HB_SIZE ulPCount, ... ) { HB_THREAD_STUB PHB_ITEM pResult = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_itemDo(%p, %hu, ...)", 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; } else if( HB_IS_POINTER( pItem ) ) pSymbol = ( PHB_SYMB ) pItem->item.asPointer.value; else if( HB_IS_SYMBOL( pItem ) ) pSymbol = pItem->item.asSymbol.value; if( pSymbol ) { hb_vmPushState(); hb_vmPushSymbol( pSymbol ); hb_vmPushNil(); if( ulPCount ) { register 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_vmDo( ( USHORT ) ulPCount ); pResult = hb_itemNew( NULL ); hb_itemForwardValue( pResult, &( HB_VM_STACK.Return ) ); hb_vmPopState(); } else if( HB_IS_BLOCK( pItem ) ) { hb_vmPushState(); hb_vmPushSymbol( &hb_symEval ); hb_vmPush( pItem ); if( ulPCount ) { register 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_vmSend( ( USHORT ) ulPCount ); pResult = hb_itemNew( NULL ); hb_itemForwardValue( pResult, &( HB_VM_STACK.Return ) ); hb_vmPopState(); } else if( HB_IS_ARRAY( pItem ) ) { hb_vmPushState(); if( hb_execFromArray( pItem ) ) { pResult = hb_itemNew( NULL ); hb_itemForwardValue( pResult, &( HB_VM_STACK.Return ) ); } hb_vmPopState(); } } return pResult; }
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; }
HB_BOOL hb_execFromArray( PHB_ITEM pParam ) { PHB_ITEM pArray = NULL; PHB_ITEM pSelf = NULL; HB_ULONG ulParamOffset = 0; if( pParam && HB_IS_ARRAY( pParam ) && ! HB_IS_OBJECT( pParam ) ) { pArray = pParam; pParam = hb_arrayGetItemPtr( pArray, 1 ); if( HB_IS_OBJECT( pParam ) ) { pSelf = pParam; pParam = hb_arrayGetItemPtr( pArray, 2 ); ulParamOffset = 2; } else ulParamOffset = 1; } if( pParam ) { PHB_SYMB pExecSym = NULL; if( HB_IS_SYMBOL( pParam ) ) pExecSym = hb_itemGetSymbol( pParam ); else if( HB_IS_STRING( pParam ) ) pExecSym = hb_dynsymGet( hb_itemGetCPtr( pParam ) )->pSymbol; else if( HB_IS_BLOCK( pParam ) && ! pSelf ) { pSelf = pParam; pExecSym = &hb_symEval; } if( pExecSym ) { int iPCount = 0; hb_vmPushSymbol( pExecSym ); if( pSelf ) hb_vmPush( pSelf ); else hb_vmPushNil(); if( pArray ) { pParam = hb_arrayGetItemPtr( pArray, ++ulParamOffset ); while( pParam && iPCount < 255 ) { hb_vmPush( pParam ); ++iPCount; pParam = hb_arrayGetItemPtr( pArray, ++ulParamOffset ); } } if( pSelf ) hb_vmSend( ( HB_USHORT ) iPCount ); else hb_vmProc( ( HB_USHORT ) iPCount ); return HB_TRUE; } } hb_errRT_BASE_SubstR( EG_ARG, 1099, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); return HB_FALSE; }