static HB_BOOL hb_gt_gui_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) { HB_TRACE( HB_TR_DEBUG, ( "hb_gt_gui_Info(%p,%d,%p)", pGT, iType, pInfo ) ); switch( iType ) { #if defined( HB_OS_WIN ) case HB_GTI_CLIPBOARDDATA: if( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING ) #if defined( UNICODE ) hb_gt_winapi_setClipboard( CF_UNICODETEXT, pInfo->pNewVal ); #else hb_gt_winapi_setClipboard( CF_TEXT, pInfo->pNewVal ); #endif else { if( pInfo->pResult == NULL ) pInfo->pResult = hb_itemNew( NULL ); #if defined( UNICODE ) hb_gt_winapi_getClipboard( CF_UNICODETEXT, pInfo->pResult ); #else hb_gt_winapi_getClipboard( CF_TEXT, pInfo->pResult ); #endif } break; case HB_GTI_KBDSHIFTS: pInfo->pResult = hb_itemPutNI( pInfo->pResult, hb_gt_winapi_getKbdState() ); if( hb_itemType( pInfo->pNewVal ) & HB_IT_NUMERIC ) hb_gt_winapi_setKbdState( hb_itemGetNI( pInfo->pNewVal ) ); break; #endif default: return HB_GTSUPER_INFO( pGT, iType, pInfo ); }
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 ); }
/* * Retrieve information about the current table/driver. */ static HB_ERRCODE hb_delimInfo( DELIMAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) { HB_TRACE(HB_TR_DEBUG, ("hb_delimInfo(%p,%hu,%p)", pArea, uiIndex, pItem)); switch( uiIndex ) { case DBI_CANPUTREC: hb_itemPutL( pItem, pArea->fTransRec ); break; case DBI_GETRECSIZE: hb_itemPutNL( pItem, pArea->uiRecordLen ); break; case DBI_GETDELIMITER: { char szDelim[ 2 ]; szDelim[ 0 ] = pArea->cDelim; szDelim[ 1 ] = '\0'; hb_itemPutC( pItem, szDelim ); break; } case DBI_SETDELIMITER: if( hb_itemType( pItem ) & HB_IT_STRING ) { char * szDelim = hb_itemGetCPtr( pItem ); if( hb_stricmp( szDelim, "BLANK" ) == 0 ) { pArea->cDelim = '\0'; pArea->cSeparator = ' '; } #ifndef HB_C52_STRICT else if( hb_stricmp( szDelim, "PIPE" ) == 0 ) { pArea->cDelim = '\0'; pArea->cSeparator = '|'; } else if( hb_stricmp( szDelim, "TAB" ) == 0 ) { pArea->cDelim = '\0'; pArea->cSeparator = '\t'; } else #else else if( *szDelim ) #endif { pArea->cDelim = *szDelim; } } /* * a small trick which allow to set character field delimiter and * field separator in COPY TO ... and APPEND FROM ... commands as * array. F.e.: * COPY TO test DELIMITED WITH ({"","|"}) */ #ifndef HB_C52_STRICT else if( hb_itemType( pItem ) & HB_IT_ARRAY )
static HB_ERRCODE sqlbaseRddInfo( LPRDDNODE pRDD, HB_USHORT uiIndex, HB_ULONG ulConnect, PHB_ITEM pItem ) { HB_ULONG ulConn; SQLDDCONNECTION * pConn; HB_SYMBOL_UNUSED( pRDD ); ulConn = ulConnect ? ulConnect : s_ulConnectionCurrent; if( ulConn > 0 && ulConn <= s_ulConnectionCount ) pConn = s_pConnection[ ulConn - 1 ]; else pConn = NULL; switch( uiIndex ) { case RDDI_REMOTE: hb_itemPutL( pItem, HB_TRUE ); break; case RDDI_CONNECTION: { HB_ULONG ulNewConnection = 0; if( hb_itemType( pItem ) & HB_IT_NUMERIC ) ulNewConnection = hb_itemGetNL( pItem ); hb_itemPutNL( pItem, ulConnect ? ulConnect : s_ulConnectionCurrent ); if( ulNewConnection ) s_ulConnectionCurrent = ulNewConnection; break; } case RDDI_ISDBF: hb_itemPutL( pItem, HB_FALSE ); break; case RDDI_CANPUTREC: hb_itemPutL( pItem, HB_TRUE ); break; case RDDI_CONNECT: { PSDDNODE pNode = NULL; HB_ULONG ul; const char * pStr; pStr = hb_arrayGetCPtr( pItem, 1 ); if( pStr ) { pNode = s_pSdd; while( pNode ) { if( ! hb_stricmp( pNode->Name, pStr ) ) break; pNode = pNode->pNext; } } hb_rddsqlSetError( 0, NULL, NULL, NULL, 0 ); pConn = ( SQLDDCONNECTION * ) hb_xgrab( sizeof( SQLDDCONNECTION ) ); memset( pConn, 0, sizeof( SQLDDCONNECTION ) ); if( pNode && pNode->Connect( pConn, pItem ) == HB_SUCCESS ) { pConn->pSDD = pNode; /* Find free connection handle */ for( ul = 0; ul < s_ulConnectionCount; ul++ ) { if( ! s_pConnection[ ul ] ) break; } if( ul >= s_ulConnectionCount ) { /* Realloc connection table */ if( s_pConnection ) s_pConnection = ( SQLDDCONNECTION ** ) hb_xrealloc( s_pConnection, sizeof( SQLDDCONNECTION * ) * ( s_ulConnectionCount + CONNECTION_LIST_EXPAND ) ); else s_pConnection = ( SQLDDCONNECTION ** ) hb_xgrab( sizeof( SQLDDCONNECTION * ) * CONNECTION_LIST_EXPAND ); memset( s_pConnection + s_ulConnectionCount, 0, sizeof( SQLDDCONNECTION * ) * CONNECTION_LIST_EXPAND ); ul = s_ulConnectionCount; s_ulConnectionCount += CONNECTION_LIST_EXPAND; } s_pConnection[ ul ] = pConn; ul++; s_ulConnectionCurrent = ul; } else { hb_xfree( pConn ); ul = 0; } hb_itemPutNI( pItem, ul ); break; } case RDDI_DISCONNECT: hb_rddsqlSetError( 0, NULL, NULL, NULL, 0 ); if( pConn && ! pConn->uiAreaCount && pConn->pSDD->Disconnect( pConn ) == HB_SUCCESS ) { hb_xfree( pConn ); s_pConnection[ ulConn - 1 ] = NULL; if( s_ulConnectionCurrent == ulConn ) s_ulConnectionCurrent = 0; hb_itemPutL( pItem, HB_TRUE ); return HB_SUCCESS; } hb_itemPutL( pItem, HB_FALSE ); return HB_SUCCESS; case RDDI_EXECUTE: hb_rddsqlSetError( 0, NULL, NULL, NULL, 0 ); if( pConn ) hb_itemPutL( pItem, pConn->pSDD->Execute( pConn, pItem ) == HB_SUCCESS ); else hb_itemPutL( pItem, HB_FALSE ); return HB_SUCCESS; case RDDI_ERROR: hb_itemPutC( pItem, s_szError ); return HB_SUCCESS; case RDDI_ERRORNO: hb_itemPutNI( pItem, s_errCode ); return HB_SUCCESS; case RDDI_QUERY: hb_itemPutC( pItem, s_szQuery ); return HB_SUCCESS; case RDDI_NEWID: hb_itemCopy( pItem, s_pItemNewID ); return HB_SUCCESS; case RDDI_AFFECTEDROWS: hb_itemPutNInt( pItem, s_ulAffectedRows ); return HB_SUCCESS; #if 0 default: return SUPER_RDDINFO( pRDD, uiIndex, ulConnect, pItem ); #endif } return HB_SUCCESS; }
/* Export field value into the buffer in PG accepted CSV format */ static HB_BOOL exportBufSqlVar( pgCopyContext * context, PHB_ITEM pValue, const char * szQuote, const char * szEsc ) { switch( hb_itemType( pValue ) ) { case HB_IT_STRING: case HB_IT_MEMO: { HB_SIZE nLen = hb_itemGetCLen( pValue ); HB_SIZE nCnt = 0; const char * szVal = hb_itemGetCPtr( pValue ); if( ! addStrToContext( context, szQuote ) ) return HB_FALSE; if( context->str_trim ) { while( nLen && HB_ISSPACE( szVal[ nLen - 1 ] ) ) nLen--; } while( *szVal && nCnt++ < nLen ) { /* if( *szVal == *szDelim || *szVal == *szEsc || *szVal == *szQuote ) we don't need to escape delim in CSV mode, only the quote and the escape itself */ if( *szVal == *szQuote || *szVal == *szEsc ) if( ! addToContext( context, *szEsc ) ) return HB_FALSE; if( ( HB_UCHAR ) *szVal >= 32 ) if( ! addToContext( context, *szVal ) ) return HB_FALSE; szVal++; } if( ! addStrToContext( context, szQuote ) ) return HB_FALSE; break; } case HB_IT_DATE: { char szDate[ 9 ]; if( ! addStrToContext( context, szQuote ) ) return HB_FALSE; hb_itemGetDS( pValue, szDate ); if( szDate[ 0 ] == ' ' ) { if( ! addStrToContext( context, "0100-01-01" ) ) return HB_FALSE; } else { if( ! addStrnToContext( context, &szDate[ 0 ], 4 ) || ! addToContext( context, '-' ) || ! addStrnToContext( context, &szDate[ 4 ], 2 ) || ! addToContext( context, '-' ) || ! addStrnToContext( context, &szDate[ 6 ], 2 ) ) return HB_FALSE; } if( ! addStrToContext( context, szQuote ) ) return HB_FALSE; break; } case HB_IT_TIMESTAMP: { long lDate, lTime; char szDateTime[ 24 ]; hb_itemGetTDT( pValue, &lDate, &lTime ); hb_timeStampStr( szDateTime, lDate, lTime ); if( ! addStrToContext( context, szQuote ) || ! addStrToContext( context, szDateTime ) || ! addStrToContext( context, szQuote ) ) return HB_FALSE; break; } case HB_IT_LOGICAL: #if 0 if( ! addStrToContext( context, szQuote ) || ! addToContext( context, hb_itemGetL( pValue ) ? 'Y' : 'N' ) || ! addStrToContext( context, szQuote ) ) #endif if( ! addToContext( context, hb_itemGetL( pValue ) ? 'Y' : 'N' ) ) return HB_FALSE; break; case HB_IT_INTEGER: case HB_IT_LONG: case HB_IT_DOUBLE: { char szResult[ HB_MAX_DOUBLE_LENGTH ]; int iSize, iWidth, iDec; hb_itemGetNLen( pValue, &iWidth, &iDec ); iSize = ( iDec > 0 ? iWidth + 1 + iDec : iWidth ); if( hb_itemStrBuf( szResult, pValue, iSize, iDec ) ) { int iPos = 0; while( iSize && HB_ISSPACE( szResult[ iPos ] ) ) { iPos++; iSize--; } if( ! addStrnToContext( context, &szResult[ iPos ], iSize ) ) return HB_FALSE; } else if( ! addToContext( context, '0' ) ) return HB_FALSE; break; } /* an "M" field or the other, might be a "V" in SixDriver */ default: return HB_FALSE; } return HB_TRUE; }
HB_ERRCODE hb_dbTransStruct( AREAP lpaSource, AREAP lpaDest, LPDBTRANSINFO lpdbTransInfo, PHB_ITEM * pStruct, PHB_ITEM pFields ) { HB_USHORT uiFields, uiSize, uiCount, uiPosSrc, uiPosDst, uiSizeSrc, uiSizeDst; HB_ERRCODE errCode; const char * szField; HB_BOOL fAll; errCode = SELF_FIELDCOUNT( lpaSource, &uiSizeSrc ); if( errCode != HB_SUCCESS ) return errCode; if( lpaDest ) { errCode = SELF_FIELDCOUNT( lpaDest, &uiSizeDst ); if( errCode != HB_SUCCESS ) return errCode; uiSize = HB_MIN( uiSizeDst, uiSizeSrc ); } else { uiSize = uiSizeDst = uiSizeSrc; } if( ! uiSize ) return HB_FAILURE; if( hb_itemType( pFields ) & HB_IT_ARRAY ) { uiFields = ( HB_USHORT ) hb_arrayLen( pFields ); if( uiFields ) uiSize = uiFields; } else uiFields = 0; fAll = ( uiSizeDst == uiSizeSrc ); lpdbTransInfo->lpaSource = lpaSource; lpdbTransInfo->lpaDest = lpaDest; lpdbTransInfo->lpTransItems = ( LPDBTRANSITEM ) hb_xgrab( uiSize * sizeof( DBTRANSITEM ) ); if( ! lpaDest ) { *pStruct = hb_itemNew( NULL ); hb_arrayNew( *pStruct, 0 ); } if( uiFields == 0 ) { if( lpaDest ) { PHB_ITEM pItem = hb_itemNew( NULL ); uiSize = 0; for( uiCount = 1; uiCount <= uiSizeSrc; ++uiCount ) { if( SELF_FIELDINFO( lpaSource, uiCount, DBS_NAME, pItem ) != HB_SUCCESS ) { uiSize = 0; break; } szField = hb_itemGetCPtr( pItem ); uiPosDst = hb_rddFieldExpIndex( lpaDest, szField ); if( uiPosDst != uiCount ) fAll = HB_FALSE; if( uiPosDst ) { HB_USHORT ui; /* check for replicated field names in source area */ for( ui = 0; ui < uiSize; ++ui ) { if( lpdbTransInfo->lpTransItems[ ui ].uiDest == uiPosDst ) break; } if( ui == uiSize ) { lpdbTransInfo->lpTransItems[ uiSize ].uiSource = uiCount; lpdbTransInfo->lpTransItems[ uiSize++ ].uiDest = uiPosDst; } } } hb_itemRelease( pItem ); } else { hb_tblStructure( lpaSource, *pStruct, 0 ); uiSize = ( HB_USHORT ) hb_arrayLen( *pStruct ); for( uiCount = 0; uiCount < uiSize; ++uiCount ) { lpdbTransInfo->lpTransItems[ uiCount ].uiSource = lpdbTransInfo->lpTransItems[ uiCount ].uiDest = uiCount + 1; } } } else { uiSize = 0; for( uiCount = 1; uiCount <= uiFields; ++uiCount ) { szField = hb_dbTransFieldPos( pFields, uiCount ); if( szField ) { uiPosSrc = hb_rddFieldExpIndex( lpaSource, szField ); if( ! uiPosSrc ) continue; if( lpaDest ) uiPosDst = hb_rddFieldExpIndex( lpaDest, szField ); else uiPosDst = uiSize + 1; if( uiPosDst ) { if( uiPosSrc != uiPosDst ) fAll = HB_FALSE; lpdbTransInfo->lpTransItems[ uiSize ].uiSource = uiPosSrc; lpdbTransInfo->lpTransItems[ uiSize++ ].uiDest = uiPosDst; if( ! lpaDest ) { hb_arraySize( *pStruct, uiSize ); hb_fldStructure( lpaSource, uiPosSrc, 0, hb_arrayGetItemPtr( *pStruct, uiSize ) ); } } } } } if( uiSize != uiSizeSrc ) fAll = HB_FALSE; if( fAll && lpaDest ) { PHB_ITEM pSrcItm = hb_itemNew( NULL ), pDstItm = hb_itemNew( NULL ); /* * if fAll is HB_TRUE here then it means that all fields are included * and they are on the same positions in both tables, so now check * if their types and sizes are also equal */ for( uiCount = 1; uiCount <= uiSize; ++uiCount ) { if( SELF_FIELDINFO( lpaSource, uiCount, DBS_TYPE, pSrcItm ) != HB_SUCCESS || SELF_FIELDINFO( lpaDest, uiCount, DBS_TYPE, pDstItm ) != HB_SUCCESS ) { uiSize = 0; break; } if( hb_stricmp( hb_itemGetCPtr( pSrcItm ), hb_itemGetCPtr( pDstItm ) ) != 0 ) { fAll = HB_FALSE; break; } if( SELF_FIELDINFO( lpaSource, uiCount, DBS_LEN, pSrcItm ) != HB_SUCCESS || SELF_FIELDINFO( lpaDest, uiCount, DBS_LEN, pDstItm ) != HB_SUCCESS ) { uiSize = 0; break; } if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) ) { fAll = HB_FALSE; break; } if( SELF_FIELDINFO( lpaSource, uiCount, DBS_DEC, pSrcItm ) != HB_SUCCESS || SELF_FIELDINFO( lpaDest, uiCount, DBS_DEC, pDstItm ) != HB_SUCCESS ) { uiSize = 0; break; } if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) ) { fAll = HB_FALSE; break; } #ifdef DBS_FLAG if( SELF_FIELDINFO( lpaSource, uiCount, DBS_FLAG, pSrcItm ) != HB_SUCCESS || SELF_FIELDINFO( lpaDest, uiCount, DBS_FLAG, pDstItm ) != HB_SUCCESS ) { uiSize = 0; break; } if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) ) { fAll = HB_FALSE; break; } #endif } hb_itemRelease( pSrcItm ); hb_itemRelease( pDstItm ); } lpdbTransInfo->uiFlags = fAll ? DBTF_MATCH : 0; lpdbTransInfo->uiItemCount = uiSize; return uiSize ? HB_SUCCESS : HB_FAILURE; }
//------------------------------------------------------------------------------ // 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 ); }
/* Export field value into the buffer in SQL format */ static HB_BOOL hb_exportBufSqlVar( PHB_FILEBUF pFileBuf, PHB_ITEM pValue, const char * szDelim, const char * szEsc ) { switch( hb_itemType( pValue ) ) { case HB_IT_STRING: { HB_SIZE nLen = hb_itemGetCLen( pValue ); HB_SIZE nCnt = 0; const char *szVal = hb_itemGetCPtr( pValue ); hb_addStrToFBuffer( pFileBuf, szDelim ); while( nLen && HB_ISSPACE( szVal[ nLen - 1 ] ) ) nLen--; while( *szVal && nCnt++ < nLen ) { if( *szVal == *szDelim || *szVal == *szEsc ) hb_addToFBuffer( pFileBuf, *szEsc ); if( ( HB_UCHAR ) *szVal >= 32 ) hb_addToFBuffer( pFileBuf, *szVal ); else { /* printf( "%d %c", *szVal, *szVal ); */ } szVal++; } hb_addStrToFBuffer( pFileBuf, szDelim ); break; } case HB_IT_DATE: { char szDate[ 9 ]; hb_addStrToFBuffer( pFileBuf, szDelim ); hb_itemGetDS( pValue, szDate ); if( szDate[ 0 ] == ' ' ) { hb_addStrToFBuffer( pFileBuf, "0100-01-01" ); } else { hb_addStrnToFBuffer( pFileBuf, &szDate[0], 4 ); hb_addToFBuffer( pFileBuf, '-' ); hb_addStrnToFBuffer( pFileBuf, &szDate[4], 2 ); hb_addToFBuffer( pFileBuf, '-' ); hb_addStrnToFBuffer( pFileBuf, &szDate[6], 2 ); } hb_addStrToFBuffer( pFileBuf, szDelim ); break; } case HB_IT_TIMESTAMP: { long lDate, lTime; char szDateTime[ 24 ]; hb_itemGetTDT( pValue, &lDate, &lTime ); hb_timeStampStr( szDateTime, lDate, lTime ); hb_addStrToFBuffer( pFileBuf, szDelim ); hb_addStrToFBuffer( pFileBuf, szDateTime ); hb_addStrToFBuffer( pFileBuf, szDelim ); break; } case HB_IT_LOGICAL: hb_addStrToFBuffer( pFileBuf, szDelim ); hb_addToFBuffer( pFileBuf, hb_itemGetL( pValue ) ? 'Y' : 'N' ); hb_addStrToFBuffer( pFileBuf, szDelim ); break; case HB_IT_INTEGER: case HB_IT_LONG: case HB_IT_DOUBLE: { char szResult[ HB_MAX_DOUBLE_LENGTH ]; int iSize, iWidth, iDec; hb_itemGetNLen( pValue, &iWidth, &iDec ); iSize = ( iDec > 0 ? iWidth + 1 + iDec : iWidth ); if( hb_itemStrBuf( szResult, pValue, iSize, iDec ) ) { int iPos = 0; while( iSize && HB_ISSPACE( szResult[ iPos ] ) ) { iPos++; iSize--; } hb_addStrnToFBuffer( pFileBuf, &szResult[ iPos ], iSize ); } else hb_addToFBuffer( pFileBuf, '0' ); break; } /* an "M" field or the other, might be a "V" in SixDriver */ default: /* We do not want MEMO contents */ return HB_FALSE; } return HB_TRUE; }
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; }