首页 > 解决方案 > 委托如何返回字符串生成器?

问题描述

第一的

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++delegatesmarshallingstringbuilder

解决方案


推荐阅读