Skip to Content
Learning DCOM
book

Learning DCOM

by Thuan L. Thai
April 1999
Intermediate to advanced
502 pages
15h 5m
English
O'Reilly Media, Inc.
Content preview from Learning DCOM

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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

.NET and COM: The Complete Interoperability Guide

.NET and COM: The Complete Interoperability Guide

Adam Nathan
Windows 7 Device Driver

Windows 7 Device Driver

Ph.D. Ronald D. Reeves

Publisher Resources

ISBN: 9781449307011Supplemental ContentErrata Page