Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than Interfaces, prefix the name with the module name and a period.
IClassFactory (Interfaces)
.
This interface is used to instantiate a COM Object with a licence key
C# Definition:
[ComImport]
[Guid("B196B28F-BAB4-101A-B69C-00AA00341D07")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IClassFactory2
{
/// <summary>
/// the standard create instance (without licence)
/// </summary>
/// <param name="unused">must be set to null</param>
/// <param name="iid">the Guid of the COM class to create</param>
/// <returns>an instance of the COM class</returns>
[return: MarshalAs(UnmanagedType.Interface)]
Object CreateInstance(
[In, MarshalAs(UnmanagedType.Interface)] Object unused,
[In, MarshalAs(UnmanagedType.LPStruct)] Guid iid);
void LockServer(Int32 fLock);
IntPtr GetLicInfo(); // TODO : an enum called LICINFO
[return: MarshalAs(UnmanagedType.BStr)]
String RequestLicKey(
[In, MarshalAs(UnmanagedType.U4)] int reserved);
/// <summary>
/// create an instance of the COM class thanks to a licence key
/// </summary>
/// <param name="pUnkOuter">don't know what it is, set to null</param>
/// <param name="pUnkReserved">must be set to null</param>
/// <param name="iid">the Guid of the COM class to create</param>
/// <param name="bstrKey">the licence key</param>
/// <returns>an instance of the COM class</returns>
[return: MarshalAs(UnmanagedType.Interface)]
Object CreateInstanceLic(
[In, MarshalAs(UnmanagedType.Interface)] object pUnkOuter,
[In, MarshalAs(UnmanagedType.Interface)] object pUnkReserved,
[In, MarshalAs(UnmanagedType.LPStruct)] Guid iid,
[In, MarshalAs(UnmanagedType.BStr)] string bstrKey);
}
VB Definition:
<ComImport>
<Guid("B196B28F-BAB4-101A-B69C-00AA00341D07")>
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Interface IClassFactory2
Function CreateInstance(<MarshalAs(UnmanagedType.[Interface])> unused As Object,
<MarshalAs(UnmanagedType.LPStruct)> iid As Guid) As <MarshalAs(UnmanagedType.[Interface])> Object
Sub LockServer(ByVal fLock As Int32)
Function GetLicInfo() As IntPtr
Function RequestLicKey(<MarshalAs(UnmanagedType.U4)> reserved As Integer) As <MarshalAs(UnmanagedType.BStr)> String
Function CreateInstanceLic(<MarshalAs(UnmanagedType.[Interface])> pUnkOuter As Object,
<MarshalAs(UnmanagedType.[Interface])> pUnkReserved As Object,
<MarshalAs(UnmanagedType.LPStruct)> iid As Guid,
<MarshalAs(UnmanagedType.BStr)> bstrKey As String) As <MarshalAs(UnmanagedType.[Interface])> Object
End Interface
<DllImport("ole32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True, PreserveSig:=False)>
Function CoGetClassObject(<MarshalAs(UnmanagedType.LPStruct)> rclsid As Guid,
dwClsContext As CLSCTX,
pServerInfo As IntPtr,
<MarshalAs(UnmanagedType.LPStruct)> riid As Guid) As <MarshalAs(UnmanagedType.[Interface])> Object
End Function
The "Object" return by methods can be cast to the specified type.
Exemple :
String LicenceKey = "haha";
IClassFactory2 icf2 = Ole32.CoGetClassObject(
typeof(Interop.MyComLibrary.ComMyLibraryClass).GUID,
CLSCTX.CLSCTX_LOCAL_SERVER, new System.IntPtr(),
typeof(IClassFactory2).GUID) as IClassFactory2;
Interop.MyComLibrary.IMyComClass instance = icf2.CreateInstanceLic(
null, null, typeof(Interop.MyComLibrary.IMyComClass).GUID, LicenceKey) as Interop.MyComLibrary.IMyComClass;
Example vb.net :
Dim strLicense As String = "haha"
Dim classFactory As IClassFactory2 = CoGetClassObject(GetType(ComMyLibraryClass).GUID,CLSCTX.CLSCTX_LOCAL_SERVER,
IntPtr.Zero, GetType(IClassFactory2).GUID)
Dim instance As IMyComClass = classFactory.CreateInstanceLic(Nothing, Nothing, GetType(IMyComClass).GUID, strLicense)
An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.
1/13/2008 4:00:13 AM - Damon Carr-72.43.165.29
Click to read this page
3/14/2008 10:48:40 AM - -194.25.187.120
The CoGetClassObject API
3/16/2007 8:07:23 AM - -24.248.164.2
Please edit this page!
Do you have...
helpful tips?
corrections to the existing content?
alternate definitions?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.