MIDL: Compiling IDL files
The previous lesson introduced you to IDL.
IYourComInterface using IDL. This lesson builds on that work.
Once we have completed our specification using IDL, we compile it using MIDL.
MIDL is a command-line tool that comes with Visual C++.
MIDL invokes the Visual C++ command-line compiler (cl).
Before you can use MIDL, you need to have the appropriate environment variables set.
The vcvars32.bat file in the DevStudio\Vc\Bin directory sets the appropriate environment variables.
The exercise below will guide you through these steps.
What compiling does
Upon successful compilation, several files are produced.
For IMyComInterface.idl, these are dlldata.c, IMyComInterface_p.c, IMyComInterface.h, and IMyComInterface_i.c. For now, we don't need dlldata.c and IMyComInterface_p.c.
IMyComInterface.h contains both C++ and C definitions of structures to implement
These definitions use several macros that are defined in various include files, included as part of the Visual C++ environment.
Most of the code in IMyComInterface.h is to support C-based COM programming. Because we are using C++, we can ignore this code.
Following is a code excerpt from IMyComInterface.h that defines
IMyComInterface : public IUnknown
virtual HRESULT STDMETHODCALLTYPE Fx1
(unsigned char __RPC_FAR *buf) = 0;
virtual HRESULT STDMETHODCALLTYPE Fx2
(void) = 0;
IYourComInterface : public IUnknown
virtual HRESULT STDMETHODCALLTYPE Zx1
(LONG ix) = 0;
If interested, you can look these macros up, starting in file objbase.h, in the Visual C++ include directory, or by using the Microsoft Platform SDK.
File IMyComInterface_i.c defines the value of
Here are the IIDs:
MIDL-generated files include an MIDL-generated interface definition file.
const IID IID_IMyComInterface =
const IID IID_IYourComInterface =
midl com - Exercise