Solved

DAO database initialization

Posted on 1998-12-01
1
260 Views
Last Modified: 2012-05-04
My application is a Win32 console application, using MFC as a static library.  When I execute the following code I get a strange problem.  When the AfxDaoInit() function is called I am not able to clear the history list of iexplorer 4.0 . (From the view menu select the internet options , clear history). iexplorer application doesnot respond until my application exits. The code is as below.

#include <afxdao.h>
#include <windows.h>


int main()
{
      CDaoDatabase obj_Database;

      AfxDaoInit();
      try
      {
      obj_Database.Open("mydata.mdb", FALSE, FALSE);
      }
      catch (CDaoException* e)
      {      
            int iIndex;
            
            for(iIndex = 0; iIndex < e->GetErrorCount(); iIndex++)
            {
                  e->GetErrorInfo(iIndex);
                  printf("%s\n", (e->m_pErrorInfo)->m_strDescription);
            }
            return(FALSE);
      }
      getchar(); // this is to keep my app running.
      db.Close();
      obj_Database.Close();
      AfxDaoTerm();
      return(TRUE);
}
0
Comment
Question by:necjc
1 Comment
 

Accepted Solution

by:
necfm earned 100 total points
ID: 1969738
The problem is that COM  creates an invisible window which must have a message loop running. When IE generates "broadcast" messages the desktop will hang if not all windows respond!
The AfxDaoInit() probably calls CoInitialize() which creates a new COM-apartment (and a window), you have to dispatch messages in this thread to avoid these problems and also to get COM to work.
A simple loop like this will solve the problem in your test program:Replace getchar(); with

  MSG msg;
  while (GetMessage(&msg,NULL,0,0) == 1) {
   TranslateMessage(&msg);
   DispatchMessage(&msg);
}

0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now