// DirectX Show 초기화, 인터페이스 생성 bool cDxCapture::Init(const int cameraIndex, const int width, const int height, const bool isThreadMode) { // Initialize COM if (FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) { Msg(TEXT("CoInitialize Failed!\r\n")); exit(1); } m_cameraIndex = cameraIndex; m_width = width; m_height = height; // Create DirectShow graph and start capturing video HRESULT hr; hr = CaptureVideo(cameraIndex); if (FAILED(hr)) return false; m_isThreadMode = isThreadMode; if (isThreadMode) { m_handle = (HANDLE)_beginthreadex(NULL, 0, DxCaptureThreadFunction, this, 0, (unsigned*)&m_threadId); } return true; }
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hInstP, LPSTR lpCmdLine, int nCmdShow) { MSG msg={0}; WNDCLASS wc; // Initialize COM if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) { Msg(TEXT("CoInitialize Failed!\r\n")); exit(1); } // Register the window class ZeroMemory(&wc, sizeof wc); wc.lpfnWndProc = WndMainProc; wc.hInstance = hInstance; wc.lpszClassName = CLASSNAME; wc.lpszMenuName = NULL; wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = NULL; if(!RegisterClass(&wc)) { Msg(TEXT("RegisterClass Failed! Error=0x%x\r\n"), GetLastError()); CoUninitialize(); exit(1); } // Create the main window. The WS_CLIPCHILDREN style is required. ghApp = CreateWindow(CLASSNAME, APPLICATIONNAME, WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT, 0, 0, hInstance, 0); if(ghApp) { HRESULT hr; // Create DirectShow graph and start capturing video hr = CaptureVideo(); if (FAILED (hr)) { CloseInterfaces(); DestroyWindow(ghApp); } else { // Don't display the main window until the DirectShow // preview graph has been created. Once video data is // being received and processed, the window will appear // and immediately have useful video data to display. // Otherwise, it will be black until video data arrives. ShowWindow(ghApp, nCmdShow); } // Main message loop while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } // Release COM CoUninitialize(); return (int) msg.wParam; }