从另一个类运行 ActiveX 函数时出现 System.AccessViolationException
我有这些课程:
Form1.cs
Server.cs
现在,当我在 Server.cs
form1.startCapture("C:\\test.mp4");
然后在 Form1.cs
public void startCapture(String filename)
{
short result = this.axVideoCap1.Start();
}
中执行操作时,我得到一个 System.AccessViolationException
System.Runtime.InteropServices.COMException was unhandled.
Message = An attempt was made to read or write protected memory. This is often an indication that other memory is corrupt.
Source = mscorlib
Stack Trace:
at System.RuntimeType.ForwardCallToInvokeMember (String membername, BindingFlags flags, Object target, Int32 [] aWrapperTypes, Message & msgData)
at VIDEOCAPLib._DVideoCap.Start ()
at AxVIDEOCAPLib.AxVideoCap.Start ()
...
我该如何解决此错误?
public void startCapture(String filename)
{
this.axVideoCap1.CaptureVideo = this.captureVideoCheckBox.Checked;
this.axVideoCap1.CaptureAudio = this.captureAudioCheckBox.Checked;
this.axVideoCap1.ShowPreview = this.showPreviewCheckBox.Checked;
this.axVideoCap1.UseVideoCompressor = this.useVideoCapCheckBox.Checked;
this.axVideoCap1.UseAudioCompressor = this.useAudioCapCheckBox.Checked;
this.axVideoCap1.CaptureMode = true;
this.axVideoCap1.CaptureFileName = filename;
this.axVideoCap1.SyncMode = 1;
short result = this.axVideoCap1.Start();
switch (result)
{
case -1:
MessageBox.Show("Capture Failure,Video, Audio Compressor not correct or capture file opening");
return;
case -2:
MessageBox.Show("Capture file not found");
return;
}
this.previewButton.Enabled = false;
this.captureButton.Enabled = false;
this.stopButton.Enabled = true;
}
I have these classes:
Form1.cs
Server.cs
Now when I do in Server.cs
form1.startCapture("C:\\test.mp4");
Then in Form1.cs
public void startCapture(String filename)
{
short result = this.axVideoCap1.Start();
}
I get then a System.AccessViolationException
System.Runtime.InteropServices.COMException was unhandled.
Message = An attempt was made to read or write protected memory. This is often an indication that other memory is corrupt.
Source = mscorlib
Stack Trace:
at System.RuntimeType.ForwardCallToInvokeMember (String membername, BindingFlags flags, Object target, Int32 [] aWrapperTypes, Message & msgData)
at VIDEOCAPLib._DVideoCap.Start ()
at AxVIDEOCAPLib.AxVideoCap.Start ()
...
How can I solve this error?
public void startCapture(String filename)
{
this.axVideoCap1.CaptureVideo = this.captureVideoCheckBox.Checked;
this.axVideoCap1.CaptureAudio = this.captureAudioCheckBox.Checked;
this.axVideoCap1.ShowPreview = this.showPreviewCheckBox.Checked;
this.axVideoCap1.UseVideoCompressor = this.useVideoCapCheckBox.Checked;
this.axVideoCap1.UseAudioCompressor = this.useAudioCapCheckBox.Checked;
this.axVideoCap1.CaptureMode = true;
this.axVideoCap1.CaptureFileName = filename;
this.axVideoCap1.SyncMode = 1;
short result = this.axVideoCap1.Start();
switch (result)
{
case -1:
MessageBox.Show("Capture Failure,Video, Audio Compressor not correct or capture file opening");
return;
case -2:
MessageBox.Show("Capture file not found");
return;
}
this.previewButton.Enabled = false;
this.captureButton.Enabled = false;
this.stopButton.Enabled = true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我修复了它,我在 Form1 中运行了无限循环。
Form1 启动 Server,Server 访问 Form1。
现在我创建了 Start.cs,它在第二个线程中启动 Server 和 Form1。
需要一些调用回调
I fixed it, I have run an infinite loop in Form1.
Form1 started Server and Server accessed Form1.
Now I created Start.cs that starts Server and Form1 in a second thread.
Needed some Invoke Callbacks