static public IntPtr CreateClass(Guid rclsid, Guid riid)
{
IntPtr classFactory;
IntPtr objCreatedObject;
COMException Exception;
// Create a local copy so that we can pass it's reference
Guid IClassFactory = IID_IClassFactory;
int hr;
hr = DllGetClassObject(ref rclsid, ref IClassFactory, out classFactory);
try
{
if (hr < 0)
{
Exception = new COMException("Call to DllGetClassObject failed.", hr);
throw Exception;
}
hr = ClassFactory_CreateInstance(classFactory, ref riid, out objCreatedObject);
if (hr < 0)
{
Exception = new COMException("Call to CreateInstance failed.", hr);
throw Exception;
}
}
finally
{
ClassFactory_Release(classFactory);
}
return objCreatedObject;
}
}