c# - 委托如何返回字符串生成器?
问题描述
第一的
delegate System.Text.StringBuilder get_content_func(uint i);
然后
get_content_func func = _content;
System.IntPtr p = Marshal.GetFunctionPointerForDelegate(func);//error - stack over flow
并且 'p' 将被注册到 c++,并会在某个时间回调以获取字符串内容。c++部分
typedef char* (__stdcall* GetContenFunc)(unsigned int id);//char*
void register_get_page_content(GetContenFunc GetHandle) {
g_GetHandle = GetHandle;//g_GetHanle is a global pointer
}
//func to call g_GetHandle
void get_page(guid id) {
char* content;
if (g_GetHandle != nullptr) {
content = g_GetHandle(id);
}
}
目的是从方法 '_content' 中获取字符串,该方法用于发送到 cpp 以执行其他操作。'p' 将是一个回调函数,用于通过 stringbuilder 获取内容。但是失败了,怎么解决?
解决方案
推荐阅读
- c# - 在 C# 代码中使用 DeviceIoControl 总是返回空的输出缓冲区
- regex - 具有随机顺序元素的正则表达式匹配组
- c - 如何将 2 个不同的文本文件改组为 1 个?
- intellij-idea - IntelliJ 无法识别 Cucumber ParameterType
- ios - Cordova iOS 应用程序关闭会在几分之一秒内显示默认的 Cordova 应用程序图标,然后显示自定义应用程序图标
- rest - Flutter 更改 TextEditController 上的 ListView 以进行搜索
- react-native - 无法在 react-native 中异步执行 sqlite db 查询
- java - 如何让 SwingUtilities.invokeLater 更快地执行任务?
- javascript - 在 jquery 中使用 .clone() 时如何停止克隆在元素内输入的文本
- google-chrome - 使用 VSCode 扩展 Debugger for Chrome 同时运行多个项目