次の方法で共有


ILogicalSensorManager::Connect method

[ILogicalSensorManager::Connect is no longer available for use as of Windows 8.]

Connects to a logical sensor.

Syntax

HRESULT Connect(
  [in] REFGUID        logicalID,
  [in] IPropertyStore *pPropertyStore
);

Parameters

  • logicalID [in]
    REFGUID that identifies the logical sensor instance.

  • pPropertyStore [in]
    Pointer to the IPropertyStore interface used to transfer data to the driver instance.

    The property store can contain one or more of the following values.

    Value Meaning
    PKEY_Device_HardwareIds

    (VT_VECTOR|VT_LPWSTR) Required. One or more hardware IDs for the driver to be loaded for the logical device instance. The device hardware ID is defined in the driver's INF file.

    PKEY_Device_CompatibleIds

    (VT_VECTOR|VTLPWSTR) Optional. An array of compatible hardware IDs.

     

Return value

The method returns an HRESULT. Possible values include, but are not limited to, those in the following table.

Return code Description
S_OK

The method succeeded.

E_ACCESS_DENIED

No permission. Connecting a logical sensor requires administrator privileges. If you receive this error while debugging, restart the development environment as administrator.

HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)

The specified logical sensor is already connected.

 

Remarks

This method installs the specified logical sensor, if needed. If the logical sensor device node already exists, this method simply creates a connection to make the logical sensor available to the Sensor and Location Platform.

Examples

The following example code creates a helper method that connects to a specified logical sensor. The method parameters receive the sensor hardware ID and a unique GUID to identify the sensor.

HRESULT ConnectToLogicalSensor(PCWSTR* wszHardwareID, GUID guidLogicalID)
{
    HRESULT hr = S_OK;
    
    ILogicalSensorManager* pLSM = NULL;
    IPropertyStore* pStore = NULL;
    PROPVARIANT pv = {};

    // Create the property store.
    hr = PSCreateMemoryPropertyStore(IID_PPV_ARGS(&pStore));

    if(SUCCEEDED(hr))
    {
        // Create the logical sensor manager.
        hr = CoCreateInstance(CLSID_LogicalSensorManager, 
                                NULL, 
                                CLSCTX_INPROC_SERVER, 
                                IID_PPV_ARGS(&pLSM));
    }

    // Fill in the values.
    if(SUCCEEDED(hr))
    {
        hr = InitPropVariantFromStringVector(wszHardwareID, 1, &pv);
    }

    if(SUCCEEDED(hr))
    {
        hr = pStore->SetValue(PKEY_Device_HardwareIds, pv);
    }

    if(SUCCEEDED(hr))
    {
        hr = pStore->SetValue(PKEY_Device_CompatibleIds, pv);
    }

    if(SUCCEEDED(hr))
    {
        // Connect to the logical sensor.
        hr = pLSM->Connect(guidLogicalID, pStore);
    }

    SafeRelease(&pStore);
    SafeRelease(&pLSM);

    return hr;
}

Requirements

Minimum supported client

Windows 7 [desktop apps only]

Minimum supported server

None supported

End of client support

Windows 7

Header

Sensorsapi.h

Library

Sensorsapi.lib

DLL

Sensorsapi.dll

See also

About Logical Sensors

ILogicalSensorManager

Using Logical Sensors