Solved

DAO database initialization

Posted on 1998-12-01
1
273 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

707 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