如何在 WP8 中从本机 c++ 与 UI 通信
How to talk to UI from native c++ in WP8?
我是WP8/c#的新手,新信息超载,肯定缺少一些东西。
我有使用本机代码库的wp8应用程序。如何通知 UI 有关本机代码的更改?我知道我无法将回调从 c# 函数传递到 wp8 上的本机 c++。下面的简单代码说明了我想要什么:
主页 cs(英文)
namespace phoneapp
{
public partial class MainPage : PhoneApplicationPage
{
testRT _testrt;
public MainPage()
{
_testrt= new testRT();
}
private void btnTest_Click(object sender, RoutedEventArgs e)
{
_testrt->foo();
}
}
}
运行时组件 CPP
namespace rtc
{
public ref class testRT sealed
{
public:
testRT();
void foo();
private:
test* _test;
};
}
testRT::testRT()
{
_test= new test();
}
testRT::foo()
{
_test->foothread();
}
原生类 CPP
test::test()
{
}
test::~test()
{
}
void test::foothread()
{
signal_UI_status("started");
while (notfinished)
{
//do something
...
signal_UI_results("found %i results", res);
}
signal_UI_status("finished");
}
在Windows Phone上实现这种"信号"功能的最佳方法是什么?回调?命名管道?套接字?
可以在 Windows 运行时中声明回调委托,并将 C# 函数传递回该委托。
public delegate void WinRtCallback(Platform::String^ resultString);
public ref class testRT sealed
{
public:
testRT();
void foo(WinRtCallback^ callback);
private:
test* _test;
};
或者更好的是,你可以让你的C++返回异步操作(通过IAsyncAction
和其他异步接口),但这要高级得多。
有关此内容的详细信息,请参阅MSDN,如"在C++中为Windows 应用商店应用程序创建异步操作",该操作也适用于Windows Phone应用程序。
相关文章:
- 如何在MS Visual Studio 2019中运行QT UI
- 如何处理使用.ui文件生成的.h文件
- 根据变量使Qt UI中的复选框为已选中/未选中
- 一旦双簧管录制开始,主 UI 线程就会被阻止
- Qt Quick,如何更改 Ui 源代码?
- QWidget UI 在使用 QQuickWidget 时冻结
- 在 3ds Max 中更新进度条后,环境和效果 UI 不刷新
- Qt - QQuickWidget setSource without freezing UI
- MFC/C++ ComboBox:禁用下拉列表关闭和打开(UI 冻结)的绘制
- Qt5 ui,多个窗口:如何从窗口 1 访问窗口 2 中的 UI 对象
- QtConcurrent - 在发布到 UI 线程的数千个结果中保持 GUI 响应
- 发出信号以从线程更新 UI
- 更好的文本UI调试C++器,如python的pudb
- 可以在JSON文件的帮助下在Qt中创建UI表单
- 在 ui 文件中隐藏 QTabWidget 中的单个选项卡窗格?
- 由于多个 *.ui 文件而导致的多个Ui_Dialog定义?
- 如何将 .ui 完全转换为 C++ 头文件和源文件
- CMake + Qt,moc 编译失败,无法实现 QMetaObject 方法(编译器找不到基本 ui 对象的标头?
- 如何创建一个接口,允许我访问C++中的按钮(和其他ui)函数,该函数是使用python中的MFC实现的
- QThread::create running on UI Thread