VLC的ActiveX控件,注册过后,在VS2008中新建一个C#的WindowsApplication工程,选择工具箱,Choose Item...加入COM Components中列出的VideoLAN VLC ActiveX Plugin2,然后把这个控件拖到Form1上,编译成功,但是此时运行的话会发现在运行到InitializeComponents方法中调用控件的EndInit时出错,提示如下:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Windows.Forms.dll堆栈情况如下:Additional information: 没有注册类别 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))
  System.Windows.Forms.dll!System.Windows.Forms.AxHost.CreateInstance() + 0x178 bytes
  System.Windows.Forms.dll!System.Windows.Forms.AxHost.GetOcxCreate() + 0x1c bytes
  System.Windows.Forms.dll!System.Windows.Forms.AxHost.TransitionUpTo(int state) + 0xf9 bytes
  System.Windows.Forms.dll!System.Windows.Forms.AxHost.CreateHandle() + 0x2a bytes
  System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible) + 0x8a bytes
  System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible) + 0x16f bytes
  System.Windows.Forms.dll!System.Windows.Forms.AxHost.EndInit() + 0x38 bytes
> WindowsFormsApplication3.exe!WindowsFormsApplication3.Form1.InitializeComponent() Line 54 + 0x4e bytes C#
  WindowsFormsApplication3.exe!WindowsFormsApplication3.Form1.Form1() Line 16 + 0x11 bytes C#
  WindowsFormsApplication3.exe!WindowsFormsApplication3.Program.Main() Line 18 + 0x1e bytes C#
  [Native to Managed Transition]
  [Managed to Native Transition]
  Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x4e bytes
  mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x80 bytes
  mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x5f bytes 这里说没有注册类别我就觉得奇怪了。控件明显是注册了呀,要不然在工具箱的Choose Item时也不会列出来啊。而且如果不用C#来用控件而换用一个MFC的工程加入这个控件就是好的。
另外对于同样的控件、同样的方法在XP,2003中都是可以用的。 是Vista和VS2008结合的问题?还是Vista需要有其他的步骤? 请遇到过同样问题的兄弟提点。我的系统是Vista x64, VS2008,这里会不会还和64位系统有关系? 总觉得和.NET最有关系,因为非托管代码调用控件是好的。