newntui/activex/queriescombo/src/queriescomboctl.cpp
//-----------------------------------------------------------------------------------------
// This function will syncronously evaluate script stored in the string "command" on the
// server or mini-server. It will use DataSource IDispatch interface to run AccessSync
// command.
// Returns EVAL_OK if the command was evaluated successfully or :
//     ERROR_DATA_SOURCE    if we were trying to evaluate the command without IDispatch 
//                          interface
//     ERROR_ACCESS_SUPPORT if the interface doesn't support AccessSync method
//     ERROR_ACCESS_COMMAND if the wrong command was passed to evaluate     
//-----------------------------------------------------------------------------------------
This function will syncronously evaluate script stored in the string "command" on the
server or mini-server. It will use DataSource IDispatch interface to run AccessSync
command.
Returns EVAL_OK if the command was evaluated successfully or :
ERROR_DATA_SOURCE    if we were trying to evaluate the command without IDispatch
interface
ERROR_ACCESS_SUPPORT if the interface doesn't support AccessSync method
ERROR_ACCESS_COMMAND if the wrong command was passed to evaluate
This function will syncronously evaluate script stored in the string " command " on the server or mini - server . It will use DataSource IDispatch interface to run AccessSync command . Returns EVAL_OK if the command was evaluated successfully or : ERROR_DATA_SOURCE if we were trying to evaluate the command without IDispatch interface ERROR_ACCESS_SUPPORT if the interface doesn ' t support AccessSync method ERROR_ACCESS_COMMAND if the wrong command was passed to evaluate
int CQueriesComboCtrl::EvaluateSync(CString& command, CString* results) {
CString MethodName("AccessSync"); 
DISPID accessID;                  
HRESULT hresult;
    if(m_DataSource==NULL) return ERROR_DATA_SOURCE;
	if(results == NULL) command+=";set tmp 1";
	BSTR methodBSTR=MethodName.AllocSysString();
    hresult = m_DataSource->GetIDsOfNames(IID_NULL,&methodBSTR, 
		                                  1,LOCALE_SYSTEM_DEFAULT,&accessID);
	if(hresult!=S_OK) return ERROR_ACCESS_SUPPORT;
	BSTR access_call = command.AllocSysString();
    DISPPARAMS cmdParamStruct;
	cmdParamStruct.rgvarg              = new VARIANT;
	cmdParamStruct.rgvarg[0].vt        = VT_BSTR | VT_BYREF; 
	cmdParamStruct.rgvarg[0].pbstrVal  = &access_call;
	cmdParamStruct.cArgs               = 1;
	cmdParamStruct.cNamedArgs=0;
	VARIANT resBSTR;
	unsigned int argWithError;
	hresult = m_DataSource->Invoke(accessID,
		                           IID_NULL,
								   LOCALE_SYSTEM_DEFAULT,
								   DISPATCH_METHOD,
								   &cmdParamStruct,
								   &resBSTR,
								   NULL,
								   &argWithError);
	delete cmdParamStruct.rgvarg;
	if(hresult!=S_OK) return ERROR_ACCESS_COMMAND;
	if(results!=NULL) *results=resBSTR.bstrVal;
	return EVAL_OK;
}
int CQueriesComboCtrl :: EvaluateSync ( CString & command , CString * results ) { CString MethodName ( " " ) ; DISPID accessID ; HRESULT hresult ; if ( m_DataSource == NULL ) return ERROR_DATA_SOURCE ; if ( results == NULL ) command += " " ; BSTR methodBSTR = MethodName . AllocSysString ( ) ; hresult = m_DataSource -> GetIDsOfNames ( IID_NULL , & methodBSTR , 1 , LOCALE_SYSTEM_DEFAULT , & accessID ) ; if ( hresult != S_OK ) return ERROR_ACCESS_SUPPORT ; BSTR access_call = command . AllocSysString ( ) ; DISPPARAMS cmdParamStruct ; cmdParamStruct . rgvarg = new VARIANT ; cmdParamStruct . rgvarg [ 0 ] . vt = VT_BSTR | VT_BYREF ; cmdParamStruct . rgvarg [ 0 ] . pbstrVal = & access_call ; cmdParamStruct . cArgs = 1 ; cmdParamStruct . cNamedArgs = 0 ; VARIANT resBSTR ; unsigned int argWithError ; hresult = m_DataSource -> Invoke ( accessID , IID_NULL , LOCALE_SYSTEM_DEFAULT , DISPATCH_METHOD , & cmdParamStruct , & resBSTR , NULL , & argWithError ) ; delete cmdParamStruct . rgvarg ; if ( hresult != S_OK ) return ERROR_ACCESS_COMMAND ; if ( results != NULL ) * results = resBSTR . bstrVal ; return EVAL_OK ; }
This function will syncronously evaluate script stored in the string "command" on the
server or mini-server.
This function will syncronously evaluate script stored in the string " command " on the server or mini - server .
// We will run AccessSync method of the DataSource // IDispatch id for the AccessSync command // if there is no data source assigned to this control, we will be unable to // evaluate this function. // Trying to receve method ID from it's name. // Interface doesn't support AccessSync method // Converting command into new OEM string wich will be passed into OLE automation. // We will free when pushing into the stack // Creating parameter structure - only one parameter will be passed as argument - command string // we will pass it as BSTR reference // Results will be inserted into VARIANT union // This will show the argument with an error // Remote command execution