Solved

#import directive  and MS access

Posted on 2000-05-03
11
526 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now