c#调用COM控件的几个问题
一个原厂商的视频客户端软件提供了COM组件用于集成的开发,该组件中提供了两个类SparkControl、VideoPanel以及相应的接口ISparkControl、IVideoControl等。SparkControl是用来注册及呼叫控制的,VideoPanel是用来视频输出及控制的。在IE浏览器中实现完全正常,主要代码如下:<HEAD>
<object classid="clsid:D87806E5-29DB-4207-8CB5-E8731E843422"
id="SparkControl"
event="EstablishedEvent(connID)"
event="HeldEvent (nConnectionId)"
event="UnheldEvent(nConnectionId)"
event="SessionCreatedEvent (nConnectionId)"
event="SessionUpdatedEvent(nConnectionId)"
event="SessionEndedEvent(nConnectionId)"
event="VideoMuteStateEvent(status,reason)"
event="IncomingSessionEvent(nConnectionId)"
>
</object>
<script type="text/javascript">
var NumberToCall = "3601";
var ConnectionID = 0;
var Spark = null;
function Register_Spark()
{
try
{
Spark = document.getElementById("SparkControl");
Spark.Register(null);
}
catch(err)
{
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.description + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
return false;
}
return true;
}
//这里还有一些其它的函数未列出
</script>
</HEAD>
<BODY onunload="OnPageUnLoad()">
<center>
<object classid="clsid:144E3A3C-78BF-4d7a-9E21-02B38862D9E7"
width="640" height="480" id="videoControl">
<param name="EnablePIP" value="0"
event="RemoteVideoSizeChangedEvent(width,height)"
event="VideoSignalingIdleChangedEvent(connectionId,videoIdleReason)"
event="VideoStateChangedEvent(nVideoState,sMessage)"
/>
</object>
<script type="text/javascript">
function videoControl::VideoStateChangedEvent(nVideoState,sMessage)
{
//alert("VideoStateChangedEvent:"+nVideoState+":"+sMessage);
}
function videoControl::RemoteVideoSizeChangedEvent(width,height)
{
document.getElementById("videoEvent").style.backgroundColor = "green";
document.getElementById("videoEvent").innerHTML =
"RemoteVideoSizeChanged "+" Width: "+ width + " Height: "+ height;
//alert("RemoteVideoSizeChanged:"+width+":"+height);
}
function videoControl::VideoSignalingIdleChangedEvent(connectionId,videoIdleReason)
{
document.getElementById("videoEvent").style.backgroundColor = "Tomato";
document.getElementById("videoEvent").innerHTML =
"VideoSignalingIdleChangedEvent "+" connectionId: "+ connectionId + " videoIdleReason: " +videoIdleReason;
//alert("VideoSignalingIdleChanged : "+ connectionId +": "+videoIdleReason);
}
</script
</center>
<hr>
<div id="videoEvent">
<font color="DarkCyan"> No VideoEvent fired!</font>
</div>
<hr>
//剩下一些按钮的定义等
第一个问题:对象SparkControl是放在HEAD中,而VideoControl是放在BODY中,有什么讲究吗?
我在C#中通过SparkControl实例化后直接调用其方法,可以实现客户端的注册和控制。代码如下:
public partial class Form1 : Form
{
string num="3010";
SparkControl Spark = new SparkControl();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Spark.Register(null);
Spark.MakeCall(num);
}
第二个问题:好像可以直接对类实例化后使用其方法进行客户端软件的控制,不需要ISparkControl这个接口。是这样的吗?如果是这样的话,厂家提供ISparkControl的这个接口有什么用?
这两个问题还不影响我的工作,但第三个问题却困扰了很久。我按照SparkControl同样的方法对类VideoPanel进行实例话,在调用其方法时,系统报错告诉我VideoControl没有初始化!
VideoPanel下的方法有:
VideoPanel.AcquireCamera()
VideoPanel.Dispose(bool)
VideoPanel.IsCameraSelectionFailure()
VideoPanel.ReleaseCamera()
VideoPanel.TerminateVideo()
VideoPanel.UpdateCameraState(bool, string)
VideoPanel.UpdateFormSize()
VideoPanel.VideoPanel()
属性有:
VideoPanel.CameraDevices
VideoPanel.CameraNotConnectedText
VideoPanel.EnableH264
VideoPanel.LocalVideoWindowPosition
VideoPanel.LocalVideoWindowSize
VideoPanel.PreferredCamera
VideoPanel.VideoBitRate
VideoPanel.VideoCameraAcquringText
VideoPanel.VideoQuality
事件有:
VideoPanel.RemoteVideoSizeChangedEvent
VideoPanel.VideoSignalingIdleChangedEvent
并且有一个IVideoControl的接口,接口中的方法和属性与VideoPanel中类似的。
第三个问题是:我不知道如何进行VideoControl的初始化,我也认为需要初始化。
并且
int LocalVideoWindowSize { set; get; }
int LocalVideoWindowPosition { set; get; }
这两个属性的设置也存在问题,我不知如何把窗口的位置及大小告诉它!
期待您的帮助,我刚学习编程。先谢了!
补充:.NET技术 , C#