小编int*_*753的帖子

将字符串从C#传递给C DLL

我试图将字符串从C#传递给C DLL.从我读到的.NET应该为我做从字符串到char*的转换,但是我得到"错误CS1503:参数'1':无法从'字符串'转换为'字符*'"有人可以告诉我我在哪里出了什么问题?谢谢.

C#代码

[DllImport("Source.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static unsafe extern bool StreamReceiveInitialise(char* filepath);

const string test = "test";
// This method that will be called when the thread is started
public void Stream()
{
    if (StreamReceiveInitialise(test))
    {


    }
}
Run Code Online (Sandbox Code Playgroud)

C DLL

extern "C"
{
    __declspec(dllexport) bool __cdecl StreamReceiveInitialise(char* filepath);
}
Run Code Online (Sandbox Code Playgroud)

c c# string dll char

6
推荐指数
1
解决办法
5625
查看次数

ffmpeg libx264 AVCodecContext 设置

我正在使用最近的 Windows(2011 年 1 月)ffmpeg 构建并尝试以 H264 录制视频。使用以下设置可以很好地录制 MPEG4:

c->codec_id = CODEC_ID_MPEG4;
c->codec_type = AVMEDIA_TYPE_VIDEO;
c->width = VIDEO_WIDTH;
c->height = VIDEO_HEIGHT;
c->bit_rate = c->width * c->height * 4;
c->time_base.den = FRAME_RATE;
c->time_base.num = 1;
c->gop_size = 12;
c->pix_fmt = PIX_FMT_YUV420P;
Run Code Online (Sandbox Code Playgroud)

仅将 CODEC Id 更改为 H264 会导致 avcodec_open() 失败 (-1)。我找到了可能的设置列表如何使用 libavcodec/x264 编码 h.264?。我已经尝试过这些,没有设置 pix_fmt,avcodec_open() 仍然失败,但如果我另外设置 c->pix_fmt = PIX_FMT_YUV420P; 然后我得到除以零的异常。

然后我在这里看到了一些帖子,说我不应该设置任何内容(除了 code_id、codec_type、宽度、高度,也许还有 bit_rate 和 pix_fmt),因为库现在会自行选择最佳设置。我尝试了各种组合, avcode_open() 仍然失败。

有人对该怎么做或一些当前的设置有一些建议吗?

谢谢。

以下是一组 H264 设置,它们给出了我所描述的问题:

static AVStream* AddVideoStream(AVFormatContext *pOutputFmtCtx, 
int frameWidth, int frameHeight, …
Run Code Online (Sandbox Code Playgroud)

windows ffmpeg libavcodec libx264

5
推荐指数
1
解决办法
9333
查看次数

如果是整数,则使用 sprintf 格式化没有小数位的浮点数

最初,我使用带有浮点数的 sprintf 始终使用以下代码保留 2 个小数位:

static void MyFunc(char* buffer, const float percentage)
{
    sprintf(buffer, "%.2f", percentage);
}
Run Code Online (Sandbox Code Playgroud)

传递的百分比值之一是 0x419FFFFF 20(调试器视图),这将 20.00 打印到缓冲区中。

当不是整数时,我想显示 2 个小数位,例如

94.74 displayed as 94.74
94.7  displayed as 94.70
0     displayed as 0
5     displayed as 5
100   displayed as 100
Run Code Online (Sandbox Code Playgroud)

我目前正在使用以下代码:

static void MyFunc(char* buffer, const float percentage)
{
    int fractional_part = ((percentage - (int)percentage) * 100);
    if (0 == fractional_part)
    {
        sprintf(buffer, "%d", (int)percentage);
    }
    else
    {
        sprintf(buffer, "%.2f", percentage);
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,如果通过 0x419FFFFF …

c floating-point printf

3
推荐指数
1
解决办法
5万
查看次数

标签 统计

c ×2

c# ×1

char ×1

dll ×1

ffmpeg ×1

floating-point ×1

libavcodec ×1

libx264 ×1

printf ×1

string ×1

windows ×1