A method and system for instantiating COM components in custom contexts
are proposed. The solution of the invention is based on an auxiliary
component, acting as a factory (215). Whenever a client (205) needs to
instantiate a new target component in a desired custom context, it calls
a dedicated method exposed by the factory, passing the identifier of the
target component together with information about the custom context. The
factory starts execution of an additional module, operating as an
impersonator (225), in a new process (230) conforming to the custom
context. The impersonator then instantiates the target component in its
own process. The impersonator passes a pointer for the target component
to the factory (calling a further method that is exposed by the factory);
the factory in turn returns that pointer to the client.