2017-04-27 32 views
2

我需要從C++傳遞字符串值到C庫。 你怎麼稱CppCallToC或.cpp我怎樣才能訪問struct rtmp_stream *stream;從C++如何執行一個方法或訪問C中的struct?

C++文件:UI /窗口鹼性-main.cpp中:

void OBSBasic::Load(const char *file) { 
    //From C++ how to go to the C method? 
    CppCallToC(); 
} 

C文件:插件/ OBS-輸出/ RTMP-stream.c:

static void CppCallToC() { 

    //https://github.com/jp9000/obs-studio/blob/master/libobs/util/dstr.h 
    //struct dstr  path, key; 
    struct rtmp_stream *stream; 
    //dstr_printf(&stream->path, obs_path); 
    //dstr_printf(&stream->key, obs_key); 
} 
+4

'std :: string'和引用不是'c'。 – Alex

+2

1.您不能在不同的功能中訪問局部變量; 2.無論如何你都不能調用這個函數 - 而且你不應該 - 因爲它是靜態的;這看起來像[XY問題](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)。 – molbdnilo

回答

5

您的問題是不一個C vs C++的問題。 rtmp-stream.c中的所有函數都聲明爲靜態的,這意味着它們具有內部鏈接,並且不能從其他編譯單元調用。您只能通過在文件尾部定義的rtmp_output_info結構間接訪問這些函數,並在obs-outputs.c中聲明,並且該聲明僅在該文件中可用。

我對OBS Studio一無所知,因此恐怕我無法幫到你。您將不得不跟蹤obs_register_output(&rtmp_output_info)中發生的情況。

相關問題