浅析C#调用ActiveX控件

开发 后端
本文介绍C#调用ActiveX控件编写播放器时,遇到了不少问题!发现MS.NET2003中缺少对一些动态链接库的引用。

C#调用ActiveX控件编写播放器时,遇到了不少问题!发现MS.NET2003中缺少对一些动态链接库的引用!在C#调用ActiveX控件等多媒体控件时,需要用到的MediaPlayer.dll 和 AxMediaPlayer.dll需要自己生成。首先用下面的命令为媒体播放器控件:msdxm.ocx 生成 MediaPlayer.dll 和 AxMediaPlayer.dll。

aximp c:\winnt\system32\msdxm.ocx

而通常msdxm.ocx中的ActiveX控件都未注册!再运行regsvr32 msdxm.ocx手动注册便生成需要的动态连接库文件.在项目中添加对MediaPlayer.dll 和 AxMediaPlayer.dll的引用,并在程序中插入:using MediaPlayer便完成了整个调用过程!

C#调用ActiveX控件源程序代码如下:

  1. usingSystem;  
  2. usingSystem.Drawing;  
  3. usingSystem.Collections;  
  4. usingSystem.ComponentModel;  
  5. usingSystem.Windows.Forms;  
  6. usingSystem.Data;  
  7. usingMediaPlayer;  
  8.  
  9. namespaceAdvancePlayer  
  10. {  
  11. /**////<summary> 
  12. ///Form1的摘要说明。  
  13. ///</summary> 
  14. publicclassForm1:System.Windows.Forms.Form  
  15. {  
  16. privateAxMediaPlayer.AxMediaPlayeraxWindowsMediaPlayer1;  
  17. privateSystem.Windows.Forms.OpenFileDialogopenFileDialog1;  
  18. privateSystem.Windows.Forms.MainMenumainMenu1;  
  19. privateSystem.Windows.Forms.MenuItemmenuItemOpen;  
  20. privateSystem.Windows.Forms.MenuItemmenuItemClose;  
  21. privateSystem.Windows.Forms.MenuItemmenuItemInitSize;  
  22. privateSystem.Windows.Forms.MenuItemmenuItemFullScreen;  
  23. privateSystem.Windows.Forms.MenuItemmenuItemShowAudioCtrl;  
  24. privateSystem.Windows.Forms.MenuItemmenuItemShowPositionCtrl;  
  25. privateSystem.Windows.Forms.MenuItemmenuItemShowTrackbarCtrl;  
  26. privateSystem.Windows.Forms.MenuItemmenuItemFile;  
  27. privateSystem.Windows.Forms.MenuItemmenuItemVideo;  
  28. privateSystem.Windows.Forms.MenuItemmenuItemWindow;  
  29.  
  30.  
  31. /**////<summary> 
  32. ///必需的设计器变量。  
  33. ///</summary> 
  34. privateSystem.ComponentModel.Containercomponents=null;  
  35.  
  36. publicForm1()  
  37. {  
  38. //  
  39. //Windows窗体设计器支持所必需的  
  40. //  
  41. InitializeComponent();  
  42.  
  43. //  
  44. //TODO:在InitializeComponent调用后添加任何构造函数代码  
  45. //  
  46. }  
  47.  
  48. /**////<summary> 
  49. ///清理所有正在使用的资源。  
  50. ///</summary> 
  51. protectedoverridevoidDispose(booldisposing)  
  52. {  
  53. if(disposing)  
  54. {  
  55. if(components!=null)  
  56. {  
  57. components.Dispose();  
  58. }  
  59. }  
  60. base.Dispose(disposing);  

【编辑推荐】

  1. C# Iterator迭代器模式
  2. 概述C# New运算符
  3. C# WiteOne学习笔记
  4. 用C# ListView显示数据记录
  5. C# ConfigDlg.cs源程序
责任编辑:佚名 来源: IT168
相关推荐

2009-08-06 16:58:40

C#编写ActiveX

2015-05-12 14:16:15

C#ActiveX控件web调用

2009-09-16 10:56:22

C#开发ActiveX

2009-08-27 14:32:15

C#编写ActiveX

2009-08-11 10:12:21

2009-08-11 14:45:41

C# DataGrid

2009-09-04 17:58:38

C# Web Brow

2009-08-28 15:05:35

C#编写Calenda

2009-08-04 09:30:33

C#调用ImageAn

2009-07-31 17:28:35

C#语言调用DLL

2009-08-14 09:15:28

C#调用构造函数

2009-09-09 10:47:29

C# CheckBox

2009-08-26 13:36:33

C#打印控件

2009-08-06 17:57:14

C# webServiC# WebServi

2009-09-11 10:41:20

C# WinForm控

2009-08-17 13:18:01

C#调用Windows

2009-08-28 16:31:21

C# treeview

2009-09-03 13:08:43

C#调用记事本

2009-09-08 14:54:40

C# listBox控

2009-08-21 11:24:16

C#异步调用
点赞
收藏

51CTO技术栈公众号