小编snk*_*snk的帖子

无法将winform控件大小传递给非托管代码

我使用非托管库来从IP Camera获取视频流.有功能:

[DllImport("client.dll", EntryPoint = "Network_ClientStartLive", SetLastError = true)]
protected static extern int Network_ClientStartLive(
        ref IntPtr pStream,
        IntPtr hDev,
        IntPtr pClientInfo,
        [MarshalAs(UnmanagedType.FunctionPtr)] ReadDatacbf lpfnCallbackFunc = null,
        UInt32 dwUserData = 0
    );
Run Code Online (Sandbox Code Playgroud)

pClientInfo是一个指向结构类型的指针:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
protected struct LiveConnect
{
    public UInt32 dwChannel;
    public IntPtr hPlayWnd;
    public UInt32 dwConnectMode;
}
Run Code Online (Sandbox Code Playgroud)

其中hPlayWnd是必须输出视频流的窗口句柄.该库通过此窗口的大小(在调用期间Network_ClientStartLive)检测视频分辨率.我在C++ MFC程序上检查了它,其中输出窗口是Picture control通过设置大小和方法MoveWindow定义的输出视频分辨率.

在这个程序的C#版本中,我使用PictureBox-control来绘制视频流.显示视频,但其大小PictureBox不影响视频流分辨率.我尝试了几种方法来改变PictureBox大小:

  1. 设置 pictureBox.Size
  2. 使用WinAPI SetWindowPos:
[DllImport("user32.dll")]
private static extern bool …

c# c++ mfc winforms

8
推荐指数
1
解决办法
491
查看次数

使用std :: vector :: emplace_back

我有一些std :: thread的类warper.这是构造函数:

template <typename Function, typename... Args>
InterruptibleThread(Function&& fun, Args&&... args)
{
    _thread = std::thread([](std::atomic_bool * f, Function&& function, Args&&... arguments)
    {
        _flag_ref = f;
        (function)(std::forward<Args>(arguments)...);
    },
        &_flag,
        std::forward<Function>(fun)
        , std::forward<Args>(args)...
        );
}
Run Code Online (Sandbox Code Playgroud)

然后我正在使用它(例子):InterruptibleThread(&SourceImageList :: StartFrameProcessingStatic,this,std :: ref(it))

编译器成功构建此代码.但现在我想制作一个这样的对象的矢量:

std::vector<InterruptibleThread> grp;
Run Code Online (Sandbox Code Playgroud)

我想在堆栈上分配它,所以我正在做的是:

grp.emplace_back(&SourceImageList::StartFrameProcessingStatic, this, std::ref(it));
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

C2064   term does not evaluate to a function taking 0 arguments
Run Code Online (Sandbox Code Playgroud)

以下是编译器验证的选项:

1) grp.push_back(new InterruptibleThread(&SourceImageList::StartFrameProcessingStatic, this, std::ref(it)));
2) grp.push_back(InterruptibleThread(&SourceImageList::StartFrameProcessingStatic, this, std::ref(it)));
Run Code Online (Sandbox Code Playgroud)

但第一个是在堆上分配一个对象,所以我需要手动释放它,第二个是对象的副本.

我可以emplace_back在这里使用(编译器是MSVC 2015更新3)吗?

更新

好的,我根据答案做了一些修复.这是这个类的最终版本:

#pragma once
#include <exception>
#include …
Run Code Online (Sandbox Code Playgroud)

c++ vector std c++11

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

标签 统计

c++ ×2

c# ×1

c++11 ×1

mfc ×1

std ×1

vector ×1

winforms ×1