BUG: You receive a "C1001" compiler error message when you compile code that has one __hook function after another __hook function in Visual C++ .NET 2003 (829749)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2003)

SYMPTOMS

In Microsoft Visual C++ .NET 2003, when you try to compile code that has one __hook function after another __hook function , you receive the following compiler error:

fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 2701) Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information.

CAUSE

This error is a bug in the Visual C++ 2003 compiler. Because of this bug, the compiler cannot correctly parse your source code because of the layout of your code.

RESOLUTION

This bug has three possible workarounds:
  • Add some code between the two __hook function calls.

    To do this, follow these steps:
    1. In Solution Explorer, under the Source Files folder, double-click the Hook.cpp file.
    2. Locate the following statement in the code window:
      // This is the first workaround.
    3. Uncomment the statement after the statement that you located in step 2, and then press CTRL+SHIFT+B to build the solution.
  • Move another function (such as the CGraph::OnDataChanged function) between the two constructor calls.

    To do this, follow these steps:
    1. In Solution Explorer, under the Source Files folder, double-click the Hook.cpp file.
    2. Locate the following statement in the code window:
      // MoveCodeHere
    3. Locate the following statement in the code window:
      // The second workaround is to move this function to the "MoveCodeHere" region.
    4. Move the function that you defined after the statement that you located in step 3 to the region that you located in step 2.

      The code window now includes the following code example:
      CMyGraph::CMyGraph(CMyGraphData& graphData) :
          m_GraphData(graphData)
      {
          // Comment the following code for the third workaround:
          __hook(&CMyGraphData::DataChanged, &m_GraphData, &CMyGraph::OnDataChanged);
          // Uncomment the following code for the third workaround:
          // CMyGraph::HookEvent();
      }
      
      // MoveCodeHere
      void CMyGraph::OnDataChanged(CMyGraphData& source) 
      { 
      }
      
      CMyGraph::CMyGraph(const CMyGraph& other) :
          m_GraphData(other.m_GraphData)
      {
          // If you uncomment the following line, compilation succeeds:
          // This is the first workaround.
          // int x = 0;
          // Comment the following code for the third workaround:
          __hook(&CMyGraphData::DataChanged, &m_GraphData, &CMyGraph::OnDataChanged);
          // Uncomment the following code for the third workaround:
          // CMyGraph::HookEvent();
      }
      
      // The second workaround is to move this function to the "MoveCodeHere" region.
      
    5. Press CTRL+SHIFT+B to build the solution.
  • Put the __hook function call into its own inline function, and then call the inline function instead of calling the __hook function directly.

    To do this, follow these steps:
    1. In Solution Explorer, under the Source Files folder, double-click the Hook.cpp file.
    2. Locate the following statement in the code window:
      // Third Workaround:
    3. Uncomment the function code that is after the statement that you located in step 2.
    4. Locate all the occurrences of the following statement in the code window, and then comment the line after this statement:
      // Comment the following code for the third workaround:
    5. Locate all the occurrences of the following statement in the code window, and then uncomment the line after this statement:
      // Uncomment the following code for the third workaround:
    6. Press CTRL+SHIFT+B to build the solution.
    You incur no overhead by using this workaround because, in the release configuration, the compiler will replace every occurrence of the HookEvent function call with the associated function body.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section of this article.

MORE INFORMATION

Steps to reproduce the behavior

  1. Start Microsoft Visual Studio .NET 2003.
  2. On the File menu, point to New, and then click Project. The New Project dialog box appears.
  3. Under Project Types, click Visual C++ Projects. Under Templates, click Win32 Console Project.
  4. In the Name box, type Hook.
  5. Click OK, and then click Finish.
  6. In Solution Explorer, double-click Hook.cpp to display the code window.
  7. In the Hook.cpp file, add the following statements before the _tmain function:
    [event_source(native)]
    class CMyGraphData {
    public:
       __event void DataChanged(CMyGraphData& source);
    };
    
    [event_receiver(native)]
    class CMyGraph
    {
    public:
        CMyGraph(CMyGraphData& graphData);
        CMyGraph(const CMyGraph& other);
    
    // Third Workaround:
    /*
    inline void CMyGraph::HookEvent()
    {
        __hook( &CMyGraphData::DataChanged, &m_GraphData, &CMyGraph::OnDataChanged); 
    }*/
    
    private:
        CMyGraphData& m_GraphData;
        void OnDataChanged(CMyGraphData& source);
    };
    
    CMyGraph::CMyGraph(CMyGraphData& graphData) :
        m_GraphData(graphData)
    {
        // Comment the following code for the third workaround:
        __hook(&CMyGraphData::DataChanged, &m_GraphData, &CMyGraph::OnDataChanged);
        // Uncomment the following code for the third workaround:
        // CMyGraph::HookEvent();
    }
    
    // MoveCodeHere
    
    CMyGraph::CMyGraph(const CMyGraph& other) :
        m_GraphData(other.m_GraphData)
    {
        // If you uncomment the following line, compilation succeeds:
        // This is the first workaround.
        // int x = 0;
        // Comment the following code for the third workaround:
        __hook(&CMyGraphData::DataChanged, &m_GraphData, &CMyGraph::OnDataChanged);
        // Uncomment the following code for the third workaround:
        // CMyGraph::HookEvent();
    }
    
    // The second workaround is to move this function to the "MoveCodeHere" region.
    void CMyGraph::OnDataChanged(CMyGraphData& source) 
    { 
    }
    
  8. Press CTRL+SHIFT+B to build the solution.

    You receive the compiler error that is mentioned in the "Symptoms" section of this article.

Modification Type:MinorLast Reviewed:1/16/2006
Keywords:kbCompiler kbHook kberrmsg kbbug KB829749 kbAudDeveloper