Dela via


IVsRunningDocumentTable.FindAndLockDocument Method

Locates a document in the RDT using the document file name, then obtains a read or edit lock on that document.

Namespace:  Microsoft.VisualStudio.Shell.Interop
Assembly:  Microsoft.VisualStudio.Shell.Interop (in Microsoft.VisualStudio.Shell.Interop.dll)

Syntax

'Declaration
Function FindAndLockDocument ( _
    dwRDTLockType As UInteger, _
    pszMkDocument As String, _
    <OutAttribute> ByRef ppHier As IVsHierarchy, _
    <OutAttribute> ByRef pitemid As UInteger, _
    <OutAttribute> ByRef ppunkDocData As IntPtr, _
    <OutAttribute> ByRef pdwCookie As UInteger _
) As Integer
int FindAndLockDocument(
    uint dwRDTLockType,
    string pszMkDocument,
    out IVsHierarchy ppHier,
    out uint pitemid,
    out IntPtr ppunkDocData,
    out uint pdwCookie
)
int FindAndLockDocument(
    [InAttribute] unsigned int dwRDTLockType, 
    [InAttribute] String^ pszMkDocument, 
    [OutAttribute] IVsHierarchy^% ppHier, 
    [OutAttribute] unsigned int% pitemid, 
    [OutAttribute] IntPtr% ppunkDocData, 
    [OutAttribute] unsigned int% pdwCookie
)
abstract FindAndLockDocument : 
        dwRDTLockType:uint32 * 
        pszMkDocument:string * 
        ppHier:IVsHierarchy byref * 
        pitemid:uint32 byref * 
        ppunkDocData:IntPtr byref * 
        pdwCookie:uint32 byref -> int
function FindAndLockDocument(
    dwRDTLockType : uint, 
    pszMkDocument : String, 
    ppHier : IVsHierarchy, 
    pitemid : uint, 
    ppunkDocData : IntPtr, 
    pdwCookie : uint
) : int

Parameters

  • dwRDTLockType
    Type: UInt32

    [in] Flags whose values are taken from the _VSRDTFLAGS enumeration.

  • pszMkDocument
    Type: String

    [in] Path to the located document.

  • ppunkDocData
    Type: IntPtr%

    [out, optional] Returns the IUnknown interface. See Remarks for details.

  • pdwCookie
    Type: UInt32%

    [out, optional] Returns an abstract value for the document.

Return Value

Type: Int32
If the method succeeds, it returns S_OK. If it fails, it returns an error code.

Remarks

FindAndLockDocumentEx is similar to this method but also allows the specification of a preferred hierarchy/itemid pair for the document in case an RDT_EditLock is desired and the document is currently registered with only a RDT_ReadLock with no hierarchy/itemid assigned.

In order to avoid a memory leak, you should call Release on the ppunkDocData object returned by this method.

COM Signature

From vsshell.idl:

HRESULT IVsRunningDocumentTable::FindAndLockDocument(
   [in] VSRDTFLAGS      dwRDTLockType,
   [in] LPCOLESTR       pszMkDocument,
   [out] IVsHierarchy **ppHier,
   [out] VSITEMID      *pitemid,
   [out] IUnknown     **ppunkDocData,
   [out] VSCOOKIE      *pdwCookie
);

punkDocData Parameter

If the document is registered, then the punkDocData value that is returned is always non-null because the environment will create a punkDocData on behalf of Editors that registered with a nulla null reference (Nothing in Visual Basic) value for punkDocData, as is the case when an Editor does not have data/view separation. This object represents the document data object associated with the registered document. Typically, the IVsPersistDocData and IVsDocDataFileChangeControl interfaces are obtained from this IUnknown object.

pdwCookie Parameter

The pdwCookie parameter returns a cookie representing the document. This cookie can be passed to the following methods:

.NET Framework Security

See Also

Reference

IVsRunningDocumentTable Interface

Microsoft.VisualStudio.Shell.Interop Namespace