Saturday, November 29, 2008

ATL-generated Code


The source code for our server DLL was generated by ATL. For many people it is perfectly acceptable to never look at the code ATL created. For others, not "knowing" the details of this code is unacceptable. This tutorial gives you a quick tour of the code produced by ATL. The code for the server DLL that is now sitting on your hard drive really resides in three different types of files. l First, there are the traditional C++ source and header files. Initially, all of this code is generated by the ATL wizards. l The Beep method was added by using the "AddMethod" dialog, which modified the MIDL interface definition. The MIDL source code is in

an IDL file - in this example it is BeepServer.IDL. The MIDL compiler will use this file to create several output files. These files will take care of much of the grunt work of implementing the server. As we add methods to the COM object, we'll be adding devinitions to the IDL file.

l The third group of source files are automatically generated MIDL output files created by the MIDL compiler. These files are source code files, but because they are automatically generated by the MIDL compiler from IDL source code, these files are never modified directly either by wizards or by developers. You might call them "second generation files" - the wizard created an IDL file and the MIDL

compiler created source code files from that IDL file. The files created by the MIDL include:


m BeepServer.RGS - Registration script for the server.

m BeepServer.h - This file contains definitions for the COM components.

m BeepServer_i.c - GUID structures for the COM components.

m Proxy/Stub files - This includes "C" source code, DLL definitions, and makefile (.mk) for the Proxy and Stub.


The ATL wizard also creates an application "resource," If you look in the project resources, you'll find it under "REGISTRY." This resource

contains the registration script defined in BeepServer.RGS. The name of the resource is IDR_BEEPOBJ.

We look at all of these different components in the sections below.



0 comments: