About COM

How do I get a service object?

Services are global objects, so unlike traditional localized COM objects, they don’t need to be initialized. You can simply declare them and then start using them.

C++

CLxUser_SceneService      scn_svc;
LXtItemType               mesh_type;

scn_svc.ItemTypeLookup (LXsITYPE_MESH, &mesh_type);

Python

scn_svc = lx.service.Scene()

mesh_type = scn_svc.ItemTypeLookup (lx.symbol.sITYPE_MESH)

The constructor for the C++ wrapper calls lx::GetGlobal() to initialize the interface. In some instances, such as when a service is created too early, the GetGlobal function call will fail. In these cases, it may be necessary to initialize the service wrapper manually. If you declare your service object as a static variable, and then simply call set() before use to initialize the interface.

C++

static CLxUser_SceneService      scn_svc;

scn_svc.set ();

How do I get my C++ implementation from a COM handle?

If you have an interface handle and you know the type of the C++ object that’s implementing it, you can unwrap the COM object and get at the meaty C++ object inside. If this is one of your servers, then you just have to call lx::CastServer() with the server name:

C++

        CMyClass *
Extract (
        ILxUnknownID             from)
{
        CMyClass                *mine;

        lx::CastServer (SERVER_NAME, from, mine);
        return mine;
}

If the COM object comes from a spawner then you need to use the Cast() method on the spawner:

C++

        CMyClass *
Extract (
        ILxUnknownID             from)
{
        CLxSpawner<CMyClass>     spawn ("myClass");

        return spawn.Cast (from);
}

You have to make sure that the interface pointer you have is actually implemented by your class. If you get an ILxItemID pointer, for example, you need to query for one of your specific implemented interfaces in order to be able to get your package instance class.

Is it possible to create COM wrappers for other languages?

Yes. Yes it is. :ref: Language Wrappers