Solved

DAO database initialization

Posted on 1998-12-01
1
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

740 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