从 c++ 传递参数到 c# 作为回调
我有一个 C++ 和 C# 应用程序相互通信。
我的设置方式如下:
c++ 项目在 c# 项目中引用如下
< img src="https://i.sstatic.net/YXrGd.png" alt="在此处输入图像描述">
现在它会执行与此问题无关的各种操作。
需求是,c#会调用c++,然后c++会做c#的回调事件。以下是我在 C# 中注册回调的方式:
Add_CB_onVideoMediaReceived(OnVideoMediaReceived);
在 c++ 中,我有以下内容,它向事件添加回调
event OnVideoMediaReceived^ event_onVideoMediaReceived;
virtual void Add_CB_onVideoMediaReceived(OnVideoMediaReceived^ cb)
{
event_onVideoMediaReceived += cb;
}
现在在 c++ 中,我调用此方法,我必须触发对 c# 的回调
unsigned int height = data->GetStreamHeight();
unsigned int width = data->GetStreamWidth();
unsigned int bufferLength = data->GetBufferLen();
if (CMeetingRecordingControllerDotNetWrap::Instance)
{
if (data)
CMeetingRecordingControllerDotNetWrap::Instance->_VideoMediaReceived(
height,
width,
//data->GetStreamHeight(),
bufferLength);
//data->GetBuffer());
}
void CMeetingRecordingControllerDotNetWrap::_VideoMediaReceived(unsigned int userId, unsigned int screenHeight,unsigned int screenWidth) {
event_onVideoMediaReceived(userId, screenHeight,screenWidth);
}
这基本上会触发 c#然而,我在唯一的第一个参数中得到了正确的值。对于参数的其余部分,例如,如果我传递的值是 300 作为整数,我在 C# 中得到一个非常长的数字,如 12333445444 而不是 300。
这是我的 C# 接收器代码是
private void OnVideoMediaReceived(UInt32 userId, UInt32 screenHeight, UInt32 screenWidth)
{
Console.WriteLine("Username changed: user ID" + userId.ToString());
}
I have a c++ and c# application talking to each other.
The way I have set things up is as follows:
the c++ project is referred to in the c# project as follows
Now it does various things which are not something related to this question.
The requirement is, c# will call c++ and then c++ will do a callback event of c#. Here is how I have registered a call back in C#:
Add_CB_onVideoMediaReceived(OnVideoMediaReceived);
In c++, I have the following which is adding a callback to events
event OnVideoMediaReceived^ event_onVideoMediaReceived;
virtual void Add_CB_onVideoMediaReceived(OnVideoMediaReceived^ cb)
{
event_onVideoMediaReceived += cb;
}
Now in c++, I am calling this method where I have to trigger a call back to c#
unsigned int height = data->GetStreamHeight();
unsigned int width = data->GetStreamWidth();
unsigned int bufferLength = data->GetBufferLen();
if (CMeetingRecordingControllerDotNetWrap::Instance)
{
if (data)
CMeetingRecordingControllerDotNetWrap::Instance->_VideoMediaReceived(
height,
width,
//data->GetStreamHeight(),
bufferLength);
//data->GetBuffer());
}
void CMeetingRecordingControllerDotNetWrap::_VideoMediaReceived(unsigned int userId, unsigned int screenHeight,unsigned int screenWidth) {
event_onVideoMediaReceived(userId, screenHeight,screenWidth);
}
That basically triggers the c# event, however, I get the correct value in the only first argument. For the rest of the argument, if for example, the value that I pass is 300 as an integer, I get a very long number in c# like 12333445444 instead of 300.
This is my c# receiver code is
private void OnVideoMediaReceived(UInt32 userId, UInt32 screenHeight, UInt32 screenWidth)
{
Console.WriteLine("Username changed: user ID" + userId.ToString());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论