Cообщество разработчиков на платформе Microsoft >
Форумы
>
Common Language Runtime
>
CoCreateInstance returns REGDB_E_CLASSNOTREG (IMAPI)
CoCreateInstance returns REGDB_E_CLASSNOTREG (IMAPI)
- Hi, i'm trying to accessing IMAPI from a Managed C++ Windows Form Control Library
the problem is that when i call CoCreateInstance i get in return REGDB_E_CLASSNOTREG.
I Really dont understand why since the equivalent code from a .NET imapi wrapper that works is identical. notice also that the same C++ code here works on another machine.
i assume also that the class is correctly registered since the C# code works.
thanks to anyone who try to help
My C++/CLI code:
[code]
CLSIDFromString(L"{520CCA62-51A5-11D3-9144-00104BA11C5E}", &CLSID_MSDiscMasterObj);
CLSIDFromString(L"{520CCA62-51A5-11D3-9144-00104BA11C5E}", &IID_IDiscMaster);
CoInitialize( NULL );
hr = CoCreateInstance(CLSID_MSDiscMasterObj, nullptr, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IDiscMaster, (void**)&m_pDiscMaster); //REGDB_E_CLASSNOTREG
[/code]
working C# code
[code]
object discMaster = null;
Guid clsIdDiscMaster = new Guid(CLSID_MSDiscMasterObj);
Guid iidDiscMaster = new Guid(IID_IDiscMaster);
int hResult = IMAPIObjectFactory.CoCreateInstance(ref clsIdDiscMaster, IntPtr.Zero, CLSCTX.CLSCTX_INPROC_SERVER | CLSCTX.CLSCTX_LOCAL_SERVER, ref iidDiscMaster, out discMaster);
[/code]
where CoCreateInstance is
[code]
[DllImport("ole32", CharSet = CharSet.Unicode)]
private extern static int CoCreateInstance(
ref Guid CLSID,
IntPtr pUnkOuter,
CLSCTX dwClsContext,
ref Guid IID,
[MarshalAs(UnmanagedType.Interface)]
out object ppv);
[/code]
Ответы
- IMAPIObjectFactory only encapsulate CoCreateinstance nothing more.
anyway i tried changed
From:
CoCreateInstance(CLSID_MSDiscMasterObj, 0, CLSCTX_ALL, IID_IDiscMaster, (void**)&m_pDiscMaster); //REGDB_E_CLASSNOTREG
To:
CoCreateInstance(__uuidof(MSDiscMasterObj), 0, CLSCTX_ALL, IID_IDiscMaster, (void**)&m_pDiscMaster); //OK
it seems to solve the problem...thx
Все ответы
- It is not equivalent code. In the C# code, you ask IMAPIObjectFactory to create the class object for you. You need to duplicate that in C++, find out how to create the IMAPIObjectFactory object.
- IMAPIObjectFactory only encapsulate CoCreateinstance nothing more.
anyway i tried changed
From:
CoCreateInstance(CLSID_MSDiscMasterObj, 0, CLSCTX_ALL, IID_IDiscMaster, (void**)&m_pDiscMaster); //REGDB_E_CLASSNOTREG
To:
CoCreateInstance(__uuidof(MSDiscMasterObj), 0, CLSCTX_ALL, IID_IDiscMaster, (void**)&m_pDiscMaster); //OK
it seems to solve the problem...thx

