Common Responsibilities
The code that the ATL Object Wizard generates includes empty method implementations for our supported interface, IOcrProcessor. It is our responsibility to fill in the functionality for the generated, empty methods. Also, there are often times when we want to add a new interface to our COM object. We will show these common responsibilities in this section.
Implementing Interface Methods
Your IOcrProcessor interface specifies a method called OcrWholeImage, which we’ll now implement. A client will pass in a SAFEARRAY of unsigned characters in the first parameter of OcrWholeImage. This is a VARIANT that represents an image buffer passed into this function for OCR processing. Your job is to pull out this binary buffer from the SAFEARRAY and perform the OCR processing. You then will pass the OCR text back to the client via pOcrText, the second parameter of OcrWholeImage. The implementation of OcrWholeImage is shown here:
STDMETHODIMP
COcrProcessor::OcrWholeImage(VARIANT binaryImageArray, BSTR * pOcrText)
{
CComBSTR bstrOcrText;
// Make sure that the variant contains a SAFEARRAY of bytes
if (binaryImageArray.vt == (VT_ARRAY|VT_UI1)) {
SAFEARRAY *pArray = binaryImageArray.parray ;
unsigned char *pRawData;
HRESULT hr = SafeArrayAccessData(pArray, (void HUGEP**)&pRawData);
unsigned long arraySize = pArray->rgsabound[0].cElements ;
// Pull out the image buffer from the SAFEARRAY unsigned char *pImageData = new unsigned char[arraySize] ; memcpy(pImageData, pRawData, ...