CreateObjectEx

The CreateObjectEx method creates the actual underlying IDL object; it differs from the CreateObject method in that it allows the specification of flag values that control the way the IDL process is initialized. 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. The flags parameter specifies one or more initialization flags governing the way the IDL process is initialized; currently, the available flags control the method used to license the IDL session. (See IDL Licensing Modes for details on the default licensing mechanism.)

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 CreateObjectEx ([in] int argc, [in] VARIANT argv, [in] VARIANT argpal, [in] long flags))

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.

flags

Flag values that control the way the IDL process is initialized. The following constant values defined in the typlib information of a wrapped IDL object can be used:

IDLBML_LIC_FULL

The application requires that a licensed copy of IDL be installed on the local machine. If IDL is installed but no license is available, the application will run in IDL Demo (7-minute) mode.

IDLBML_LIC_LICENSED_SAV

The application looks for an embedded license in the save file being restored.

IDLBML_LIC_RUNTIME

The application looks for a runtime IDL license. If no runtime license is available, the application will run in Virtual Machine mode.

IDLBML_LIC_VM

The application will run in Virtual Machine mode.

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 CreateObjectEx() method with the rect and filename parameters, and which explicitly specifies that it should run in IDL Virtual Machine mode, 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.CreateObjectEx(2, argv, argp, IDLBML_LIC_VM);