C++ cli 我怎样才能在编解码器';它还会显示每个编解码器的类型吗?

C++ cli 我怎样才能在编解码器';它还会显示每个编解码器的类型吗?,c++-cli,C++ Cli,每个编解码器的类型或编解码器的 在我最后的列表中,我想要大约500个编解码器,例如在开始的列表中,它将显示例如: 音频 姆佩哈 mpegv ..... 视频 十六 迪沃斯 等等 获取编解码器列表的前两个函数是C语言: const char* Encoder_GetNextCodecName() { current_codec = av_codec_next(current_codec); while (current_codec != NULL) {

每个编解码器的类型或编解码器的 在我最后的列表中,我想要大约500个编解码器,例如在开始的列表中,它将显示例如:

音频 姆佩哈 mpegv ..... 视频 十六 迪沃斯

等等

获取编解码器列表的前两个函数是C语言:

const char* Encoder_GetNextCodecName()
{
    current_codec = av_codec_next(current_codec);
    while (current_codec != NULL)
    {       
        return current_codec->name;
    }
    return "";
}

const char* Encoder_GetFirstCodecName()
{
    current_codec = NULL;
    return Encoder_GetNextCodecName();
}
然后我有头文件:

const char* Encoder_GetNextCodecName();
const char* Encoder_GetFirstCodecName();
< P>然后在我创建列表的另一个C++头文件:

List<String^> ^GetCodecs()
    {
        List<String^> ^l = gcnew List<String^>;

        String ^s = gcnew String(Encoder_GetFirstCodecName());
        while (!String::IsNullOrEmpty(s))
        {
            l->Add(s);
            s = gcnew String(Encoder_GetNextCodecName());
        }

        return l;
     }
它们有很多特性。 在C文件中也有类似的内容:

AVMediaType::
这给了我7种类型的编解码器

问题是,当我创建列表时,在C++列表头文件中,我将如何使用每个编解码器的类型或每个编解码器组的类型:音频、视频、数据……p> 编辑

这是连接C函数和CLI的另一个头文件:

我有另一个头文件,我第一次从C调用函数:

ifdef __cplusplus
extern "C"
{
#endif

#include <stdint.h>

bool Encoder_MoveToNextCodec();
bool Encoder_MoveToFirstCodec();
const char* Encoder_GetCurrentCodecName();
int Encoder_GetCurrentCodecType();

#ifdef __cplusplus
}    // extern "C"
#endif
ifdef\uu cplusplus
外部“C”
{
#恩迪夫
#包括
bool编码器_MoveToNextCodec();
bool编码器_MoveToFirstCodec();
const char*编码器_getCurrentCodeName();
int编码器_GetCurrentCodeType();
#ifdef_uucplusplus
}//外部“C”
#恩迪夫
这是我的CLI代码:

#pragma once



// FFMPEG_WRAPPER.cpp : Defines the exported functions for the DLL application.
//
#include "ENCODER.h"

#include <stdlib.h>
#include <string.h>
#include <msclr\marshal.h>
#include <vcclr.h>
#include <cstdlib>
#include <Windows.h>

using namespace System;
using namespace System::Drawing;
using namespace System::Collections::Generic;
using namespace System::Runtime::InteropServices;
using namespace System::Drawing::Imaging;

using namespace msclr::interop;

namespace MyVideo
{

public ref class FFMPEGWrapper
{
public:
    FFMPEGWrapper(void)
    {

        Encoder_init();

    }

ref class CodecInfo
{
public:
    String^ CodecName;
    int CodecType;
};

List<CodecInfo^> ^GetCodecs()
{
    List<CodecInfo^> ^l = gcnew List<CodecInfo^>;

    bool KeepLooping = Encoder_MoveToFirstCodec();
    while (KeepLooping)
    {
        CodecInfo ^codec = gcnew CodecInfo();

        codec->CodecName = gcnew String(Encoder_GetCurrentCodecName());
        codec->CodecType = Encoder_GetCurrentCodecType();


        l->Add(codec);
        KeepLooping = Encoder_MoveToNextCodec();
    }

    return l;
 }
#pragma一次
//FFMPEG_WRAPPER.cpp:定义DLL应用程序的导出函数。
//
#包括“编码器.h”
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间系统;
使用名称空间系统::绘图;
使用命名空间System::Collections::Generic;
使用名称空间System::Runtime::InteropServices;
使用名称空间System::Drawing::Imaging;
使用名称空间msclr::interop;
名称空间MyVideo
{
公共参考类FFMPEGWrapper
{
公众:
FFMPEGWrapper(无效)
{
编码器_init();
}
参考类编码信息
{
公众:
字符串^code名称;
int编码类型;
};
列表^GetCodecs()
{
列表^l=gcnew列表;
bool keeploping=编码器_MoveToFirstCodec();
同时(继续)
{
CodecInfo^codec=gcnew CodecInfo();
编解码器->编解码器名称=gcnew字符串(编码器_getCurrentCodeName());
编解码器->编解码器类型=编码器_GetCurrentCodeType();
l->添加(编解码器);
keeploping=Encoder_MoveToNextCodec();
}
返回l;
}
然后在CSHARP中我做了:

List<f.CodecInfo> l = f.GetCodecs();
List l=f.GetCodecs();
但是CodecInfo不存在,我在GetCodecs()上得到一个错误

错误1无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List”

错误2“ScreenVideoRecorder.Form1.f”是一个“字段”,但与“类型”一样使用


错误所在的问题在CSHARP中。

您需要扩展C代码以公开所需的额外详细信息,例如:

__declspec(thread) AVCodec* current_codec = NULL;

bool Encoder_MoveToNextCodec()
{
    current_codec = av_codec_next(current_codec);
    return (current_codec != NULL);
}

bool Encoder_MoveToFirstCodec()
{
    current_codec = NULL;
    return Encoder_MoveToNextCodec();
}

const char* Encoder_GetCurrentCodecName()
{
    if (current_codec != NULL)
        return current_codec->name;
    return "";
}

int Encoder_GetCurrentCodecType()
{
    if (current_codec != NULL)
        return (int) current_codec->type;
    return AVMEDIA_TYPE_UNKNOWN;
}
然后展开CLI代码以存储该信息:

ref class CodecInfo
{
public:
    String^ CodecName;
    int CodecType;
    ...
};

List<CodecInfo^> ^GetCodecs()
{
    List<CodecInfo^> ^l = gcnew List<CodecInfo^>;

    bool KeepLooping = Encoder_MoveToFirstCodec();
    while (KeepLooping)
    {
        CodecInfo ^codec = gcnew CodecInfo();

        codec->CodecName = gcnew String(Encoder_GetCurrentCodecName());
        codec->CodecType = Encoder_GetCurrentCodecType();
        ...

        l->Add(codec);
        KeepLooping = Encoder_MoveToNextCodec();
    }

    return l;
 }
ref class CodecInfo
{
公众:
字符串^code名称;
int编码类型;
...
};
列表^GetCodecs()
{
列表^l=gcnew列表;
bool keeploping=编码器_MoveToFirstCodec();
同时(继续)
{
CodecInfo^codec=gcnew CodecInfo();
编解码器->编解码器名称=gcnew字符串(编码器_getCurrentCodeName());
编解码器->编解码器类型=编码器_GetCurrentCodeType();
...
l->添加(编解码器);
keeploping=Encoder_MoveToNextCodec();
}
返回l;
}
最后,根据需要使用新信息:

List<CodecInfo> l = f.GetCodecs();
foreach(CodecInfo codec in l)
{
    // use codec.CodecName, codec.CodecType, ... as needed
}
List l=f.GetCodecs();
foreach(编解码器信息编解码器,l)
{
//根据需要使用codec.CodecName、codec.CodecType等
}

<代码>你所使用的语言不是C++而不是C++。它被称为“C++ + CLI”。它的名字和C++非常不同。标签更新。在CSHARP中的ReMe没有列表。CODECKION不存在。里米,我正在更新我的问题。请看它。用错误和问题来更新我的问题。CSHARP@YaronCohenMinz:显然,您必须在C#中定义一个与C++CLI中的类型匹配的
CodecInfo
类型。
ref class CodecInfo
{
public:
    String^ CodecName;
    int CodecType;
    ...
};

List<CodecInfo^> ^GetCodecs()
{
    List<CodecInfo^> ^l = gcnew List<CodecInfo^>;

    bool KeepLooping = Encoder_MoveToFirstCodec();
    while (KeepLooping)
    {
        CodecInfo ^codec = gcnew CodecInfo();

        codec->CodecName = gcnew String(Encoder_GetCurrentCodecName());
        codec->CodecType = Encoder_GetCurrentCodecType();
        ...

        l->Add(codec);
        KeepLooping = Encoder_MoveToNextCodec();
    }

    return l;
 }
List<CodecInfo> l = f.GetCodecs();
foreach(CodecInfo codec in l)
{
    // use codec.CodecName, codec.CodecType, ... as needed
}