1

Hello I got the following exception.

Retrieving the COM class factory for component with CLSID {6BF52A4F-394A-11D3-B153-00C04F79FAA6} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

When i try to create o COM object with flow code( in c#)

Object instancePlayer = null;
Guid guid_IWMPPlayer = typeof(WMPLib.IWMPPlayer).GUID;
Guid guid_IUnknown = new Guid("00000000-0000-0000-C000-000000000046");
Type type = Type.GetTypeFromCLSID(guid_IWMPPlayer);
instancePlayer = Activator.CreateInstance(type);
Longit644
  • 43
  • 1
  • 9
  • COM distinguishes between classes and interfaces. And just like .NET, you cannot create an instance of an interface. Your code doesn't make any sense, it is just a broken way to say `Type type = typeof(WMPLib.IWMPPlayer)`. Nor does it make sense to try to use late binding and then still use the early bound interface types. I can't see the intent of this code. Use the ProgId for late binding. – Hans Passant Apr 17 '13 at 13:24
  • I get exception at code : instancePlayer = Activator.CreateInstance(type); – Longit644 Apr 17 '13 at 13:27
  • sure you do. You want to create an instance of an interface, not implementation. How does your the framework know which implementation you want? How do you imagine a line like `var object = Activator.CreateInstance(typeof(IDisposable));` should work? – Zdeslav Vojkovic Apr 17 '13 at 13:49
  • By any chance are you running your code in 64-bit and trying to activate something that's 32-bit only? I suspect Windows Media Player has a 64-bit version but it doesn't hurt to double check. I was getting the same exception testing a COM component from 64-bit LinqPad until it dawned on me that it's an old 32-bit only COM component (one I had written in Delphi 7) – Ian Yates May 11 '17 at 02:50

1 Answers1

1

COM uses GUIDs to identify classes and interfaces. It looks like you're using an interface ID (IID) called IWMPPlayer instead of a class ID (CLSID). See if you can find a corresponding class for the player object and use the GUID of that.

Update: I looked up the class for you. Get the CLSID like this...

Guid guid_WMPPlayer = typeof(WMPLib.WindowsMediaPlayer).GUID;

... and then pass this CLSID into Type.GetTypeFromCLSID.

Update 2: Can I just check though, that you definitely need to use these GUIDs? Why not just do...

instancePlayer = new WMPLib.WindowsMediaPlayer();

...?

Martin
  • 5,392
  • 30
  • 39
  • Can you say more detail about it ?? – Longit644 Apr 17 '13 at 13:26
  • but I want create a WMPLib.IWMPFolderMonitorServices object from WMPLib.IWMPPlayer Object – Longit644 Apr 17 '13 at 14:32
  • That sounds like a separate question; you didn't mention it before. Does my answer resolve the question you posted? – Martin Apr 17 '13 at 14:39
  • I'm sorry. after this code I want Retrieve a pointer to IWMPFolderMonitorServices by calling QueryInterface through IWMPPlayer but I get excpetion here – Longit644 Apr 17 '13 at 14:59
  • No need to apologise. Just post another question explaining what you tried, and showing the error you get. Just like you did with this question :-) – Martin Apr 17 '13 at 15:10