ATL COM Class Final Construct dies with Member Accessor Class 
Author Message
 ATL COM Class Final Construct dies with Member Accessor Class

Hi

I have a ATL COM class that has a Accessor Class as a member.
I have discovered if I exit the CAccessor before the database is opened
(Exit in OpenDataSource())that the
Final Construct of the Parent Class gives a Unhandled Exception - Access
Violation in the
CComClassFactory. Do I need to initialize the CSession or CDataSource???

Is there something else I should look at ???

Thanks
Steve

Parent Class
--------------

// CScheduleManager
class ATL_NO_VTABLE CScheduleManager :
 public CComObjectRootEx<CComSingleThreadModel>,
 public CComCoClass<CScheduleManager, &CLSID_ScheduleManager>,
 public ISupportErrorInfo,
 public IDispatchImpl<IScheduleManager, &IID_IScheduleManager,
&LIBID_DBSERVERLib>
{
public:
 CScheduleManager()
 {
 }

void FinalRelease();
HRESULT FinalConstruct();

DECLARE_REGISTRY_RESOURCEID(IDR_SCHEDULEMANAGER)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CScheduleManager)
 COM_INTERFACE_ENTRY(IScheduleManager)
 COM_INTERFACE_ENTRY(IDispatch)
 COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()

// ISupportsErrorInfo
 STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);

// IScheduleManager
public:
 STDMETHOD(get_getToSgSchemeID)(/*[out, retval]*/ long *pVal);
 STDMETHOD(get_getToDxSchemeID)(/*[out, retval]*/ long *pVal);
 STDMETHOD(get_getFromSgSchemeID)(/*[out, retval]*/ long *pVal);
 STDMETHOD(get_getFromDxSchemeID)(/*[out, retval]*/ long *pVal);
 STDMETHOD(get_getDBCount)(/*[out, retval]*/ long *pVal);
 STDMETHOD(get_getStatFile4)(/*[out, retval]*/ BSTR *pVal);
 STDMETHOD(get_getStatFile3)(/*[out, retval]*/ BSTR *pVal);
 STDMETHOD(get_getStatFile2)(/*[out, retval]*/ BSTR *pVal);
 STDMETHOD(get_getStatFile1)(/*[out, retval]*/ BSTR *pVal);
 STDMETHOD(get_getMapType)(/*[out, retval]*/ long *pVal);
 STDMETHOD(get_getToSchemeID)(/*[out, retval]*/ long *pVal);
 STDMETHOD(get_getFromSchemeID)(/*[out, retval]*/ long *pVal);
 STDMETHOD(get_getGrouperName)(/*[out, retval]*/ BSTR *pVal);
 STDMETHOD(find_sched)(/*[in]*/ BSTR UserKey, BSTR BeginDate, BSTR
EndDate, /*[out,retval]*/ long *pVal);

 Cschedule mySchedule;

Quote:
};

CAccessor CLass
--------------------

class Cschedule : public CCommand<CAccessor<CscheduleAccessor> >
{
public:
 HRESULT OpenDB()
 {
  HRESULT  hr;

  hr = OpenDataSource();
  if (ERROR_SUCCESS != hr)
   return hr;

  return OpenRowset();
 }

 HRESULT OpenDataSource()
 {
  HRESULT  hr;
  CDBPropSet dbinit(DBPROPSET_DBINIT);
  HKEY hKey;
  char *psz;
  TCHAR szBuff[200]={0};
  DWORD dwType = 0, dwLen=sizeof(szBuff);

  USES_CONVERSION;
  CComBSTR tempbstr;

  psz = "Software\\Batch";

  hr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, psz, 0, KEY_READ, &hKey);

  if(ERROR_SUCCESS != hr){
   return hr;
  }

  // Get the InputDateSeparator value in szBuff
  psz = "InputDateSeparator";
  hr = RegQueryValueEx(hKey, psz, 0, &dwType, (LPBYTE)szBuff, &dwLen);

  if(ERROR_SUCCESS != hr)
  {

   return hr;
  }

  cInputDateSeparator = szBuff[0];

  // Get the InputDateFormat value in szBuff
  dwType = 0;
  dwLen=sizeof(szBuff);
  psz = "InputDateFormat";
  hr = RegQueryValueEx(hKey, psz, 0, &dwType, (LPBYTE)szBuff, &dwLen);

  if(ERROR_SUCCESS != hr){
   return hr;
  }

  strcpy(cInputDateFormat, szBuff);
  //
  // Find Where database was installed
  //
  psz = "Software\\Microsoft\\Windows\\CurrentVersion";

  // Open Key
  hr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, psz, 0, KEY_READ, &hKey);

  if(ERROR_SUCCESS != hr)
   return -1;

  // Get the value
  dwType = 0;
  dwLen=sizeof(szBuff);
  psz = "CommonFilesDir";
  hr = RegQueryValueEx(hKey, psz, 0, &dwType, (LPBYTE)szBuff, &dwLen);

  if(ERROR_SUCCESS != hr)
   return -1;

  // Append to path
  tempbstr = A2W(szBuff);
  tempbstr += "\\3MHIS\\ScheduleSetup\\Schedule.mdb";

  RegCloseKey (hKey);

  dbinit.AddProperty(DBPROP_AUTH_CACHE_AUTHINFO, true);
  dbinit.AddProperty(DBPROP_AUTH_ENCRYPT_PASSWORD, false);
  dbinit.AddProperty(DBPROP_AUTH_MASK_PASSWORD, false);
  dbinit.AddProperty(DBPROP_AUTH_PASSWORD, OLESTR(""));
  dbinit.AddProperty(DBPROP_AUTH_PERSIST_ENCRYPTED, false);
  dbinit.AddProperty(DBPROP_AUTH_USERID, OLESTR("Admin"));
  dbinit.AddProperty(DBPROP_INIT_DATASOURCE, tempbstr);
  //dbinit.AddProperty(DBPROP_INIT_DATASOURCE, OLESTR("schedule.mdb"));
  //dbinit.AddProperty(DBPROP_INIT_DATASOURCE,
OLESTR("E:\\wigit\\dbserver\\Debug\\schedule.mdb"));
  dbinit.AddProperty(DBPROP_INIT_MODE, (long)16);
  dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
  dbinit.AddProperty(DBPROP_INIT_PROVIDERSTRING,
OLESTR(";COUNTRY=0;CP=1252;LANGID=0x0409"));
  dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);

  hr = db.OpenWithServiceComponents(_T("Microsoft.Jet.OLEDB.4.0"),
&dbinit);

  if (ERROR_SUCCESS != hr)
   return hr;

  hr = m_session.Open(db);
  return hr;
 }

 HRESULT OpenRowset()
 {
  CComBSTR sqlBSTR;
   CDBPropSet dbinit(DBPROPSET_DBINIT);
  CCommand<CAccessor<CscheduleAccessor> > schedule;

  sqlBSTR = "SELECT * FROM ";
  sqlBSTR += "schedule";
  sqlBSTR += " WHERE UserKey1 = ?";

  USES_CONVERSION;
  return CCommand<CAccessor<CscheduleAccessor> >::Create(m_session,
_T(W2A(sqlBSTR)));

  //return CCommand<CAccessor<CscheduleAccessor> >::Create(m_session,
_T("SELECT * FROM schedule WHERE UserKey1 = ?"));
  //return CCommand<CAccessor<CscheduleAccessor> >::Open(m_session);
 }

 CSession m_session;
 CDataSource db;

 TCHAR  cInputDateSeparator;
 TCHAR  cInputDateFormat[80];

Quote:
};



Sun, 22 Aug 2004 04:20:49 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. ATL COM - Passing ATL COM classes through another ATL COM class in the same app

2. Accessing COM class members when passed in to a COM class

3. Constructing a member out of the class constructor

4. Howto Expose a normal C++ class with methods via an Interface Class in ATL COM

5. Constructing each instance of a class in an array of classes

6. ATL class in non-ATL class

7. Inherit multiple Com Classes into one Com class

8. How to access a member variable of a class from other class

9. I am not able to see my database class members in class view - Please help

10. does static class member change class size?

11. Classes as member variables of another class

12. Using vector of class A as member of class A

 

 
Powered by phpBB® Forum Software