newntui/activex/Impact/src/ImpactCtl.cpp
//---------------------------------------------------------------------------
// Executes Access command and returns a result:
//   If a result starts with 'Error:' - it means some error has occurred and 
//              rest of the strind is the error description
//   Otherwise its the command result
//---------------------------------------------------------------------------
Executes Access command and returns a result:
If a result starts with 'Error:' - it means some error has occurred and
rest of the strind is the error description
Otherwise its the command result
Executes Access command and returns a result : If a result starts with ' Error : ' - it means some error has occurred and rest of the strind is the error description Otherwise its the command result
CString CImpactCtrl::ExecCommand(CString &command)
{
    CString MethodName("AccessSync"); 
    DISPID accessID;                  
    HRESULT hresult;
	if(m_DataSource==NULL) return m_cszError + CString(" No data source - can't evaluate a command");
    BSTR methodBSTR=MethodName.AllocSysString();
    hresult = m_DataSource->GetIDsOfNames(IID_NULL,&methodBSTR, 
                                              1,LOCALE_SYSTEM_DEFAULT,&accessID);
    if(hresult!=S_OK) return m_cszError + CString(" data source does not support AccessSync method");
	::SysFreeString(methodBSTR);
    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;
	::SysFreeString(access_call);
    CString szResult;
    if(hresult!=S_OK) szResult = m_cszError + " Command '" + command + "' failed.\n";
    szResult += resBSTR.bstrVal;
    return szResult;
}
CString CImpactCtrl :: ExecCommand ( CString & command ) { CString MethodName ( " " ) ; DISPID accessID ; HRESULT hresult ; if ( m_DataSource == NULL ) return m_cszError + CString ( " " ) ; BSTR methodBSTR = MethodName . AllocSysString ( ) ; hresult = m_DataSource -> GetIDsOfNames ( IID_NULL , & methodBSTR , 1 , LOCALE_SYSTEM_DEFAULT , & accessID ) ; if ( hresult != S_OK ) return m_cszError + CString ( " " ) ; :: SysFreeString ( methodBSTR ) ; 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 ; :: SysFreeString ( access_call ) ; CString szResult ; if ( hresult != S_OK ) szResult = m_cszError + " " + command + " \n " ; szResult += resBSTR . bstrVal ; return szResult ; }
Executes Access command and returns a result:
If a result starts with 'Error:' - it means some error has occurred and
rest of the strind is the error description
Otherwise its the command result
Executes Access command and returns a result : If a result starts with ' Error : ' - it means some error has occurred and rest of the strind is the error description Otherwise its the command result
// 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