Writing Your Own Visual C++ Application

  1. Create a VC++ project choosing MFC AppWizard (exe)

  2. Click View->ClassWizard and MFC ClassWizard dialogue will show up. Press Add Class... and choose From a type library..., and select Passhio.tlb. The following classes will be created:

  3. Use CreateDispatch to create an IOhioSessions object (see CVchioApp class in the sample). Don't forget to initialize OLE libraries by calling AfxOleInit.

  4. Add event map into a CCmdTarget-derived class in your program which supports OLE Automation (call EnableAutomation in the constructor, see CVchioView in the sample) like following:

    BEGIN_DISPATCH_MAP(CVchioView, CEditView)

    //{{AFX_DISPATCH_MAP(CVchioView)

    DISP_FUNCTION_ID(CVchioView, "OnSessionChanged", 0, OnSessionChanged, VT_EMPTY, VTS_I4)

    DISP_FUNCTION_ID(CVchioView, "OnScreenChanged",  1, OnScreenChanged,  VT_EMPTY, VTS_I4 VTS_I4 VTS_I4)

    //}}AFX_DISPATCH_MAP

    END_DISPATCH_MAP()

    BEGIN_INTERFACE_MAP(CVchioView, CEditView)

    INTERFACE_PART(CVchioView, DIID__IOhioSessionEvents, Dispatch)

    END_INTERFACE_MAP()



    In the header file you also need to add:

    // Generated OLE dispatch map functions

    //{{AFX_DISPATCH(CVchioView)

    afx_msg void OnSessionChanged(long iState);

    afx_msg void OnScreenChanged(long iUpdate, long istate, long iEnd);

    //}}AFX_DISPATCH

    DECLARE_DISPATCH_MAP()

    DECLARE_INTERFACE_MAP()
     

See class CVchioView in the example
 

  1. Using AddSession method of IOhioSessions object to create IOhioSession object. You need to call AfxConnectionAdvise to let the event source (IOhioSession) know where to post the events (CVchioView in the sample). You also need to terminate the connection between source and sink using AfxConnectionUnadvise (see CVchioView in the sample) after closing the session.

  2. Whenever the screen changes, event handler for OnScreenChanged will be called so you can add your code there, for example, displaying current screen.

  3. Make sure to call the ReleaseDispatch method of IOhioSessions to release the IDispatch connection when closing the application (see ExitInstance in class CVchioApp).
     

Note: If you want to write a Win32 application without MFC, you need to follow the same kind of steps described above without all the MACROS. See VC++ documentation for help. A sample Win32 C++ application can be in the \Win32CSample\ sub folder and is called HIOC.EXE.