Solved

#import directive  and MS access

Posted on 2000-05-03
11
539 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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 250 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

756 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