首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使摄像头设备对进程不可见

使摄像头设备对进程不可见
EN

Stack Overflow用户
提问于 2018-10-09 20:15:15
回答 1查看 190关注 0票数 0

一些背景:

我有一个应用程序,它在Windows 10 64位上打开第一个摄像头设备(无论在设备枚举期间索引0是什么),并对帧进行一些处理。无法访问应用程序的源代码。

问题:

我需要使这个应用程序在同一时间与两个网络摄像头工作。我想也许有一种方法可以做到以下几点:

  1. 隐藏网络摄像头2
  2. 运行应用程序(拾取摄像头1)
  3. 隐藏摄像头1,取消隐藏摄像头2
  4. 运行应用程序(拾取摄像头2)

有没有办法在不干扰摄像机操作的情况下做到这一点?请注意,这两个应用程序是在同一时间运行,所以硬-禁用一个相机不是一个选项。调用Win32 api或在PowerShell中这样做是可以接受的。

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-12 19:03:05

由于对我最初问题的评论,我设法通过连接到CM_Get_Device_Interface_List_ExW Win32 API调用来解决我的问题。

我必须验证调用了什么API,所以我使用了和API跟踪工具(API监视器v2 64位)。调试器也应该工作,但由于某种原因,我的VS调试器没有向我显示任何符号(可能缺少pdbs)。

我试图连接到的原始进程是用C#编写的,所以我通过注入的包含EasyHook的C# DLL连接到调用中。下面是我的代码片段(忽略了实际的注入代码):

代码语言:javascript
复制
using System;
using System.Runtime.InteropServices;

using EasyHook;

public class HookDevices : IEntryPoint
{
    LocalHook FunctionLocalHook;

    // construct this to hook into calls
    HookDevices()
    {
        try
        {
            FunctionLocalHook = LocalHook.Create(
                LocalHook.GetProcAddress("CfgMgr32.dll", "CM_Get_Device_Interface_List_ExW"),
                new FunctionHookDelegate(CM_Get_Device_Interface_List_Ex_Hooked),
                this);
            FunctionLocalHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
        }
        catch (Exception ExtInfo)
        {
            Debug.LogException(ExtInfo);
            return;
        }
    }

    [UnmanagedFunctionPointer(CallingConvention.StdCall,
        CharSet = CharSet.Unicode,
        SetLastError = true)]
    delegate uint FunctionHookDelegate(
        ref Guid interfaceClassGuid,
        string deviceID,
        IntPtr buffer,
        uint bufferLength,
        uint flags,
        IntPtr hMachine);

    [DllImport("CfgMgr32.dll",
        CharSet = CharSet.Unicode,
        SetLastError = true,
        CallingConvention = CallingConvention.StdCall)]
    static extern uint CM_Get_Device_Interface_List_ExW(
        ref Guid interfaceClassGuid,
        string deviceID,
        IntPtr buffer,
        uint bufferLength,
        uint flags,
        IntPtr hMachine);

    // this is where we are intercepting all API accesses!
    static uint CM_Get_Device_Interface_List_Ex_Hooked(
        ref Guid interfaceClassGuid,
        string deviceID,
        IntPtr buffer,
        uint bufferLength,
        uint flags,
        IntPtr hMachine)
    {
        // pass-through original API
        uint ret = CM_Get_Device_Interface_List_ExW(
            ref interfaceClassGuid,
            deviceID,
            buffer,
            bufferLength,
            flags,
            hMachine);
        // do custom logic here and re-arrange "buffer"
        return ret;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52728671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档