Solved

DAO database initialization

Posted on 1998-12-01
1
256 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
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…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

772 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

16 Experts available now in Live!

Get 1:1 Help Now