Eval method

The Eval method determines if a target matches the criteria that a provided SDEL statement describes.

Syntax

HRESULT Eval(
  [in]           BSTR SDEL,
  [out, retval]  VARIANT_BOOL *pResult
);

Parameters

  • SDEL [in]
    The SDEL statement that the target will be matched against.

  • pResult [out, retval]
    The address of a variable that will receive VARIANT_TRUE if the SDEL statement matches this target and VARIANT_FALSE otherwise.

Return value

Eval returns a standard HRESULT value.

Remarks

For more information about using the Eval method, see Creating WDTF Scenarios.

The following code example demonstrates how to use the Eval method.

VBScript

WScript.Echo "Starting Disable Enable Test for CDROM(s) - " & vbcrlf

'
' Disable/Enable CD-ROM drives
'
For Each CDROM In CDROMs

    On Error Resume Next

    DisplayName = CDROM.GetValue("#DisplayName")
 
    WScript.Echo Space(2) & DisplayName
 
    '
    '  Check if the CD-ROM device is Disableable
    '
    If ( CDROM.Eval("IsDisableable=false") ) Then
        WScript.Echo Space(4) & "Specified device is not Disableable. Skipping Disable/Enable test for this device"
    Else
        '
        ' Get Disable-Enable Action Interface for the Target
        '
        Set Action = CDROM.GetInterface("DeviceManagement")
 
        If Err.number <> 0 Then
            WScript.Echo Space(4) & "Failed to get interface DeviceManagement. Error Number:" & Err.number
        Else 
            '
            ' Disable CD-ROM
            '
            WScript.Echo Space(4) & "Trying to disable device..."
 
            Action.Disable()
 
            If Err.number <> 0 Then
                WScript.Echo Space(4) & "Failed to disable the specified CDROM. Error Number:" & Err.number & vbcrlf
            Else
                 WScript.Echo Space(4) & "Specified CDROM successfully disabled." & vbcrlf
            End If
 
            '
            ' Enable CD-ROM
            '
            WScript.Echo Space(4) & "Trying to enable device..."
 
            Action.Disable()
 
            If Err.number <> 0 Then
                WScript.Echo Space(4) & "Failed to enable the specified CDROM. Error Number:" & Err.number & vbcrlf
            Else
                 WScript.Echo Space(4) & "Specified CDROM successfully enabled." & vbcrlf
            End If
        End If
 
        If Action Is Not Null Then
            Set Action = Nothing
        End If
    End If
Next

C++

_tprintf(_T("\nStarting Disable Enable Test for CDROM(s) -"));

//
// For all of the CD-ROM devices (that is, Target objects) found, invoke Disable/Enable action
//
for(int i=1; i<=nCDROMs; i++)
{
    hr = pCDROMs->get_Item(i, &pCDROM);

 if(FAILED(hr))
    {
        _tprintf(_T("\nFailed to get Item # %d from CDROM Device collection. Error: 0x%x"), i, hr);
 goto Cleanup;
    }
 
    wprintf(L"\n");

 //
 // Get device '#DisplayName'
 //
    VariantInit(&vtDesc);

    hr = pCDROM->GetValue(L"#DisplayName", &vtDesc);
 if(FAILED(hr))
    {
        _tprintf(_T("\nFailed to get FriendlyName OR Description from device. Error: 0x%x"), hr);
 goto Cleanup;
    }

    wprintf(L"\n%s", vtDesc.bstrVal);
 
 //
 // Check whether the CD-ROM device 'is Disableable'
 //
    VARIANT_BOOL vtbIsDisableble;          // Indicates whether the device is 'Disableable' or not

    hr = pCDROM->Eval(L"IsDisableable=true", &vtbIsDisableble);
 if(FAILED(hr))
    {
        _tprintf(_T("\nFailed to find whether the device 'is disableable' or not. Error: 0x%x"), hr);
 continue;
    }
 
 if(!vtbIsDisableble)
    {
        _tprintf(_T("\nSpecified device is not Disableable. Skipping Disable/Enable test for this device"));
 continue;
    }
 
    IDevMan* pDevMan;    // IDevMan Action interface

    VARIANT vtEmpty;   // To be passed as a parameter to ITarget::GetInterface
    VariantInit(&vtEmpty);

 //
 // Get IDevMan Action interface
 //
    hr = pCDROM->GetInterface(L"DeviceManagement", vtEmpty, vtEmpty, (IAction**)(&pDevMan));
 if(FAILED(hr))
    {
        _tprintf(_T("\n  Failed to get DeviceManagement Interface for specified CDROM Device. Error: 0x%x"), hr);
 goto Cleanup;
    }

 //
 // Disable CD-ROM
 //
    _tprintf(_T("\n  Trying to disable device..."));

    hr = pDevMan->Disable();
 if(FAILED(hr))
    {
        _tprintf(_T("\n  Failed to disable the specified CDROM. Error: 0x%x"), hr);
    }
 else
    {
        _tprintf(_T("\n  Specified CDROM successfully disabled."));
    }

    _tprintf(_T("\n"));

 //
 // Enable CD-ROM
 //
    _tprintf(_T("\n  Trying to enable device..."));

    hr = pDevMan->Enable();
 if(FAILED(hr))
    {
        _tprintf(_T("\n  Failed to enable the specified CDROM. Error: 0x%x"), hr);
    }
 else
    {
        _tprintf(_T("\n  Specified CDROM successfully enabled."));
    }
 
 //
 // Release reference
 //
 if(pDevMan)
    {
        pDevMan->Release();
    }
}

See also

ITarget

 

 

Send comments about this topic to Microsoft

Build date: 1/12/2012