简体   繁体   中英

CoCreateInstance exception. Class registration using REGSVR32 on a static library?

The code(a snippet from my c++ com server project built for Win32 platform, in my c# app):

CComPtr<IMSPRProvider> test;
hr = CoCreateInstance(CLSID_MSPRProvider, NULL, CLSCTX_ALL, IID_IMSPRProvider, reinterpret_cast<void**>(&test));

The HR: regdb_e_classnotreg. class not registered

In this same project I have an older WMDRM drm implementation that works just fine with cocreateinstance calls. So the issue is particular to the new playready classes.

I see other questions with this exception that suggest registering the dll using regsvr32.exe. If that is the solution, I have two questions:

  1. I never needed to register anything else(like the WMDRM stuff) so why this?
  2. I'm using the PlayReady SDK which consists of some .h, .idl, and .lib files that I've linked into my project. I do not have a dynamic library. What is the equivalent solution for static libraries?

PS: I have almost zero experience with c++. I am seriously winging all of this so my apologies if I haven't given sufficient details.

CoCreateInstance creates an instance using server which somehow needs to be available. In most cases the server is a DLL and it needs to be registered with regsvr32 first so that CLSID in question is written in global list and API knows how where to look for implementation.

I never needed to register anything else(like the WMDRM stuff) so why this?

REGDB_E_CLASSNOTREG indicates that server is not registered, so you need to do it. If you never did it before then you have it done for you by something else.

I'm using the PlayReady SDK which consists of some .h, .idl, and .lib files that I've linked into my project. I do not have a dynamic library. What is the equivalent solution for static libraries?

There is no equivalent for static library. CoCreateInstance creates an instance using standard API. You just don't need it for static library at all if implementation is linked in. Most likely, however, your "static library" is only a front end and/or declaration and the real implementation is in dynamic load library. Hence CoCreateInstance , and the registration.

Another thing for you to note is 32/64-bit confusion. Your code should be matching bitness of the DLL. In case of mismatch you can again run into REGDB_E_CLASSNOTREG problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM