c# - Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)) -
i try flowing code create wmplib.iwmpfoldermonitorservices in c# manage folders contain music.
public partial class mainwindow : window { private wmplib.iwmpplayer player; private wmplib.iwmpfoldermonitorservices managefolder; [dllimport("ole32.dll", exactspelling = true, preservesig = false)] [return: marshalas(unmanagedtype.interface)] static extern void cocreateinstance([in, marshalas(unmanagedtype.lpstruct)] guid rclsid, [marshalas(unmanagedtype.iunknown)] object punkouter, clsctx dwclscontext, [in, marshalas(unmanagedtype.lpstruct)] guid riid, [marshalas(unmanagedtype.iunknown)] out object rreturnedcomobject); public mainwindow() { initializecomponent(); object instanceplayer = null; guid guid_iwmpplayer = typeof(wmplib.iwmpplayer).guid; guid guid_iunknown = new guid("00000000-0000-0000-c000-000000000046"); try { cocreateinstance(guid_iwmpplayer, null, clsctx.clsctx_inproc_server, guid_iunknown, out instanceplayer); } catch (exception e) { messagebox.show(e.message); } type type = type.gettypefromclsid(guid_iwmpplayer); player = instanceplayer wmplib.iwmpplayer; object instancefolder = null; guid guid_iwmfolder = typeof(wmplib.iwmpfoldermonitorservices).guid; intptr ptr1, ptr2; try { ptr1 = marshal.getcominterfaceforobject(instanceplayer, type); marshal.queryinterface(ptr1, ref guid_iwmfolder, out ptr2); marshal.ptrtostructure(ptr2, instancefolder); } catch(exception e) { messagebox.show(e.message); } managefolder = instancefolder wmplib.iwmpfoldermonitorservices; } } }
i exception :
class not registered (exception hresult: 0x80040154 (regdb_e_classnotreg))
at :
cocreateinstance(guid_iwmpplayer, null, clsctx.clsctx_inproc_server, guid_iunknown, out instanceplayer);
and exception:
value cannot null. parameter name: o
in second try block. search on google exception can't fix it.
if need create instance of media player, this:
windowsmediaplayerclass wmp = new windowsmediaplayerclass();
windowsmediaplayerclass has been created when imported wmplib.
Comments
Post a Comment