Article ID: 186212
Article Last Modified on 11/21/2006
//Type library GUID, corresponds to the uuid attribute of the library
//section in the .odl file.
const GUID CDECL BASED_CODE _tlid = { 0x9dbafcd2, 0x592f, 0x101b,
{ 0x85, 0xce, 0x0, 0x60, 0x8c, 0xec, 0x29, 0x7b } };
//Type library major version number, number on the left of decimal
//point, in version attribute of the library section in .odl file.
const WORD _wVerMajor = 1;
//Type library minor version number, number on the right of decimal
//point, in version attribute of the library section in .odl file.
const WORD _wVerMinor = 0;
STDAPI DllUnregisterServer(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
//MFC Automation servers do not register typelibs by default.
//Add following line only if you have code to register typelib.
if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
return ResultFromScode(SELFREG_E_TYPELIB);
if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
return ResultFromScode(SELFREG_E_CLASS);
return S_OK;
}
DECLARE_OLECREATE(CMyObj)
to the following:
DECLARE_OLECREATE_EX(CMyObj)
IMPLEMENT_OLECREATE(CMyObj, ...)
to the following:
IMPLEMENT_OLECREATE_EX(CMyObj, ...)
//The classfactory is nested in your class and has a name formed
//by concatenating the class name with "Factory".
BOOL CMyObj::CMyObjFactory::UpdateRegistry(BOOL bRegister)
{
if (bRegister)
return AfxOleRegisterServerClass(m_clsid, m_lpszProgID,
m_lpszProgID, m_lpszProgID, OAT_DISPATCH_OBJECT);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);
COleObjectFactory::UpdateRegistryAll();
with the following:
//if command line has /unregister...
if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister)
{
//During unregistration we call UpdateRegistry(OAT_DISPATCH_OBJECT)
//to set up the m_bOAT member COleTemplateServer to the correct
//type for unregistration of automation object supported by CDocument
//derived class. Unregistration is done in ProcessShellCommand().
m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);
//This unregisters all other COM objects derived from CcmdTarget.
COleObjectFactory::UpdateRegistryAll(FALSE);
}
else
{
m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);
COleObjectFactory::UpdateRegistryAll();
}
COleObjectFactory::UpdateRegistryAll();
with the following:
// Parse command line.
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
//if command line has /unregister...
if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister)
{
//FALSE results in unregistering all COM objects implemented as
//CCmdTarget derived classes.
COleObjectFactory::UpdateRegistryAll(FALSE);
}
else
{
COleObjectFactory::UpdateRegistryAll();
}
Additional query words: MfcOLE
Keywords: kbautomation kbcode kbhowto kbregistry KB186212