110,913
社区成员
int GGCAM_InitDevice()
{
int v1; // eax
sub_10003350(dword_101BE1F0, "CGGCAM_InitDevice-start");
dword_101BE6D4 = CreateGGCameraHandle();
if ( !dword_101BE6D4 )
{
sub_10003350(dword_101BE1F0, "camHandle == NULL");
byte_101BE4CA = 0;
return 0;
}
if ( (unsigned __int8)sub_10002BC0(2760, 13168, 0) && (unsigned __int8)sub_10002BC0(3141, 25408, 0) )
{
v1 = 6;
dword_101BE4CC = 6;
LABEL_12:
byte_101BE4CA = 1;
sub_10003350(dword_101BE1F0, "CGGCAM_InitDevice-end,%d", v1);
return dword_101BE4CC;
}
if ( (unsigned __int8)sub_10002BC0(11674, 25344, 4626)
&& (unsigned __int8)sub_10002BC0(11674, 25360, 4102)
&& (unsigned __int8)sub_10002BC0(11674, 25376, 8197) )
{
v1 = 9;
dword_101BE4CC = 9;
goto LABEL_12;
}
if ( (unsigned __int8)sub_10002BC0(5075, 21525, 0) )
{
dword_101BE4CC = 888;
sub_10003350(dword_101BE1F0, byte_1016EEE4);
v1 = dword_101BE4CC;
goto LABEL_12;
}
byte_101BE4CA = 0;
sub_100094FA(&unk_1016EF00, 0, 0);
return 0;
}
int __thiscall GGCAM_GetTotalDeviceNum(void *this)
{
int result; // eax
void *v2; // [esp+0h] [ebp-4h] BYREF
v2 = this;
sub_10003350(dword_101BE1F0, "CGGCAM_GetTotalDeviceNum-start");
if ( byte_101BE4CA )
{
v2 = 0;
((void (__stdcall *)(int, void **))GetVideoDeviceNum)(dword_101BE6D4, &v2);
sub_10003350(dword_101BE1F0, "CGGCAM_GetTotalDeviceNum-end, total=%d", v2);
result = (int)v2;
}
else
{
sub_10003350(dword_101BE1F0, "CAM not init");
result = 0;
}
return result;
}
DLL文件:CameraControl.dll链接: https://caiyun.139.com/m/i?014MchibaXQ5v 提取码:PV1g
CGGCamera.dll链接: https://caiyun.139.com/m/i?014McNhs5tcen 提取码:J6bE
只需要能获取数量就行了。。。。
在C#中,不直接操作内存地址或者直接调用Windows API函数,而是通常使用封装好的类库或者P/Invoke来调用外部函数。因此,这段代码的转换会涉及到一些假设,特别是关于外部调用的处理。下面是一个可能的转换:
using System;
using System.Runtime.InteropServices;
public static class GGCAM
{
private static IntPtr camHandle = IntPtr.Zero;
private static bool isInitialized = false;
private static int lastInitResult = 0;
[DllImport("SomeExternalDLL.dll", CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr CreateGGCameraHandle();
[DllImport("SomeExternalDLL.dll", CallingConvention = CallingConvention.StdCall)]
private static extern bool GetVideoDeviceNum(IntPtr handle, out int num);
[DllImport("SomeExternalDLL.dll", CallingConvention = CallingConvention.StdCall)]
private static extern bool SubFunction(int param1, int param2, int param3);
public static int InitDevice()
{
Log("CGGCAM_InitDevice-start");
camHandle = CreateGGCameraHandle();
if (camHandle == IntPtr.Zero)
{
Log("camHandle == NULL");
isInitialized = false;
return 0;
}
if (SubFunction(2760, 13168, 0) && SubFunction(3141, 25408, 0))
{
lastInitResult = 6;
}
else if (SubFunction(11674, 25344, 4626) &&
SubFunction(11674, 25360, 4102) &&
SubFunction(11674, 25376, 8197))
{
lastInitResult = 9;
}
else if (SubFunction(5075, 21525, 0))
{
lastInitResult = 888;
}
else
{
isInitialized = false;
Log("Initialization failed in an unknown way.");
return 0;
}
isInitialized = true;
Log($"CGGCAM_InitDevice-end, {lastInitResult}");
return lastInitResult;
}
public static int GetTotalDeviceNum()
{
Log("CGGCAM_GetTotalDeviceNum-start");
if (!isInitialized)
{
Log("CAM not init");
return 0;
}
int totalNum = 0;
GetVideoDeviceNum(camHandle, out totalNum);
Log($"CGGCAM_GetTotalDeviceNum-end, total={totalNum}");
return totalNum;
}
private static void Log(string message)
{
// Implement logging mechanism here
Console.WriteLine(message);
}
}
在这个转换中,我做了以下假设和调整:
①外部函数调用:我使用了DllImport来声明外部函数(CreateGGCameraHandle, GetVideoDeviceNum, 和一个假定的 SubFunction 代表 sub_10002BC0)。这些函数的确切声明可能需要根据实际的DLL和函数签名进行调整。
②日志记录:原始代码中的sub_10003350函数似乎用于日志记录。在C#中,我创建了一个简单的Log方法来模拟这个行为,但实际上你可能需要根据你的应用程序的日志记录机制来实现它。
③全局变量:原始代码中使用的全局变量(如dword_101BE6D4和byte_101BE4CA)在C#版本中被转换为静态字段。
④类型转换和数据类型:C++代码中的某些数据类型和操作(如指针和类型转换)在C#中有所不同,因此在转换过程中进行了适当的调整。
请注意,由于缺少原始环境和完整上下文,这个转换可能需要进一步的调整才能完全符合实际需求。
写了一段句柄可以获取但是数量就是没有,因为是新手不知道是那错了。
public partial class Form1 : Form
{
private int hHwnd;
[DllImport("CameraControl.dll", EntryPoint = "CreateGGCameraHandle", ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
public static extern int CreateGGCameraHandle();
[DllImport("CameraControl.dll", EntryPoint = "GetVideoDeviceNum", ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
public static extern int GetVideoDeviceNum(int jj,int kk);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
hHwnd = CreateGGCameraHandle();
MessageBox.Show(hHwnd.ToString());
}
private void button2_Click(object sender, EventArgs e)
{
int jkl = GetVideoDeviceNum(hHwnd, 0);
MessageBox.Show(jkl.ToString());
}
}