IWDFRemoteTarget::OpenFileByName method

The OpenFileByName method opens a remote I/O target that is a file.

Syntax


HRESULT OpenFileByName(
  [in]           PCWSTR                      pszFileName,
  [in]           DWORD                       DesiredAccess,
  [in, optional] PUMDF_IO_TARGET_OPEN_PARAMS pOpenParams
);

Parameters

pszFileName [in]

A pointer to a caller-supplied, null-terminated string that represents the name of the file to open. For more information about this member, see the FileName parameter of CreateFile in the Windows SDK.

DesiredAccess [in]

A bitmask that specifies the caller's desired access to the file. For more information about this member, see the dwDesiredAccess parameter of CreateFile in the Windows SDK.

pOpenParams [in, optional]

A pointer to a caller-allocated UMDF_IO_TARGET_OPEN_PARAMS structure that contains additional parameters. This parameter is optional and can be NULL.

Return value

OpenFileByName returns S_OK if the operation succeeds. Otherwise, the method might return the following value:

Return codeDescription
E_OUTOFMEMORY

The framework's attempt to allocate memory failed.

 

This method might return one of the other values that Winerror.h contains.

The framework's verifier reports an error if the framework cannot open the file.

Remarks

Your driver can use OpenFileByName to open a file, if the driver stack to which your driver belongs does not support the file's device. Use IWDFFileHandleTargetFactory::CreateFileHandleTarget to open a file, if the driver stack to which your driver belongs does support the file's device.

The specified file must be accessible by the account that loaded the UMDF-based driver, which is typically the Local Service account. However, if the driver uses impersonation when it calls OpenFileByName, the file must be accessible by the impersonated account.

Do not call OpenFileByName to open a remote target to a control device object. Instead, open the control device directly by calling CreateFile.

For more information about the OpenFileByName method and remote I/O targets, see General I/O Targets in UMDF.

Examples

The following code example creates a remote target object and opens an existing file with read-only access.


UMDF_IO_TARGET_OPEN_PARAMS openParams;
HRESULT hr;

//
// Create a new remote target object and provide a callback 
// object to handle remote target events.
//
CComPtr<IWDFRemoteTarget> fxTarget;
hr = FxDevice->CreateRemoteTarget(MyRemoteTargetIUnknown,
                                  fxRemoteInterface,
                                  &fxTarget);
if (FAILED(hr)) goto Error;

//
// Open existing file for read-only access.
//
openParams.dwShareMode = 0;
openParams.dwCreationDisposition = OPEN_EXISTING;
openParams.dwFlagsAndAttributes = FILE_ATTRIBUTE_READONLY;

hr = fxTarget->OpenFileByName(FILE_PATH,
                              GENERIC_READ,
                              &openParams);
 

Requirements

Target platform

End of support

Unavailable in UMDF 2.0 and later.

Minimum UMDF version

1.9

Header

Wudfddi.h (include Wudfddi.h)

DLL

WUDFx.dll

See also

IWDFRemoteTarget
IWDFDevice2::CreateRemoteTarget
IWDFRemoteTarget::OpenRemoteInterface

 

 

Send comments about this topic to Microsoft

Show: