Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

#import directive  and MS access

Posted on 2000-05-03
11
Medium Priority
?
551 Views
Last Modified: 2008-03-06
I am trying to create a com object of MS access, using the import directive in a windows C++ dll [not MFC]. but I was faced with some compilation errors. Can any one help?
0
Comment
Question by:zakmol
[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
11 Comments
 

Author Comment

by:zakmol
ID: 2774917
Using VC++ v6.0 - again it is not MFC.
0
 

Expert Comment

by:sklose
ID: 2775657
Could you paste in the compilation errors so we can see what they are?

A little more detail would help us to help you :)
0
 

Author Comment

by:zakmol
ID: 2775716
in my .cpp file I typed
#import "D:\Program Files\Microsoft Office\Office\Msacc9.olb" no_namespace

and the following are the errors
debug\msacc9.tlh(2085) : error C2504: 'Property' : base class undefined
debug\msacc9.tlh(2992) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(4660) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(5345) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(6100) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(6857) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(7471) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(8272) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(9377) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(10302) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(11404) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(12316) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(13777) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(14272) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(14790) : error C2504: 'IAccessible' : base class undefined
debug\msacc9.tlh(15306) : error C2504: 'IAccessible' : base class undefined
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:zakmol
ID: 2778095
Adjusted points from 100 to 125
0
 
LVL 4

Expert Comment

by:saurabh_dasgupta
ID: 2778309
I am using MS Access through #import compiler directive (no MFC support at all, VC 50)
In the following sample, I have written a simple stand alone function for counting the number of records in a specified table.



#import     <dao350.dll> rename("EOF","EOFdao") //for DAO interfaces

#import   <comdef.h>
#include  <stdio.h>

void main()
{
    HRESULT hr=NOERROR;
    _bstr_t bstrDbName ="c:\\temp\\MyDB.mdb";

    DAO::_DBEnginePtr iDbEngine;
    //this is the DAO database engine object

    DAO::DatabasePtr iDbs;

    hr=
    iDbEngine.CreateInstance(L"DAO.DBEngine.35");
    //check for errors

    hr=
    iDbEngine->raw_OpenDatabase(
                    bstrDbName,
                    vtMissing,
                    vtMissing,
                    vtMissing,
                    &iDbs);
    //check for errors

   //use iDbs for querying the DB


//count the records in some valid table
   long nCount =0;
   char lpsTableName[200] = "Students";

   hr=
   _count_records  (iDbs,lpsTableName,&nCount);
   //check hr for errors

   printf("no of records in table %s=" ,lpsTableName,nCount);

}




HRESULT _count_records(
                        DAO::DatabasePtr objDb ,
                    const char* lpcstrTableName,
                        long *nCount
                        )
    /*
    counts the total no of records in the given table     */
    {

    HRESULT hr=NOERROR;
    DAO::RecordsetPtr objRecSet;
    char lpsQuery[512]="";
    _bstr_t bstrQuery;
    long count=0;

    *nCount=0;
    sprintf(
            lpsQuery,
            "select * from %s ",
            lpcstrTableName
            );
    bstrQuery=lpsQuery;
    hr=objDb->raw_OpenRecordset(
                            bstrQuery,
                            vtMissing,
                            vtMissing,
                            vtMissing,
                            &objRecSet);
    //check hr for errors

    while(objRecSet->GetEOFdao() != VARIANT_TRUE)
        {
        count++;
        objRecSet->MoveNext();
        }

    *nCount = count;
wrapup:
    return hr;
}
0
 

Author Comment

by:zakmol
ID: 2778531
Adjusted points from 125 to 150
0
 

Author Comment

by:zakmol
ID: 2778532
Thanks for what you have posted, I need to use MS access object model and not DAO, for example using MS Access object model you can create forms, run wizards and so, I succeeded in VB, but not in VC
0
 

Author Comment

by:zakmol
ID: 2778636
Thanks for what you have posted, I need to use MS access object model and not DAO, for example using MS Access object model you can create forms, run wizards and so, I succeeded in VB, but not in VC

0
 

Author Comment

by:zakmol
ID: 2780761
Adjusted points from 150 to 175
0
 

Author Comment

by:zakmol
ID: 2789307
Adjusted points from 175 to 250
0
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 750 total points
ID: 2792031
when you look at the top of the .tlh file you will see a section called 'Cross-referenced type libraries:' it was these you were missing

try the following:

(unfortunatly you will need to use namespaces as there is too much conflict otherwise)

Note they may be different on you machine so be prepared to look around :)

#import "D:\Program Files\Common Files\System\Ado\msado15.dll" rename("EOF","EOFmsa")
#import "D:\Program Files\Common Files\Microsoft Shared\DAO\DAO360.DLL" rename("EOF","EOFdao")
#import "D:\Program Files\Microsoft Office\Office\MSO9.DLL"
#import "D:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"
//#import "D:\Program Files\Common Files\Microsoft Shared\DAO\dao350.dll" no_namespace rename("EOF","EOFdao") //for DAO interfaces

#import "D:\Program Files\Microsoft Office\Office\Msacc9.olb"

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

647 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