Page #23 (Dynamic Link Library)

< BACK  NEXT >
[oR]

Fixing a Defect

Our customers bought the TV (tv.exe) and the VCR (vcr.dll) and started using it. Meanwhile, the VCR vendor realizes that the logic of generating the signal values is not quite correct. The signal being generated from the VCR kept on increasing in magnitude with time, though the specifications indicated that the upper limit of the magnitude is 40. The fix is to reset the output after every four rounds (5, 15, 25, 35, 5, 15, 25, 35, 5, 15, and so on). To keep track of the current round, a private member variable needs to be added to the CVcr class. This is okay, as our C++ knowledge on encapsulation tells us that changing private member variables and methods of a C++ class does not require its users to modify their code. The new class definition is shown below:

 class CVcr  { public:    CVcr(void);    long GetSignalValue();  private:    long m_lCurValue;    int m_nCurCount;  };  CVcr:: CVcr ()  {   m_lCurValue = 5;    m_nCurCount = 0;  }  long CVcr::GetSignalValue()  {   m_nCurCount++;    if (5 == m_nCurCount ) {     m_lCurValue = 5;      m_nCurCount = 1;    }    long lReturnValue = m_lCurValue;    m_lCurValue += 10;    return lReturnValue;  } 

Compile the code, create new vcr.dll (version 2.0), and distribute it to our customers.

Following is what customers see when they turn on the TV:

 Round: 1 - Value: 5  Round: 3 - Value: 15  Round: 1 - Value: 5  Round: 3 - Value: 15  Round: 1 - Value: 5  ... 

What we expected to see was the output value cycling through 5, 15, 25, 35, 5, 15, and so on. Instead, what we witnessed was that the output value just toggled between 5 and 15. Moreover, the TV program was supposed to quit after 10 iterations. Instead, it went into an infinite loop.

In the hardware component scenario, being the electronic junkie that you are, you know that you have replaced the VCR many times. Each time, once you connect the video input/output jacks, the TV received video signals just fine. So what went wrong in our simulation program?

We will need to reexamine the hardware TV-VCR interconnection and see what we missed in our software simulation.


< BACK  NEXT >


COM+ Programming. A Practical Guide Using Visual C++ and ATL
COM+ Programming. A Practical Guide Using Visual C++ and ATL
ISBN: 130886742
EAN: N/A
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net