从另一个类运行 ActiveX 函数时出现 System.AccessViolationException

发布于 2025-01-07 14:53:45 字数 2019 浏览 3 评论 0原文

我有这些课程:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぶ宁プ宁ぶ 2025-01-14 14:53:45

我修复了它,我在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文