如何在c#中使用指向指针的指针?

zja*_*obs 0 c# pointers ffmpeg

我在Visual Studio 2012中使用C#来调用包含在我的项目所需的一组外部库中的函数.该函数需要传入一个双指针,但我不确定确切的语法.单指针对我很有用.我使用的是unsafe关键字.

AVFormatContext _file = new AVFormatContext();

fixed (AVFormatContext* p_file = &_file)
{
   avformat_alloc_output_context2(&p_file,null,null,filename);
}
Run Code Online (Sandbox Code Playgroud)

VS抱怨"&p_file"语法错误为"无法获取只读局部变量的地址".

任何帮助将非常感激!

Eri*_*ert 6

你不能取地址p_file因为p_file在固定块内是只读的.如果您可以获取其地址,那么这将是可能的:

fixed (AVFormatContext* p_file = &_file)
{
   AVFormatContext** ppf = &p_file;
   *ppf = null; // Just changed the contents of a read-only variable!
Run Code Online (Sandbox Code Playgroud)

因此,您必须获取可以更改的内容的地址:

fixed (AVFormatContext* p_file = &_file)
{
   AVFormatContext* pf = p_file;
   AVFormatContext** ppf = &pf;
Run Code Online (Sandbox Code Playgroud)

现在我们都很好; 变化*ppf不会改变p_file.