Microsoft Knowledge Base Email Alertz

(177135) - When using the MFC Database classes or calling ODBC functions within the DLL_PROCESS_DETACH case of the DllMain() function, an access violation can occur especially if the DLL links to the MFC DLL (which does a LoadLibrary call to call ODBC). For...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 177135 - Last Review: December 8, 2003 - Revision: 4.0

PRB: Do not Call ODBC Within DLL_PROCESS_DETACH Case

This article was previously published under Q177135

SYMPTOMS

When using the MFC Database classes or calling ODBC functions within the DLL_PROCESS_DETACH case of the DllMain() function, an access violation can occur especially if the DLL links to the MFC DLL (which does a LoadLibrary call to call ODBC). For example, calling CDatabase::Close() from the destructor of a global static object in the DLL causes an access violation error in ODBC32.DLL.

CAUSE

Because there are no guarantees of the order by which DLLs receive the DLL_PROCESS_DETACH case, it is possible that the ODBC handle memory can be freed before your DLL's DllMain() function gets called with DLL_PROCESS_DETACH. Therefore, any calls to ODBC using those handles can cause a crash.

RESOLUTION

Do not call ODBC functions or use the MFC ODBC classes in destructors of global objects within DLLs or in the DllMain() DLL_PROCESS_DETACH case.

Instead use a termination function in the DLL which the application can call before exiting.

STATUS

This behavior is by design.

APPLIES TO
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
Keywords: 
kbdatabase kbprb KB177135
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate