\n
Microsoft Invisible Computing

INameSpace Interface

The INameSpace interface provides methods for manipulating namespaces and the run-time library provides a function and flags for accessing the system namespace.

C type for interface pointer:

Extends IUnknown

Extended by INameRanges

Implemented by CNameSpace CNameRanges FatName RomName HostName NtName TmpFs

See also CurrentNameSpace BindToObject

Methods: Register Unregister Bind FindNext GetCapabilities

Constants: NAME_SPACE_FLAGS

Methods

Register

Adds the specified name and its associated object to the namespace.

Unregister

Removes a registered {name, object} pair from the namespace.

Bind

Translates a name into an object reference. This method either creates or references the object associated with the specified name and returns a pointer to that object.

FindNext

Returns the next name that appears in the namespace or subnamespace.

GetCapabilities

Reports the capabilities supported by an object registered under the specified name. These capabilities are those defined by the INameSpace.Register method and have no meaning for the namespace itself.

Constants

NAME_SPACE_FLAGS

Bit values for Flags arguments in INameSpace methods.

INameSpace.Register Method

Adds the specified name and its associated object to the namespace.

SCODE Register( 
    /*in,this*/ PINAMESPACE iThis,
    /*in*/ const _TCHAR * pName,
    /*in*/ PIUNKNOWN pObj,
    /*in*/ NAME_SPACE_FLAGS Flags,
    /*in,optional*/ PINAMESPACE pServerNameSpace)
pName

Points to a null-terminated string that contains the name to be associated with an object.

pObj

A pointer to the object associated with the pName string.

Flags

Each bit is a flag that the caller sets to one to select the processing option represented by the flag. Multiple flags may be set to select multiple options simultaneously.

pServerNameSpace

This parameter is not used in the current implementation and should be NULL.

Example Register

UINT TestRefs = 0;

/* MyObject implements only IUnknown. */
struct MyObject: IUnknown {
    SCODE MCT QueryInterface(REFIID riid, void **ppvObject);
    UINT MCT AddRef(void);
    UINT MCT Release(void);
};

SCODE MCT MyObject::QueryInterface(REFIID riid, void **ppvObject)
{
    if (UuidCmp(IID_IUnknown, riid)) {
        this->AddRef();
        *ppvObject = this;
        return S_OK;
    } else {
        *ppvObject = NULL;
        return E_NO_INTERFACE;
    }
}

UINT MCT MyObject::AddRef(void)
{
    UINT Refs = AtomicInc(&TestRefs);
    _tprintf(_TEXT("refs=%d (after inc in AddRef)\n"), Refs);
    return Refs;
}

UINT MCT MyObject::Release(void)
{
    UINT Refs = AtomicDec(&TestRefs);
    _tprintf(_TEXT("refs=%d (after dec in Release)\n"), Refs);
    return Refs;
}

int _tmain()
{
    PIUNKNOWN pObject;

    /* Pointer and reference to the current namespace */
    INameSpace *pNS = CurrentNameSpace();

    /* Initialize an unknown object as MyObject */
    IUnknown *pUnknwn = new MyObject; 

    SCODE StatusCode;
    _TCHAR *pName = _TEXT("MyObject");
    StatusCode = pNS->Register(pName, pUnknwn, 0, NULL);
    if(FAILED(StatusCode)) {
        _tprintf(_TEXT("Registering %s failed with error code %08x.\n"),
                      pName, StatusCode);
        exit(0);
    }
    _tprintf(_TEXT("Registering %s succeeded.\n"), pName);
 
    /* Verify that MyObject is registered in system namespace. */
    StatusCode = pNS->Bind(pName, 0, &pObject);
    if (StatusCode != S_OK) {
        _tprintf(_TEXT("Error in registering object name!\n"));
        exit(0);
    }
    _tprintf(_TEXT("Succeeded in registering object name.\n"));

    /* Other threads use the object. */
    /* ... */
    return 0;
}

See also CurrentNameSpace NAME_SPACE_FLAGS

C++

SCODE INameSpace::Register( 
    /*in*/ const _TCHAR * pName,
    /*in*/ PIUNKNOWN pObj,
    /*in*/ NAME_SPACE_FLAGS Flags,
    /*in,optional*/ PINAMESPACE pServerNameSpace)

INameSpace.Unregister Method

Removes a registered {name, object} pair from the namespace.

SCODE Unregister( 
    /*in,this*/ PINAMESPACE iThis,
    /*in*/ const _TCHAR * pName)
pName

Contains the address of a null-terminated string specifying the name of an object previously registered in the namespace.

The following example produces an E_NAME_NOT_FOUND error if the example from the INameSpace.Register method has not been executed first.

Example Unregister

/* Pointer and reference to the system namespace. */
INameSpace *pNS;
SCODE StatusCode;
IUnknown *pObject;
_TCHAR *pName = _TEXT("MyObject");

/* "MyObject" must already be registered in the namespace. */
_tprintf(_T("Attempting to unregister object name \"%s\".\n"),
              pName);
pNS = CurrentNameSpace();
StatusCode = pNS->Unregister(pName);
if(StatusCode != S_OK) {
    _tprintf(_T("Failed to unregister object name!\n"));
    exit(0);
}

/* Verify that object name is no longer registered. */
StatusCode = pNS->Bind(pName, 0, &pObject);
if (StatusCode == S_OK) {
    _tprintf(_T("Error in unregistering object name!\n"));
    pObject->Release();
    exit(0);
}
_tprintf(_T("Succeeded in unregistering object name.\n"));

See also CurrentNameSpace

C++

SCODE INameSpace::Unregister( 
    /*in*/ const _TCHAR * pName)

INameSpace.Bind Method

Translates a name into an object reference. This method either creates or references the object associated with the specified name and returns a pointer to that object.

SCODE Bind( 
    /*in,this*/ PINAMESPACE iThis,
    /*in*/ const _TCHAR * pName,
    /*in*/ NAME_SPACE_FLAGS Flags,
    /*out*/ PIUNKNOWN* ppUnk)
pName

Address of a null-terminated string that specifies the name registered in the namespace for the object.

Flags

Each bit is a flag that the caller sets to one to select the processing option represented by the flag. Multiple flags may be set to select multiple options simultaneously.

ppUnk

On successful return, the location pointed to by this parameter contains the address of an interface pointer to the object. Note that it is returned as a pointer to an object of class IUnknown and that one reference is taken on the returned object.

This method can create only INameSpace interface objects; use INameSpace.Register to insert any other type of object.

The method returns a pointer to the object in the namespace that is registered under the specified name. Since an IUnknown interface pointer points to the registered object, the IUnknown.QueryInterface method can be used to obtain an interface pointer to the correct type. After obtaining the pointer to the object, you can use that object and call its methods. Remember to release the IUnknown object properly.

Example Bind

/* If a namespace object named "MyNamespace/" already exists, get
 * a pointer to it.  Otherwise, create a new namespace object.
 */
INameSpace *pSysNS;
IUnknown *pUnknown;
SCODE StatusCode;
_TCHAR ObjName[] = _TEXT("MyNamespace/");

/* Get a pointer to the object registered as "MyNamespace/". */
pSysNS = CurrentNameSpace();
StatusCode = pSysNS->Bind(ObjName, 0, &pUnknown);
if (FAILED(StatusCode)) {
    /* Need to create namespace object named "MyNamespace/" */
    _tprintf(_TEXT("Namespace \"%s\" does not exist--create it.\n"),
                  ObjName);
    StatusCode = pSysNS->Bind(ObjName, NAME_SPACE_CREATE, &pUnknown);
    if (FAILED(StatusCode)) {
        _tprintf(_TEXT("Failed to create namespace %s.\n"), ObjName);
        exit(0);
    }
}
_tprintf(_TEXT("The namespace object named \"%s\""), ObjName);
_tprintf(_TEXT(" is located at address %08x\n"), (ADDRESS) pUnknown);
pUnknown->Release();

See also ICRuntime.BindToObject CurrentNameSpace INameSpace.Register NAME_SPACE_FLAGS

C++

SCODE INameSpace::Bind( 
    /*in*/ const _TCHAR * pName,
    /*in*/ NAME_SPACE_FLAGS Flags,
    /*out*/ PIUNKNOWN* ppUnk)

INameSpace.FindNext Method

Returns the next name that appears in the namespace or subnamespace.

SCODE FindNext( 
    /*in,this*/ PINAMESPACE iThis,
    /*in,optional*/ const _TCHAR * pPrefix,
    /*in,optional*/ const _TCHAR * pPrevious,
    /*out*/ _TCHAR * pBuffer,
    /*in*/ UINT BufSize,
    /*out,optional*/ UINT * pStrLen)
pPrefix

This parameter is used to start the search at a given subnamespace. A simple namespace implementation might not support subnamespaces. Use NULL to specify the root namespace.

pPrevious

Contains the address of a null-terminated string specifying a name previously returned by the INameSpace.FindNext method. This parameter typically points to the same location as the pBuffer parameter (during iterations). Note that if pPrevious is either a null pointer or points to an empty string, the method returns the first name that appears in the given namespace.

pBuffer

A pointer to a buffer into which the method, if successful, copies the name of the object.

BufSize

Number of bytes in the buffer pointed to by the pBuffer parameter.

pStrLen

A pointer to an integer variable into which the method, if successful, copies the length of the string that is written to the buffer pointed to by pBuffer. The length is specified as the number of characters in the string containing the name, excluding the terminating null character. Note that in the case of a Unicode string, the number of characters does not equal the number of bytes.

An error code is never returned if an entry that matches pPrevious exists in the namespace.

The status code S_NO_MORE_ENTRIES indicates that the name pointed to by pString was successfully matched to an entry in the namespace. It also indicates that the namespace contains no more entries, but this can happen in one of two ways.

First, it may be that the namespace entry that matches the name pointed to by pString is the next-to-last entry in the namespace. In this case, the method copies the name from the last entry into the buffer pointed to by pBuffer and writes the name's string length to the location pointed to by pStrLen.

Second, it may be that the name matching the one pointed to by pString is the last entry. In this case, the method writes zero to the location pointed to by pStrLen.

Example FindNext

/* Find all entries in system namespace. */
#define BUFLEN    20
#define BUFSIZE   BUFLEN*sizeof(_TCHAR)

INameSpace *pNS;
SCODE StatusCode;
_TCHAR Buf[BUFLEN];
UINT Len;

_tprintf(_T("Search for all names in system namespace.\n"));
pNS = CurrentNameSpace();
StatusCode = pNS->FindNext(NULL, NULL, Buf, BUFSIZE, &Len);
do {
    switch (StatusCode) {
        case S_OK:
            _tprintf(_T("The next name in the namespace is \"%s\".\n"),Buf);
            _tprintf(_T("The string length of \"%s\" is %d.\n"), Buf, Len);
            break;
        case S_NO_MORE_ENTRIES:    
            _tprintf(_T("The last name in the namespace is \"%s\".\n"),Buf);
            _tprintf(_T("The string length of \"%s\" is %d.\n"), Buf, Len);
            break;
        case S_BUFFER_TOO_SMALL:    
            _tprintf(_T("The name is %d characters long, which is\n"), Len);
            _tprintf(_T("too long to fit in the buffer supplied.\n"));
            break;
        default:   
            _tprintf(_T("An error has occurred!\n"));
            break;
    }
    StatusCode = pNS->FindNext(_T(""), Buf, Buf, BUFSIZE, &Len);
} while (StatusCode == S_OK);

Example FindFirst

/* Find first entry in system namespace. */
#define BUFLEN   20
#define BUFSIZE  BUFLEN*sizeof(_TCHAR)

INameSpace *pNS;
SCODE StatusCode;
_TCHAR Buf[BUFLEN];
UINT Len;

_tprintf(_T("Search for first name in system namespace.\n"));
pNS = CurrentNameSpace();
StatusCode = pNS->FindNext(NULL, NULL, Buf, BUFSIZE, &Len);
switch (StatusCode) {
    case S_OK:
        _tprintf(_T("The first name in the namespace is \"%s\".\n"), Buf);
        _tprintf(_T("The string length of \"%s\" is %d.\n"), Buf, Len);
        break;
    case S_NO_MORE_ENTRIES:    
        _tprintf(_T("The only name in the namespace is \"%s\".\n"), Buf);
        _tprintf(_T("The string length of \"%s\" is %d.\n"), Buf, Len);
        break;
    case S_BUFFER_TOO_SMALL:    
        _tprintf(_T("The name is %d characters long.\n"), Len); 
        _tprintf(_T("It's too long to fit in the buffer supplied.\n"));
        break;
    default:
        _tprintf(_T("The namespace is empty.\n"));
        break;
}

C++

SCODE INameSpace::FindNext( 
    /*in,optional*/ const _TCHAR * pPrefix,
    /*in,optional*/ const _TCHAR * pPrevious,
    /*out*/ _TCHAR * pBuffer,
    /*in*/ UINT BufSize,
    /*out,optional*/ UINT * pStrLen)

INameSpace.GetCapabilities Method

Reports the capabilities supported by an object registered under the specified name. These capabilities are those defined by the INameSpace.Register method and have no meaning for the namespace itself.

SCODE GetCapabilities( 
    /*in,this*/ PINAMESPACE iThis,
    /*in*/ const _TCHAR * pName,
    /*out*/ NAME_SPACE_FLAGS * pFlags)
pName

Contains the address of a null-terminated string specifying a valid name within the namespace.

pFlags

On successful return, contains flag values that describe the capabilities of the named object.

C++

SCODE INameSpace::GetCapabilities( 
    /*in*/ const _TCHAR * pName,
    /*out*/ NAME_SPACE_FLAGS * pFlags)

NAME_SPACE_FLAGS Constant

Bit values for Flags arguments in INameSpace methods.

Underlying C type:

NAME_SPACE_READ 0x1

Read access.

NAME_SPACE_WRITE 0x2

Write access.

NAME_SPACE_SHARE_READ 0x4

Windows 2000 compat. Ignored.

NAME_SPACE_SHARE_WRITE 0x8

Windows 2000 compat. Ignored.

NAME_SPACE_CREATE 0x10

Create a new object. Destroys existing object if any (in this case S_ALREADY_EXISTS is returned.

NAME_SPACE_FAILIFEXIST 0x20

Together with CREATE makes the call return E_ALREADY_EXISTS if there was an existing object with the specified name with the existing object intact.

NAME_SPACE_EXTENSION 0x800

The registered object should be treated as a subnamespace.

NAME_SPACE_NOFOLLOW 0x1000

Do not follow symbolic links.

NAME_SPACE_PREFIX 0x2000

Treat name as is without splitting at slashes.

NAME_SPACE_APPEND 0x40000

Compatibility flag. Ignored by most file systems. On hostfs it is passed through to Windows.

Each bit is a flag that the caller sets to one to select the processing option represented by the flag. Multiple flags may be set to select multiple options simultaneously.

Type NAME_SPACE_FLAGS is defined as unsigned integer. Each bit in a variable of this type is treated as a flag controlling a particular option. When the bit is set, the option is selected or enabled. Zero, one, or multiple flags may be set within the variable.

Individual flag bits are specified by symbolic constants, each of which is a value where the designated flag bit is set to one and all other bits are set to zero. The value of a variable of type NAME_SPACE_FLAGS is formed by a bitwise OR of one or more of these flags. A value of zero specifies that none of the flags is set.

©2006 Microsoft Corporation. All rights reserved. Terms of Use Privacy Statement Accessibility End User License Agreement