Microsoft KB Archive/172405: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - "&" to "&")
 
(One intermediate revision by the same user not shown)
Line 12: Line 12:
<div id="TitleRow">
<div id="TitleRow">


= <span id="KB172405"></span>FIX: &quot;Unhandled exception&quot; in MFC DAO App After VC++ 5.0 SP1 =
= <span id="KB172405"></span>FIX: "Unhandled exception" in MFC DAO App After VC++ 5.0 SP1 =




Line 45: Line 45:
== SYMPTOMS ==
== SYMPTOMS ==


After installing the MFC42.dll (version 4.21.7160) that ships with Visual C++ 5.0 Service Pack 1, applications that were compiled with Visual C++ 4.2 and use MFC DAO may fail with an unhandled exception or MFC may display a &quot;Command Failed&quot; error message. Specifically, the exception will occur when creating index fields (CDaoTableDef::CreateIndex) or retrieving information about index fields (CDaoTableDef::GetIndexInfo). If you catch the exception to examine the error message you will see &quot;No error message is available&quot;.
After installing the MFC42.dll (version 4.21.7160) that ships with Visual C++ 5.0 Service Pack 1, applications that were compiled with Visual C++ 4.2 and use MFC DAO may fail with an unhandled exception or MFC may display a "Command Failed" error message. Specifically, the exception will occur when creating index fields (CDaoTableDef::CreateIndex) or retrieving information about index fields (CDaoTableDef::GetIndexInfo). If you catch the exception to examine the error message you will see "No error message is available".


</div>
</div>
Line 99: Line 99:


Following is an excerpt from DBDAOID.H included with Visual C++ 5.0:
Following is an excerpt from DBDAOID.H included with Visual C++ 5.0:
<pre class="codesample">  //  The pre-3.5 GUIDs have been redefined with &quot;30&quot; added to the ID.
<pre class="codesample">  //  The pre-3.5 GUIDs have been redefined with "30" added to the ID.
   //      For example:
   //      For example:
   //  IID_IDAOIndex becomes IID30_IDAOIndex
   //  IID_IDAOIndex becomes IID30_IDAOIndex
Line 107: Line 107:


The following code will reproduce the error:
The following code will reproduce the error:
<pre class="codesample">  CString strFilename = _T(&quot;c:\\db1.mdb&quot;);
<pre class="codesample">  CString strFilename = _T("c:\\db1.mdb");




Line 115: Line 115:
   database.Create(strFilename);
   database.Create(strFilename);


   // Create &quot;DEFAULT&quot; table
   // Create "DEFAULT" table


   CDaoTableDef tableDef(&amp;database);
   CDaoTableDef tableDef(&database);
   tableDef.Create(_T(&quot;DEFAULT&quot;));
   tableDef.Create(_T("DEFAULT"));


   // Create a single field &quot;IDENTIFIER&quot;
   // Create a single field "IDENTIFIER"


   CDaoFieldInfo fieldInfo;
   CDaoFieldInfo fieldInfo;
   fieldInfo.m_strName = _T(&quot;IDENTIFIER&quot;);
   fieldInfo.m_strName = _T("IDENTIFIER");
   fieldInfo.m_nType = dbText;
   fieldInfo.m_nType = dbText;
   fieldInfo.m_lSize = 255;
   fieldInfo.m_lSize = 255;
Line 136: Line 136:


   CDaoIndexFieldInfo indexFieldInfo;
   CDaoIndexFieldInfo indexFieldInfo;
   indexFieldInfo.m_strName = _T(&quot;IDENTIFIER&quot;);
   indexFieldInfo.m_strName = _T("IDENTIFIER");
   indexFieldInfo.m_bDescending = FALSE;
   indexFieldInfo.m_bDescending = FALSE;


   CDaoIndexInfo indexInfo;
   CDaoIndexInfo indexInfo;
   indexInfo.m_strName = _T(&quot;IDENTIFIER&quot;);
   indexInfo.m_strName = _T("IDENTIFIER");
   indexInfo.m_pFieldInfos = &amp;indexFieldInfo;
   indexInfo.m_pFieldInfos = &indexFieldInfo;
   indexInfo.m_nFields = 1;
   indexInfo.m_nFields = 1;
   indexInfo.m_bPrimary = TRUE;
   indexInfo.m_bPrimary = TRUE;

Latest revision as of 12:30, 21 July 2020

Article ID: 172405

Article Last Modified on 10/24/2003



APPLIES TO

  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0 SP1
  • Microsoft Visual C++, 32-bit Professional Edition 5.0 SP1



This article was previously published under Q172405

SYMPTOMS

After installing the MFC42.dll (version 4.21.7160) that ships with Visual C++ 5.0 Service Pack 1, applications that were compiled with Visual C++ 4.2 and use MFC DAO may fail with an unhandled exception or MFC may display a "Command Failed" error message. Specifically, the exception will occur when creating index fields (CDaoTableDef::CreateIndex) or retrieving information about index fields (CDaoTableDef::GetIndexInfo). If you catch the exception to examine the error message you will see "No error message is available".

CAUSE

Apps compiled with Visual C++ 4.2 should use DAO 3.0. DAO 3.0 GUIDs were redefined (in DBDAOID.H) after DAO 3.5 was released and MFC DAO source was not modified to use the new definitions.

There are two places where MFC DAO uses the wrong GUIDs.In DaoCore.cpp:

  1. Line 5527 inside AfxGetIndexFields(), IID_IDAOIndexFields is used instead of IID30_IDAOIndexFields.
  2. Line 5580 inside AfxGetIndexFieldInfo(), IID_IDAOField is used instead of IID30_IDAOFields. Any application that directly or indirectly calls these functions will fail.


RESOLUTION

There are three possible workarounds for this problem:

  • Recompile your application with Visual C++ 4.2 and statically link to MFC.


-or-

  • Recompile your application with Visual C++ 5.0.


-or-

  • Place the MFC 4.2 dll (from Visual C++ 4.2) inside your application's directory so it will be used instead of the newer one.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Studio 97 Service Pack 3.

For more information, please see the following article in the Microsoft Knowledge Base:

170365 INFO: Visual Studio 97 Service Packs - What, Where, and Why


MORE INFORMATION

Following is an excerpt from DBDAOID.H included with Visual C++ 5.0:

   //   The pre-3.5 GUIDs have been redefined with "30" added to the ID.
   //      For example:
   //   IID_IDAOIndex becomes IID30_IDAOIndex
   // 

This way both the 30 and 3.5 GUIDs can be used at once.

Steps to Reproduce Behavior

The following code will reproduce the error:

   CString strFilename = _T("c:\\db1.mdb");


   // Create a dao database

   CDaoDatabase database;
   database.Create(strFilename);

   // Create "DEFAULT" table

   CDaoTableDef tableDef(&database);
   tableDef.Create(_T("DEFAULT"));

   // Create a single field "IDENTIFIER"

   CDaoFieldInfo fieldInfo;
   fieldInfo.m_strName = _T("IDENTIFIER");
   fieldInfo.m_nType = dbText;
   fieldInfo.m_lSize = 255;
   fieldInfo.m_lAttributes = 0;
   fieldInfo.m_nOrdinalPosition = 0;
   fieldInfo.m_bRequired = FALSE;
   fieldInfo.m_bAllowZeroLength = FALSE;
   fieldInfo.m_lCollatingOrder = 0;
   tableDef.CreateField(fieldInfo);

   // Create the primary key

   CDaoIndexFieldInfo indexFieldInfo;
   indexFieldInfo.m_strName = _T("IDENTIFIER");
   indexFieldInfo.m_bDescending = FALSE;

   CDaoIndexInfo indexInfo;
   indexInfo.m_strName = _T("IDENTIFIER");
   indexInfo.m_pFieldInfos = &indexFieldInfo;
   indexInfo.m_nFields = 1;
   indexInfo.m_bPrimary = TRUE;
   indexInfo.m_bUnique = TRUE;
   indexInfo.m_bClustered = FALSE;
   indexInfo.m_bIgnoreNulls = FALSE;
   indexInfo.m_bRequired = TRUE;
   indexInfo.m_bForeign = TRUE;
   indexInfo.m_lDistinctCount = 0;
   tableDef.CreateIndex(indexInfo); // Generates exception

Keywords: kbbug kbfix kbvs97sp2fix kbdatabase KB172405