Commit d52e8a2c authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
+119 −0
Changes for Basics/ClassMoniker/ClassMoniker.cpp: 119 added lines, 0 removed lines.
Original line number Diff line number Diff line
//******************************************************************
//*******************************************************************
//*** Client
//*******************************************************************
//*******************************************************************

//-------------------------------------------------------------------
//  Required definitions
//-------------------------------------------------------------------
#define UNICODE
#define _WIN32_DCOM

//-------------------------------------------------------------------
//  includes
//-------------------------------------------------------------------
#include <assert.h>
#include <stdio.h>
#include <windows.h>
#include <initguid.h>
#include "..\OCREngine\idl\ocr.h"

//*******************************************************************
//*******************************************************************
//***  UTILITY FUNCTIONS
//*******************************************************************
//*******************************************************************
void DisplayStatus(wchar_t *pwszMsg, HRESULT hr)
{

    if (hr == S_OK)
    {
        wprintf(TEXT("%s\n"), pwszMsg);
        return;
    }

    if (HRESULT_FACILITY(hr) == FACILITY_WINDOWS)
        hr = HRESULT_CODE(hr);

    wchar_t *pwszStatus;
    FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
        FORMAT_MESSAGE_FROM_SYSTEM,
        NULL,
        hr,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPWSTR)&pwszStatus,
        0,
        NULL );

    wprintf(TEXT("%s: %s (ECode: %lx)\n"), pwszMsg, pwszStatus, hr);

    LocalFree(pwszStatus);
}

wchar_t *GetBestOcrFactory()
{
    static wchar_t *pwszChangeableFactory = 
        TEXT("CLSID:DF22A6B2-A58A-11d1-ABCC-00207810D5FE:");
    return pwszChangeableFactory;
}

//*******************************************************************
//*******************************************************************
//*** Main
//*******************************************************************
//*******************************************************************
void main(int argc, char **argv)
{
    DisplayStatus(TEXT("Client: Started"), S_OK);

    HRESULT hr = S_OK;

    // Init COM
    hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
    if (FAILED(hr)) { return ; }

    // Dynamically get the best OCR Factory
    // This extra level of indirection allows 
    // you to build cool distributed software.
    wchar_t *pwszDispName = GetBestOcrFactory();

    // Create a binding context
    IBindCtx *pBind = 0;
    hr = CreateBindCtx(0, &pBind);
    assert(SUCCEEDED(hr));

    // Create a class moniker based on the textual name
    // A class moniker represents a factory
    ULONG ulEaten = 0;
    IMoniker *pMon = 0;
    hr = MkParseDisplayName(pBind, pwszDispName, &ulEaten, &pMon);
    assert(SUCCEEDED(hr));

    // Bind to the factory and get the IID_IClassFactory interface
    IClassFactory *pClassFactory = 0;
    hr = pMon->BindToObject(pBind, 0, IID_IClassFactory, (void**)&pClassFactory);
    assert(SUCCEEDED(hr));
    pMon->Release();
    pBind->Release();

    // Tell the factory to manufacture an object
    // and get back a pointer to its IOcr interface
    IOcr *pOcr =0;
    hr = pClassFactory->CreateInstance(0, IID_IOcr, (void**)&pOcr);
    assert(SUCCEEDED(hr));
    pClassFactory->Release();

    // Call pOcr methods.
    DisplayStatus(TEXT("Make good use of the object.\n")
		          TEXT("Call pOcr methods...\n")
		          TEXT("This sample creates an object using a Class Moniker.\n")
		          TEXT("Check out the code, and see how simple it is!"), 
				  S_OK);

    pOcr->Release();

    CoUninitialize();
    DisplayStatus(TEXT("Client shutting down..."), S_OK);
}
+88 −0
Changes for Basics/ClassMoniker/ClassMoniker.dsp: 88 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Microsoft Developer Studio Project File - Name="ClassMoniker" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **

# TARGTYPE "Win32 (x86) Console Application" 0x0103

CFG=ClassMoniker - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE 
!MESSAGE NMAKE /f "ClassMoniker.mak".
!MESSAGE 
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE 
!MESSAGE NMAKE /f "ClassMoniker.mak" CFG="ClassMoniker - Win32 Debug"
!MESSAGE 
!MESSAGE Possible choices for configuration are:
!MESSAGE 
!MESSAGE "ClassMoniker - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "ClassMoniker - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE 

# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe

!IF  "$(CFG)" == "ClassMoniker - Win32 Release"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386

!ELSEIF  "$(CFG)" == "ClassMoniker - Win32 Debug"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept

!ENDIF 

# Begin Target

# Name "ClassMoniker - Win32 Release"
# Name "ClassMoniker - Win32 Debug"
# Begin Source File

SOURCE=.\ClassMoniker.cpp
# End Source File
# End Target
# End Project
+29 −0
Changes for Basics/ClassMoniker/ClassMoniker.dsw: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!

###############################################################################

Project: "ClassMoniker"=.\ClassMoniker.dsp - Package Owner=<4>

Package=<5>
{{{
}}}

Package=<4>
{{{
}}}

###############################################################################

Global:

Package=<5>
{{{
}}}

Package=<3>
{{{
}}}

###############################################################################
+35 −0
Changes for Basics/Dispatch/WordDispatch.cpp: 35 added lines, 0 removed lines.
Original line number Diff line number Diff line
#include <Windows.h>

void main()
{
   CoInitialize(0);

   // Get the CLSID that maps to the program ID named Word.Basic.
   GUID clsid;
   CLSIDFromProgID(L"Word.Basic", &clsid);

   // Activate the object and request for as IDispatch interface.
   IDispatch *pDisp = 0;
   CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, 
                    IID_IDispatch, (void**)&pDisp);

   // We need to know the name of the method we want to invoke.
   OLECHAR *method = L"AppShow";

   // The AppShow method expects no parameter.
   DISPPARAMS parms = {NULL, NULL, 0, 0};
   
   // Given a method name, get back the corresponding dispid.
   DISPID dispid;  
   pDisp->GetIDsOfNames(IID_NULL, &method, 1, LOCALE_USER_DEFAULT, &dispid);

   // Dynamically invoke the the AppShow method using a dispid.
   pDisp->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, 
                 DISPATCH_METHOD, &parms, NULL, NULL, NULL);

   //  Do whatever....
   Sleep(5000);

   pDisp->Release();
   CoUninitialize();
}
+88 −0
Changes for Basics/Dispatch/WordDispatch.dsp: 88 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Microsoft Developer Studio Project File - Name="WordDispatch" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **

# TARGTYPE "Win32 (x86) Console Application" 0x0103

CFG=WordDispatch - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE 
!MESSAGE NMAKE /f "WordDispatch.mak".
!MESSAGE 
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE 
!MESSAGE NMAKE /f "WordDispatch.mak" CFG="WordDispatch - Win32 Debug"
!MESSAGE 
!MESSAGE Possible choices for configuration are:
!MESSAGE 
!MESSAGE "WordDispatch - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "WordDispatch - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE 

# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe

!IF  "$(CFG)" == "WordDispatch - Win32 Release"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386

!ELSEIF  "$(CFG)" == "WordDispatch - Win32 Debug"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept

!ENDIF 

# Begin Target

# Name "WordDispatch - Win32 Release"
# Name "WordDispatch - Win32 Debug"
# Begin Source File

SOURCE=.\WordDispatch.cpp
# End Source File
# End Target
# End Project
Loading