40
Argus Encoder Family Version 2.6 API Developer’s Guide
FMTestApp
Creating the Project
When you are creating a Microsoft Foundation Class (MFC) Application Wizard
EXE project like FMTestApp, it is very important that you select from the App
Wizard window the check box that adds support for ActiveX™ controls. This
inserts into the stdafx.h file the header files required to support the COM libraries.
If you are adding COM support to an existing project, or if your project does not
use MFC, we highly suggest studying some of the books available on MFC core
details and COM specifics. We also suggest using MFC as a shared DLL from
App Wizard, as all of the COM components are already using this DLL.
Initializing the COM libraries
When you create a client of a COM object, you first initialize the COM libraries
by calling either the
CoInitialize
,
CoInitializeEx
, or
OleInitialize
functions. The
decision about which function to call is based on several factors, the most impor-
tant of which is the type of threading model you want to use with the components.
All of the Argus API core components support a dual interface (i.e., any interface
that inherits from
IDispatch
, which is the interface that supports OLE Automa-
tion). Using the custom interface of the component provides the client with direct
table access to the functionality of the component. This is much more efficient
than the
IDispatch
interface which uses the COM Automation libraries to access
component functionality.
In general, if you are using versions 5.0 or later of Visual C++ or Visual Basic, it is
best to use the custom interface directly. The
IDispatch
interface is provided to
support VB 4.0 and earlier development, as well as to access the components from
scripting languages such as VBScript and JScript.
Since we are going to use the Filter Manager custom interface, we will use
CoInitialize
or
CoInitializeEx
. To determine which function to call, we need
to determine the threading model we will use. Our components require that the
client use the “apartment” threading model. For apartment model threading,
CoInitialize
is sufficient. The code to initialize the components looks like this:
{
HRESULT hr = CoInitialize( NULL );
if ( FAILED(hr ) )
return FALSE;
}
This piece of code would normally appear in the
InitInstance
method of the
CApp
object.