Click here to Skip to main content
14,448,151 members

OCR With MODI in Visual C++

Rate this:
3.81 (20 votes)
Please Sign up or sign in to vote.
3.81 (20 votes)
23 Jan 2007
An article on how to use Microsoft Office Document Imaging Library (MODI) for OCR in Visual C++



Microsoft Office Document Imaging Library (MODI) which comes with the Office 2003 package, allows us easily integrate OCR functionality into our own applications. Although there is a good C# sample: "OCR with Microsoft® Office" posted on this web site, I would need something in C++. After searching on the Internet and the Microsoft web site and can't find anything good regarding MODI's OCR for Visual C++. I decided to dig this thing out and write this sample demo program to show the basic thing of MODI's OCR feature. I believe that some people may be interested in this program, so, I post it on the codeproject web site to share the common interest.Project Background

This project was firstly started in Visual C++ 6.0 and then updated to Visual Studio .Net 2003 and I have included two project file in the demo program. To run it in Visual C++ 6.0, open MODIVCDemo.dsp manually.

Build Project and Use Code

Add MODI Active-X into the project

In visual C++ 6.0, click "Project->Add To Project->Components and Controls->Registered ActiveX Control" and select MODI ActiveX as shown below.

 MODI Active-X Control

Mapping Active-X into the project

MODI Active-X Control Mapping

Once map MODI Active-X control into the project, all Active-X control wrapped classes will be automatically added into the project.

HOW TO OCR it in Visual C++.

Following is the sample code showing how to use MODI for OCR.

BOOL CMODIVC6Dlg::bReadOCRByMODIAXCtrl(CString csFilePath, 
                                       CString &csText)
   BOOL bRet = TRUE;
   HRESULT hr = 0;

   IUnknown *pVal = NULL;
   IDocument *IDobj = NULL;
   ILayout *ILayout = NULL;
   IImages *IImages = NULL;
   IImage *IImage = NULL;
   IWords *IWords = NULL;
   IWord *IWord = NULL;

   pVal = (IUnknown *) m_MIDOCtrl.GetDocument(); 

   if ( pVal != NULL )
      //Already has image in it, Don't need to create again
      //Just get IDocument interface
      pVal->QueryInterface(IID_IDocument,(void**) &IDobj);
      if ( SUCCEEDED(hr) )
         hr = IDobj->OCR(miLANG_SYSDEFAULT,1,1);

         if ( SUCCEEDED(hr) )
            long iImageCount=0;
            for ( int img =0; img<iImageCount;img++)

               long numWord=0;


               for ( long i=0; i<numWord;i++)
                  CString csTemp;
                  BSTR result;
                  char buf[256];

                  csText += csTemp;
                  csText +=" ";

            //Release all objects

      } else {
         bRet = FALSE;
   } else {
      bRet = FALSE;


   } else {
      bRet = FALSE;

   return bRet;

That is!

Version History

Version 1: No Active-X ctrl in the dialogue, use bReadOCRByMODI(...)

Version 2: Add Active-X ctrl in the dialogue,use bReadOCRByMODIAXCtrl(...)

and version 2 is the 1st demo program posted on the codeproject.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior)
United States United States

The author is a senior software engineer in US.

Comments and Discussions

Questioncompile error with VS 2015, any ideas on how to compile this on later versions of Visual Studio? Pin
hobnob17-Oct-16 8:45
Memberhobnob17-Oct-16 8:45 
AnswerRe: compile error with VS 2015, any ideas on how to compile this on later versions of Visual Studio? Pin
pengyuefan23-Mar-17 0:17
Memberpengyuefan23-Mar-17 0:17 
Questionclass not registered Pin
catchit20008-Feb-16 16:21
Membercatchit20008-Feb-16 16:21 
QuestionMODI dll has dependency on Office package. Pin
suvidh shetty16-Oct-14 3:30
Membersuvidh shetty16-Oct-14 3:30 
QuestionNot able to launch the MODIVCDEMO.exe Pin
suvidh shetty7-Oct-14 21:09
Membersuvidh shetty7-Oct-14 21:09 
QuestionA Simple C# Example Pin
ZamirF26-Sep-11 23:42
MemberZamirF26-Sep-11 23:42 
BugCXPageException when OCR Pin
AgentX300020-Jun-11 6:28
MemberAgentX300020-Jun-11 6:28 
GeneralRe: CXPageException when OCR Pin
catchit200018-Feb-16 14:35
Membercatchit200018-Feb-16 14:35 
GeneralPlease send me Source code Pin
Ramesh Venkadesh10-Mar-11 20:57
MemberRamesh Venkadesh10-Mar-11 20:57 
QuestionExample doesn't work? Pin
Member 442795525-Aug-10 8:10
MemberMember 442795525-Aug-10 8:10 
AnswerRe: Example doesn't work? Pin
donghuih1-Feb-13 4:31
Memberdonghuih1-Feb-13 4:31 
AnswerRe: Example doesn't work? Pin
JasMineLeaf19-Oct-14 17:07
MemberJasMineLeaf19-Oct-14 17:07 
QuestionPreffered Image resolution for better results Pin
erappy18-May-09 1:03
Membererappy18-May-09 1:03 
Questionc Pin
snawy20-Jan-09 19:54
Membersnawy20-Jan-09 19:54 
QuestionHow OCR method of MODI support Multi language? Pin
snawy20-Jan-09 19:22
Membersnawy20-Jan-09 19:22 
GeneralMODI in Java Pin
paolopagano4-Aug-08 10:28
Memberpaolopagano4-Aug-08 10:28 
GeneralRe: MODI in Java Pin
srabbis27-Sep-11 5:14
Membersrabbis27-Sep-11 5:14 
QuestionHow to include in a Visual C++ project? Pin
paolopagano4-Aug-08 0:53
Memberpaolopagano4-Aug-08 0:53 
QuestionOne Query...MS Office? Pin
KBM7321-May-08 2:05
MemberKBM7321-May-08 2:05 
Questiona question Pin
zhaoyanggolden30-Mar-08 16:54
Memberzhaoyanggolden30-Mar-08 16:54 
QuestionStill error after reinstalling Office 2003 Pin
Hooo26-Dec-07 19:39
MemberHooo26-Dec-07 19:39 
GeneralRe: Still error after reinstalling Office 2003 Pin
Yangchenlong20-Jan-08 21:04
MemberYangchenlong20-Jan-08 21:04 
AnswerRe: Still error after reinstalling Office 2003 Pin
zhb_sh15-Mar-09 5:55
Memberzhb_sh15-Mar-09 5:55 
Generalhi Pin
lulukuku20-Nov-07 6:41
Memberlulukuku20-Nov-07 6:41 
Generalthanks you! Pin
lulukuku20-Nov-07 6:40
Memberlulukuku20-Nov-07 6:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 23 Jan 2007


60 bookmarked