WIA stands for Windows Image Acquisition and has been introduced since Windows ME. Born to address the many problems in using the old protocol TWAIN, today became the basis for all capture devices. The focus of this article is to explain how to use our applications in C/C++, as for example in XXXXX (software for inventory) that uses this technology to capture images to be included in the database.
First of all blocks so that the program does not have to create a worker thread that does all the work and see when he’s finished with a semaphore:
CWinThread* pThread = AfxBeginThread(AcquireThreadProc, this); AfxGetMainWnd()->EnableWindow(FALSE); while (MsgWaitForMultipleObjects(1, &pThread->m_hThread, FALSE, INFINITE, QS_ALLINPUT, QS_ALLPOSTMESSAGE) == WAIT_OBJECT_0 + 1) { MSG msg; while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } }
Here is the code to wait until the end of the acquisition, while we can see how it should be implemented as AcquireThreadProc thread initialized, a simple callback function must initialize the static object COM (Component Object Model) IWiaDevMgr this:
CoInitialize(NULL); CComPtr pDev; HRESULT hr = pDev.CoCreateInstance(CLSID_WiaDevMgr); if (hr != S_OK) { CoUninitialize(); return 1; }
Last thing to do and also the simplest method is to call the object GetImageDlg IWiaDevMgr created before:
GUID guidFormat = GUID_NULL; HRESUT hr = pDev->GetImageDlg(((CWnd*)pParam)->m_hWnd, StiDeviceTypeDefault, WIA_DEVICE_DIALOG_SINGLE_IMAGE, WIA_INTENT_NONE, NULL, szBuffer, &guidFormat); if (FAILED(hr)) { CoUninitialize(); return 1; }
With this method we are done, but if we go deeper in detail and manage the acquisition, there are many other methods of serving more than atro to customize the various stages of this procedure. I remember that we can capture pictures and images from scanners, cameras and all that hardware is compatible with the technology WIA (Windows Image Acquisition).
Our latest application exploits this technology to capture images and insert them into the database of customers, suppliers, inventory items, and other employees and can be found on our site.