一些背景:
我有一个应用程序,它在Windows 10 64位上打开第一个摄像头设备(无论在设备枚举期间索引0是什么),并对帧进行一些处理。无法访问应用程序的源代码。
问题:
我需要使这个应用程序在同一时间与两个网络摄像头工作。我想也许有一种方法可以做到以下几点:
有没有办法在不干扰摄像机操作的情况下做到这一点?请注意,这两个应用程序是在同一时间运行,所以硬-禁用一个相机不是一个选项。调用Win32 api或在PowerShell中这样做是可以接受的。
谢谢!
发布于 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连接到调用中。下面是我的代码片段(忽略了实际的注入代码):
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;
}
}https://stackoverflow.com/questions/52728671
复制相似问题