Page #20 (Reference Hardware Components)


Simulation Program

In my simulation program, the VCR vendor has signed an agreement to provide a C++ class, CVcr, to the TV manufacturer. This class has a public method called GetSignalValue that, when invoked by the TV, will return the magnitude of the current video signal. The maximum value of the signal was decided to be 40.

 // File vcr.h  class CVcr  { public:    CVcr(void);    long GetSignalValue();  private:    long m_lCurValue;  }; 

In my implementation of this class, I will return a value of five the first time this method is called. On each subsequent call, I will increment the value by ten. The implementation logic is shown in the following code:

 // From vcr.cpp  CVcr:: CVcr ()  {   m_lCurValue = 5;  }  long CVcr::GetSignalValue()  {   long lReturnValue = m_lCurValue;    m_lCurValue += 10;    return lReturnValue;  } 

As a VCR vendor, I present two files to the TV manufacturer:

  • Header file vcr.h that contains the definition of class CVcr

  • Library file vcr.lib that contains the programming logic in object code format.

My TV simulation application will obtain and display the signal values 10 times in a loop as shown here:

 #include "VCR.h"  #include <iostream.h>  int main(int argc, char* argv[])  {   int i;    CVcr vcr;    for(i=0; i<10; i++) {     long val = vcr.GetSignalValue();      cout << "Round: " << i << " - Value: " << val << endl;    }    return 0;  } 

I will compile this program code and link it with library vcr.lib to create the final executable tv.exe.

 cl  c tv.cpp  link tv.obj vcr.lib 


The VCR implementation is providing a ser vice, and the TV code is consuming the services provided by the VCR. In general, the software component that provides a service is referred to as the server and the software component that consumes the services is referred to as the client.

Here is the output when I execute the simulation program:

 Round: 0 - Value: 5  Round: 1 - Value: 15  Round: 2 - Value: 25  Round: 3 - Value: 35  Round: 4 - Value: 45  Round: 5 - Value: 55  Round: 6 - Value: 65  Round: 7 - Value: 75  Round: 8 - Value: 85  Round: 9 - Value: 95 

Though the interaction between the TV and the VCR is working as expected, my implementation had a flaw in that the signal value should not exceed 40. Although a trivial solution is required to correct the implementation, it is too late. The client code has been shipped to thousands of customers and recalling the product is not an option.

Is there a way to field-replace the fix?

Let s peek under the hood and see how an application (more precisely, an application s executable) gets created by the linker and loaded by the operating system.


COM+ Programming. A Practical Guide Using Visual C++ and ATL
COM+ Programming. A Practical Guide Using Visual C++ and ATL
ISBN: 130886742
Year: 2000
Pages: 129 © 2008-2017.
If you may any questions please contact us: