This question is an extension of this article .
In the same case, I created a instance of WMP ActiveX by its ProgID
.
protected const string WMP_PROG_ID = "WMPlayer.OCX.7";
private dynamic _wmp;
protected virtual bool init(){
try{
_wmp = Activator.CreateInstance(Type.GetTypeFromProgID(WMP_PROG_ID));
}
catch{ return false; }
return connectEvent();
}
According the MSDN document, there are an Error
event and an error
property in WMPlayer object. So, I try to attach events like this way.
protected bool connectEvent(){
try{
_wmp.PlayStateChange += new StateHandler(_wmp_PlayStateChange);
//_wmp.Error += new Action(_wmp_ErrorEvent);
}
catch { return false; }
return true;
}
protected void _wmp_PlayStateChange(WMPlayerState state){
//do something I like
}
protected void _wmp_ErrorEvent(){
//do some error handling
}
If I keep //_wmp.Error += new Action(_wmp_ErrorEvent)
commented, there's no compile error and PlayStateChange
works pretty good.
However, if I remove the comment mark, there's a runtime exception. Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: can not apply operator "+=" between 'System.__ComObject' and 'System.Action'
It seems the two "error" are conflicted because COM is case insensitive. How can I solve it? My goal is that attach to "Error" event without using AxWindowsMediaPlayer.
I ran in to a very similar problem as you but mine was with Size
. The strongly typed ActiveX control redefined Size
so I needed to cast it back to Control
when the forms designer wanted to size the control on my form.
((Control)this.axLEAD1).Size = new System.Drawing.Size(298, 240);
If you can get a strongly typed class for the com object (by adding a reference or using tlbimp.exe ) you may be able to cast to the strongly typed com object instead of __ComObject
and have it use the correct method.
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.