Symbian
Symbian OS Library

SYMBIAN OS V9.3

[Index] [Spacer] [Previous] [Next]



How to define instantiation functions

An object definition's instantiation function does not have the usual new(ELeave)..PushL()...ConstructL()...Pop() structure. Instead, it delegates construction to a static function REComSession::CreateImplementationL().

There are a number of overloads of the CreateImplementationL() function that offer different parameter options:

An interface definition can have more than one such instantiation function, offering different options to the client.

Example

The following example declares a NewL() function that takes a string to use for resolution from the client, wraps this in a TEComResolverParams, and calls REComSession::CreateImplementationL() to get an instance.

Typically, the NewL() function is static, and means that you need to pass the offset to the data member that is to contain the instance identifier key. This offset value is passed as the second parameter in the call to REComSession::CreateImplementationL(), which then puts the instance identifier key value into that position in the returned object (which is cast as a CExampleInterfaceDefinition type).

inline CExampleInterfaceDefinition* CExampleInterfaceDefinition::NewL(const TDesC& aMatchString)
    {
    const TUid KExampleInterfaceDefinitionUid = {0x10009DC0};

    TEComResolverParams resolverParams; 
    resolverParams.SetDataType(aMatchString);
    TAny* ptr = REComSession::CreateImplementationL(
       KExampleInterfaceUid,
        _FOFF(CExampleInterfaceDefinition,iDtor_ID_Key),
        resolverParams);

     return REINTERPRET_CAST(CExampleInterfaceDefinition*, ptr);
     }

Note

CreateImplementationL() returns a TAny* (i.e. a void*), so this must be cast to the actual pointer type.