CreateObject

The CreateObject method creates the actual underlying IDL object. The argc, argv, and argpal parameters are used to supply parameters to the underlying IDL object's Init method. If the Init method does not have any parameters, the caller sets argc, argv, and argpal to 0, NULL, and NULL, respectively.

This method creates IDL objects that use a default licensing algorithm (see IDL Licensing Modes for details). To use a specific IDL licensing mode, use the CreateObjectEx method.

Note
By default, ActiveX controls call the CreateObject method implicitly. In an ActiveX control, calls to the CreateObject method in client code will be ignored if the Explicit CreateObject property in the Export Bridge Assistant project was set to False when the ActiveX control was built.

Syntax

HRESULT CreateObject ([in] int argc, [in] VARIANT argv, [in] VARIANT argpal)

Parameters

argc

An integer that specifies the number of elements in the argv and argpal arrays.

argv

A VARIANT containing a COM SafeArray of VARIANT types, one for each parameter to Init. The elements in the array are given in order of the parameters listed in Init, ordered from left to right.

argpal

A VARIANT containing a COM SafeArray of 32-bit integer flag values, which can be a combination of the IDLBML_PARMFLAG_CONST and IDLBML_PARMFLAG_CONVMAJORITY values ORed together. The latter value is only used when an argv element is an array itself. For parameters that are not arrays, the argpal[n] value must be 0.

The following constant values defined in the typlib information of a wrapped IDL object can be used:

IDLBML_PARMFLAG_CONST

Use for parameters that are constant (In-Only, meaning that their values cannot be changed).

IDLBML_PARMFLAG_CONVMAJORITY

Include if the property value is an array.

For more information, see Converting Array Majority.

Example

Note
See COM Object Creation for examples of creating objects from a variety of COM programming languages.

The Init method of the IDL object being wrapped has the following signature:

PRO IDLexFoo::INIT, rect, filename 

where rect is an array of 4 integers and filename is a string.

The COM client code that creates an instance of the wrapper object, and calls the CreateObject() method with the rect and filename parameters, would look like the following:

CComSafeArray<int> csa(4); 
csa[0] = 0; csa[1] = 0; csa[2] = 5; csa[3] = 10; 
 
CComVariant argv[2]; 
int         argp[2]; 
 
argv[0] = csa.Detach(); 
argp[0] = IDLBML_PARMFLAG_CONST; 
argv[1] = "someFilename.txt"; 
argp[1] = IDLBML_PARMFLAG_CONST; 
 
CComPtr<IMyWrapper> spWrapper; 
spWrapper.CoCreateInstance(__uuidof(MyWrapper)); 
 
spWrapper->CreateObject(2, argv, argp);