C ++ import and use of ADO

I have two short questions related to importing and using ADO in a C ++ project. I do not experience ADO in any form.

Firstly, so far the database aspect of my program should only run on Windows. Is it enough to check if _WIN32 or _WIN64 were defined before running the special ADO code, or are there more efficient approaches? I am using Visual C ++ 2010 Express as my compiler.

Secondly, I follow this page as my guide. I have included the #import instruction for msado15.dll. The #import directive is underlined in red, and the error I get when I hover over it says: "... cannot open the path to the source file / in / msado15.tlh", and any ADO files that I copy to the source code remain red. I checked the directory indicated in the error message, and msado15.tlh is, if that matters. In addition, the program compiles (it crashes, although after its execution, but I will diagnose something else separately).

I pretty much don't know why this is happening. Any help or advice would be appreciated.

+5
source share
2 answers

, V++ Directories/Include

$(ProgramFiles)\Common Files\System\ado

:

#import "msado15.dll" rename_namespace("ADO") rename("EOF", "EndOfFile") no_implementation

cpp

#import "msado15.dll" rename_namespace("ADO") rename("EOF", "EndOfFile") implementation_only

, EOF.

++ MSDN

++ MSDN

+9

, ADO. ( , ...) , , .

 #import "C:\Program\Delade filer\System\ado\msado15.dll" rename_namespace("USEADO"),rename("EOF","EndOfFile") .

cpp :

#include "stdafx.h"

int SQLsetInfo(THING *Thing, GADGET *Gadget)
{

HRESULT hr;                                                         
USEADO::_ConnectionPtr connection;                                  
USEADO::_RecordsetPtr recordset;                                    

 //Initialize COM  
    if(FAILED(hr = CoInitialize(NULL)))                         
    {   MessageBox( NULL, L"Initialize COM Failed", L"MyProg!",MB_ICONEXCLAMATION |MB_OK);
        //Do something, eg shut down DB stuff and continue without or exit program
        //Insert error handeler below
        return hr;//TODO Ad error handeling see line 149
    }   

if(FAILED(hr = connection.CreateInstance(__uuidof(USEADO::Connection))))
    {   MessageBox( NULL, L"Create connection instance Failed", L"MyProg!",MB_ICONEXCLAMATION |MB_OK);
        //Do something, eg shut down DB stuff and continue without or exit program
        return hr;
    }

if(FAILED(hr = recordset.CreateInstance(__uuidof(USEADO::Recordset))))
    {   MessageBox( NULL, L"Create recordset instance Failed", L"MyProg!",MB_ICONEXCLAMATION |MB_OK);
        //Do something, eg shut down DB stuff and continue without or exit program 
        return hr;
    }

    connection->CursorLocation = USEADO::adUseServer; //http://dev.mysql.com/tech-resources/articles/vb-cursors-and-locks.html                                           

    //Try to connect to SQL server
    try         { connection->Open(L"YOUR CONNECTION STRING", USEADO::adConnectUnspecified);    }
    catch(...)  {std::cout << "!!! connection->Open(ConnectionString   FAILED !!!" << std::endl;        }

++, . , . - / , ....

+2

All Articles