Solved

#import directive  and MS access

Posted on 2000-05-03
11
538 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

809 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