?
Solved

#import directive  and MS access

Posted on 2000-05-03
11
Medium Priority
?
547 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

743 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