【发布时间】:2013-03-23 11:04:40
【问题描述】:
这个问题是this article 的扩展。
在同样的情况下,我通过它的ProgID 创建了一个 WMP ActiveX 实例。
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();
}
根据MSDN 文档,WMPlayer 对象中有一个Error 事件和一个error 属性。
所以,我尝试以这种方式附加事件。
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
}
如果我继续评论//_wmp.Error += new Action(_wmp_ErrorEvent),
没有编译错误,PlayStateChange 工作得很好。
但是,如果我删除注释标记,则会出现运行时异常。
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: can not apply operator "+=" between 'System.__ComObject' and 'System.Action'
这两个“错误”似乎是冲突的,因为 COM 不区分大小写。我该如何解决? 我的目标是在不使用 AxWindowsMediaPlayer 的情况下附加到“错误”事件。
【问题讨论】:
标签: c# com case-sensitive case-insensitive wmp