Advanced COM CreateObject method
CreateObject  method

Creates COM object as specified (see below).


Set o = object.CreateObject( objIDString [, flags])


objIDString - A string containing ProgID, ClassID, DLL path + ClassID, File name etc. Depending on the value different mechanisms will be attempted. The string can follow one of the following schemes:

ClassID - A form like {238DF0CC-1982-4D2A-9773-22795F358304}. The method will attempt standard COM techniques (if not forbidden by the flags - see below) and if the object is not registered the newobjectspack1.dll will be tried - if the ClassID matches some of the classes in it the object will be created.

ProgID - A form like Company.ClassName or Company.Category.ClassName. The usual way COM objects are created from scripting applications. This will succeed only if the object is registered in the system registry.

File name - Form like this C:\mycomponents\composite_definition.def. Method will see if the file is a definition of a composite object and will try to create it.

DLL File + ClassID - Form like this C:\dlls\someCOMDll.DLL{238DF0CC-1982-4D2A-9773-22795F358304} The method will attempt to load the DLL and create an object of the class specified by the ClassID after the DLL name.

Internal Alias - An alias of one of the classes in the newobjectspack1.dll. Teh following aliases are currently defined:

ScpMan  ScriptManager2
ScpAggregate ScriptAggregate
VarDictionary VarDictionary universal collection
UtilStringList UtilStringList object
CustomLock CustomLock object
ConfigFile ConfigFile object
IniFile IniFile object
SFStream SFStream object
SFMain SFMain object
SFStorage SFStorage object
SFFileStream SFFileStream object
SFDirStorage SFDirStorage object
SFDrive SFDrive object
SFField SFField object
SFRecord SFRecord object
SFFilter SFFilter object
TypeConvertor TypeConvertor object
VaryDisp VaryDisp object
VaryDispCreator VaryDispCreator object
SFShellLink SFShellLink object
Pack1Creator Pack1Creator object
COMApartment COMApartment object
COMThread COMThread object
COMApartmentFreeThreaded COMApartment object initialized as free-threaded.

flags -  optional flags which can be used to forbid some of the supported mechanisms. Specifying flags may improve the application performance if the application creates objects in rapid rate. The flags supported are:

&H01 Try the standard COM techniques first
&H10 Do not use ActiveX Pack1 aliases
&H20 Do not try as composite definition files
&H40 Do not try the standard COM techniques
&H80 Do not try direct DLL


Set cr = Server.CreateObject("newObjects.utilctls.Pack1Creator")
' Typical COM way
Set o = cr.CreateObject("newObjects.utilctls.SFShellLink")
' By alias
Set o = cr.CreateObject("SFShellLink")
' By alias but also flags are used to help the method determine what to do
Set o = cr.CreateObject("SFShellLink",&HE0)
' Direct creation from a DLL
Set o = cr.CreateObject(Server.MapPath("DLLS\newobjectspack1.dll{70BD6BA6-C316-4CD5-9E95-A5BEA443ABAC}")


The flags can be used also to guarantee no confusion will occur if there is a registered COM class with ProgID matching an internal object alias. This is most likely impossible but can be done with some of the development tools (in C++ you are free to specify whatever you want for ProgID) so a precaution will not be a mistake.

If the class is not registered in the registry or is registered as "Both" it will be created in the same COM apartment where the Pack1Creator is. This gives the application more control over the creation process than usual. For example COMApartment object uses this to allow the application create objects in the newly created apartment. So having a Pack1Creator object in a given context you can create other objects in the same context through it.

See also the remarks for the CreateObjectFromDLL if you are going to use direct DLL creation.

Applies to: Pack1Creator object

newObjects Copyright 2001-2006 newObjects [ ]