使用回调在c#中访问C导出的dll函数

时间:2017-02-27 02:52:50

标签: c# c dll callback

我正在尝试使用c#创建自定义OBS UI。 OBS是一种录制/流媒体软件,可以录制窗口或屏幕或其他一些东西。我找到了这个C#包装器 https://github.com/GoaLitiuM/libobs-sharp 但不幸的是它没有记录或流的能力,所以我试图自己实现。

我从https://github.com/jp9000/obs-studio/blob/master/UI/obs-frontend-api/obs-frontend-api.h导入了obs_frontend_recording_start()和obs_frontend_recording_stop(),但是当我调用这些函数时,我收到一条错误,说明试图调用(func name)而没有回调。我调查了它并尝试使用委托来调用这些函数:

NSWindow *window = self.tableView.window;
CGRect screenRowRect = [window convertRectToScreen:windowRowRect];

然后在我的主程序中,当我按下按钮时它应该这样做

public class Recording
{
    public delegate void StartRecord();
    public delegate void StopRecord();
    public Recording()
     {
        StartRecord d1 = new StartRecord(StartRecording);
        StopRecord d2 = new StopRecord(StopRecording);

    }


    public void StartRecording()
    {
        libobs.obs_frontend_recording_start();

    }


    public void StopRecording()
    {
        libobs.obs_frontend_recording_stop();
    }

执行此操作后,有关回调的原始错误消失了,但在停止录制后我没有得到任何反馈或录音。

编辑:这就是我导入函数的方式

 private void rec_Click(object sender, EventArgs e)
    {
        Recording.StartRecord d1 = new Recording.StartRecord(StartRecording);
        Recording.StopRecord d2 = new Recording.StopRecord(StopRecording);

        if (!isRec) {
            rec.Image = Properties.Resources.RecordingOnButton_small;
            d1();
            isRec = true;
        }
        else
        {
            rec.Image = Properties.Resources.RecordOffButton_small;
            d2();
            isRec = false;
        }

    }

0 个答案:

没有答案
相关问题