Microsoft KB Archive/198989

= FIX: ATL Local Server Wizard-Generated Code Doesn't Call Term =

Article ID: 198989

Article Last Modified on 12/8/2003

-

APPLIES TO

 The AppWizard, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q198989

<div class="symptoms_section">

SYMPTOMS
Creating a new ATL COM server application with AppWizard, which was generated as an EXE for the Server Type, does not call CComModule::Term inside of tWinMain. As a result, kernel objects that ATL has created, such as critical sections, will not be released until the process has been unloaded entirely by the operating system. Also, any class factories that were created and used may not be released until CoUninitialize has been called.

Note that this problem exists in Visual C++ 6.0 only when an ATL Service project is selected in the ATL Wizard.

<div class="cause_section">

CAUSE
This problem is due to a bug in the Visual C++ 5.0 AppWizard.

<div class="resolution_section">

RESOLUTION
Add a call to the Term function.

For example, you may change the code generated from the following

extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,   HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) {   lpCmdLine = GetCommandLine; //This line necessary for _ATL_MIN_CRT.

//Code omitted for brevity... CoUninitialize; return nRet; }

to the following:

extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,   HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/) {   lpCmdLine = GetCommandLine; //This line necessary for _ATL_MIN_CRT.

//Code omitted for brevity... _Module.Term; CoUninitialize; return nRet; }

<div class="status_section">

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been corrected in Visual C++ 6.0.

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> Create a new ATL COM Server Application with AppWizard; pick EXE as the Server Type.</li>  Examine the _tWinMain function and look for a call:

_Module.Term; </li></ol>

<div class="references_section">