Microsoft SDK for Java

Object Allocation

The following Java statement is identical to Java's syntax for allocating ordinary Java objects. Behind the scenes, the COM API function CoCreateInstance is called instead of allocating space in the runtime heap. However, this call is invisible to the Java programmer.

In C++, you allocate a new COM object using the following syntax:

IDrawable pDrawable;
CoCreateInstance(CLSID_MyCircle, NULL, CLSCTX_SERVER,
                  IID_IDrawable, (void**)&pDrawable);

In Java, the equivalent code looks like this:

IDrawable drawable = (IDrawable)new MyCircle();

© 1999 Microsoft Corporation. All rights reserved. Terms of use.