Microsoft KB Archive/829749

= BUG: You receive a &quot;C1001&quot; compiler error message when you compile code that has one __hook function after another __hook function in Visual C++ .NET 2003 =

Article ID: 829749

Article Last Modified on 4/19/2007

-

APPLIES TO


 * Microsoft Visual C++ .NET 2003 Standard Edition

-



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:  In Solution Explorer, under the Source Files folder, double-click the Hook.cpp file.  Locate the following statement in the code window: // This is the first workaround.  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:  In Solution Explorer, under the Source Files folder, double-click the Hook.cpp file.</li>  Locate the following statement in the code window: // MoveCodeHere </li>  Locate the following statement in the code window: // The second workaround is to move this function to the &quot;MoveCodeHere&quot; region. </li>  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 &quot;MoveCodeHere&quot; region. </li> Press CTRL+SHIFT+B to build the solution.</li></ol> </li> 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:  In Solution Explorer, under the Source Files folder, double-click the Hook.cpp file.</li>  Locate the following statement in the code window: // Third Workaround: </li> Uncomment the function code that is after the statement that you located in step 2.</li>  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: </li>  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: </li> Press CTRL+SHIFT+B to build the solution.</li></ol>

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.</li></ul>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section of this article.

<div class="moreinformation_section">

Steps to reproduce the behavior
 Start Microsoft Visual Studio .NET 2003.</li> On the File menu, point to New, and then click Project. The New Project dialog box appears.</li> <li>Under Project Types, click Visual C++ Projects. Under Templates, click Win32 Console Project.</li> <li>In the Name box, type Hook .</li> <li>Click OK, and then click Finish.</li> <li>In Solution Explorer, double-click Hook.cpp to display the code window.</li> <li> 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 &quot;MoveCodeHere&quot; region. void CMyGraph::OnDataChanged(CMyGraphData& source) { } </li> <li>Press CTRL+SHIFT+B to build the solution.

You receive the compiler error that is mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">