static PMIXKEY mixKeyNew( PHB_ITEM pItem, HB_ULONG ulRecNo, HB_BYTE bType, HB_USHORT uiLen ) { PMIXKEY pKey; double dbl; HB_BYTE buf[ 8 ]; pKey = ( PMIXKEY ) hb_xgrab( sizeof( HB_ULONG ) + uiLen ); pKey->rec = ulRecNo; switch( bType ) { case 'C': { HB_SIZE ul = hb_itemGetCLen( pItem ); if( ul > ( HB_SIZE ) uiLen ) ul = uiLen; memcpy( pKey->val, hb_itemGetCPtr( pItem ), ul ); if( ul < ( HB_SIZE ) uiLen ) memset( pKey->val + ul, ' ', ( HB_SIZE ) uiLen - ul ); break; } case 'N': dbl = hb_itemGetND( pItem ); HB_DBL2ORD( &dbl, buf ); memcpy( pKey->val, buf, 8 ); break; case 'D': dbl = ( double ) hb_itemGetDL( pItem ); HB_DBL2ORD( &dbl, buf ); memcpy( pKey->val, buf, 8 ); break; case 'L': pKey->val[ 0 ] = ( HB_BYTE ) ( hb_itemGetL( pItem ) ? 'T' : 'F' ); break; default: memset( pKey->val, ' ', uiLen ); } return pKey; }
//------------------------------------------------------------------------------ // 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 ); }
BOOL sql_item2str( sql_item_arg *pItemArg, SQLSYS_INFO *pSysInfo ) { ULONG lSize = 0L; /* For Temporary values */ char *szText = NULL; /* Temporary buffer */ BOOL bFree = TRUE; if (!pItemArg) { HB_TRACE(HB_TR_DEBUG,(" Invalid Argument -> %p", pItemArg )); return FALSE; } if (!pSysInfo) { pSysInfo = (SQLSYS_INFO *) SQLSYS_GETINFO( 0 ); // Valid driver? It has been correctly loaded into memory? if (!SR_ISVALID_DRIVER(pSysInfo)) { HB_TRACE(HB_TR_DEBUG,(" Invalid driver !!" )); return FALSE; } } HB_TRACE(HB_TR_DEBUG,(" ARGUMENT => '%s'", hb_itemTypeStr( pItemArg->pItem ) )); switch( hb_itemType( pItemArg->pItem ) ) { case HB_IT_MEMO: case HB_IT_STRING: { HB_TRACE(HB_TR_DEBUG,(" As Text => '%s'", hb_itemGetCPtr( pItemArg->pItem ) )); lSize = hb_itemGetCLen( pItemArg->pItem ); szText = (*pSysInfo->EscapeString) ( hb_itemGetCPtr( pItemArg->pItem ), &lSize, 0 ); /* char *szTemp, *szBuff; szTemp = (*pSysInfo->EscapeString) ( hb_itemGetCPtr( pItemArg->pItem ), &lSize, 0 ); if (szTemp) { szText = (char *) hb_xgrab( lSize + 3L ); // chr(0) + 2 separators szBuff = szText; *szText = pSysInfo->FieldDelim; szText ++; memcpy( szText, szTemp, lSize ); szText += lSize; *szText = pSysInfo->FieldDelim; szText ++; *szText = '\0'; hb_xfree( szTemp ); } /***/ break; } case HB_IT_LOGICAL: HB_TRACE(HB_TR_DEBUG,(" As BOOL => %d", (int) hb_itemGetL( pItemArg->pItem ) )); szText = (hb_itemGetL( pItemArg->pItem ) ? pSysInfo->BoolTrue : pSysInfo->BoolFalse); lSize = strlen( szText ); bFree = FALSE; break; case HB_IT_DATE: { int iYear, iMonth, iDay; hb_dateDecode( hb_itemGetDL( pItemArg->pItem ), &iYear, &iMonth, &iDay ); HB_TRACE(HB_TR_DEBUG,(" As DATE => %04d/%02d/%02d", iYear, iMonth, iDay )); if (pSysInfo->DateFormat == ESCAPE_FORMAT_DATE_ISO) { szText = SQLSYS_DATETOISO( (char *) hb_xgrab(13), iYear, iMonth, iDay, TRUE ); lSize = 12L; } break; } case HB_IT_INTEGER: case HB_IT_DOUBLE: case HB_IT_LONG: { szText = hb_itemStr( pItemArg->pItem, NULL, NULL ); HB_TRACE(HB_TR_DEBUG,(" As Number => %s", szText )); if( szText ) { ULONG nToSkip = 0L; while( szText[ nToSkip] == ' ' ) ++nToSkip; /* Rever isto aqui de perto */ if( nToSkip ) memmove( szText, szText + nToSkip, strlen( szText + nToSkip ) + 1 ); lSize = strlen( szText ); HB_TRACE(HB_TR_DEBUG,(" As Text => '%s' -- %lu", szText, lSize )); } break; } default: { szText = (char *) hb_xgrab(5); *szText = '\0'; strcat( szText, "NULL" ); lSize = strlen( szText ); break; } } if (!szText) { HB_TRACE(HB_TR_DEBUG,(" Impossivel converter este valor:" )); HB_TRACE_ARGS( pItemArg->pItem ); return FALSE; } pItemArg->szResult = szText; pItemArg->ulSize = lSize; pItemArg->bDestroy = bFree; return TRUE; }