Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
290 views
in Technique[技术] by (71.8m points)

C#: Error calling the camera on the tablet of Microsoft Surface-win10

[DllImport("avicap32.dll")]
public static extern bool capGetDriverDescriptionA(short wDriver, byte[] lpszName, int cbName, byte[] lpszVer, int cbVer);

[DllImport("avicap32.dll")]
public static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);

[DllImport("User32.dll")]
public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, int lParam);

[DllImport("User32.dll")]
public static extern bool SendMessage(IntPtr hWnd, int wMsg, bool wParam, int lParam);

public const int WM_USER = 0x400; 
public const int WS_CHILD = 0x40000000; 
public const int WS_VISIBLE = 0x10000000; 
public const int WM_CAP_DRIVER_CONNECT = WM_USER + 10; 
public const int WM_CAP_DRIVER_DISCONNECT = WM_USER + 11; 
public const int WM_CAP_SET_PREVIEW = WM_USER + 50; 
public const int WM_CAP_SET_PREVIEWRATE = WM_USER + 52; 

byte[] lpszName = new byte[100];
byte[] lpszVer = new byte[100];
capGetDriverDescriptionA(0, lpszName, 100, lpszVer, 100);
IntPtr lwndC = capCreateCaptureWindowA(lpszName, WS_VISIBLE + WS_CHILD, 0, 0, mWidth, mHeight, mControlPtr, 0);

//When the program runs to the following code, a camera selection dialog box (Microsoft Camera Front/Microsoft Camera Rear) appears. After selecting any of them, the code in the if statement is not executed,and the camera cannot run normally. Can anyone help me? Why is this happening, thank you.

if (SendMessage(lwndC, VideoAPI.WM_CAP_DRIVER_CONNECT, 0, 0))
{
    SendMessage(lwndC, WM_CAP_SET_PREVIEWRATE, 66, 0);
    SendMessage(lwndC, WM_CAP_SET_PREVIEW, true, 0);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...