Help on ADO with ObjectARX

Help on ADO with ObjectARX

Anonymous
Not applicable
494 Views
1 Reply
Message 1 of 2

Help on ADO with ObjectARX

Anonymous
Not applicable
I am just trying to get connection to external database using ado
#import directive. Infact I just merged the code from two samples and they works fine separately but when I pull them together its showing following errors:

c:\temp\aaa\debug\msado15.tlh(2667) : error C2059: syntax error : 'constant'
c:\temp\aaa\debug\msado15.tlh(2667) : error C2238: unexpected token(s) preceding ';'

code:
// aaa.cpp : Initialization functions
#include "StdAfx.h"
#include "StdArx.h"
#include "resource.h"
#include
#import "C:\Program Files\Common Files\System\ado\MSADO15.dll" rename("EOF", "ADOEOFile")
void mydbcon();

struct StartOLEProcess{
StartOLEProcess( ) {
::CoInitialize(NULL);
}
~StartOLEProcess( ) {
::CoUninitialize( );
}
} _start_StartOLEProcess;


// This command registers an ARX command.
void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal = -1);

// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_MSG
void InitApplication();
void UnloadApplication();
//}}AFX_ARX_MSG

// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_ADDIN_FUNCS
//}}AFX_ARX_ADDIN_FUNCS


/////////////////////////////////////////////////////////////////////////////
// ObjectARX EntryPoint
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
switch (msg) {
case AcRx::kInitAppMsg:
// Comment out the following line if your
// application should be locked into memory
acrxDynamicLinker->unlockApplication(pkt);
acrxDynamicLinker->registerAppMDIAware(pkt);
InitApplication();
break;
case AcRx::kUnloadAppMsg:
UnloadApplication();
break;
}
return AcRx::kRetOK;
}


// Init this application. Register your
// commands, reactors...
void InitApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_INIT
//}}AFX_ARX_INIT

acedRegCmds->addCommand("MYDBCON_COMMANDS",
"dblog",
"dblog",
ACRX_CMD_MODAL,
mydbcon);


// TODO: add your initialization functions

}

// Unload this application. Unregister all objects
// registered in InitApplication.
void UnloadApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_EXIT
//}}AFX_ARX_EXIT

// TODO: clean up your application
acedRegCmds->removeGroup("HELLOWORLD_COMMANDS");
}

// This functions registers an ARX command.
// It can be used to read the localized command name
// from a string table stored in the resources.
void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal)
{
char cmdLocRes[65];

// If idLocal is not -1, it's treated as an ID for
// a string stored in the resources.
if (idLocal != -1) {
HMODULE hModule = GetModuleHandle("Adskaaa.arx");

// Load strings from the string table and register the command.
::LoadString(hModule, idLocal, cmdLocRes, 64);
acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes, cmdFlags, cmdProc);

} else
// idLocal is -1, so the 'hard coded'
// localized function name is used.
acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLoc, cmdFlags, cmdProc);
}

void mydbcon()
{

acutPrintf("\nCreating db connection!");

// define our variables which will be used as references to the
// Connection and Recordset objects

ADODB::_ConnectionPtr con = NULL;
ADODB::_RecordsetPtr rec = NULL;

// define variables to read the Author field from the recordset

ADODB::FieldPtr pAuthor;
_variant_t vAuthor;
char sAuthor[40];

// create two strings for use with the creation of a Connection
// and a Recordset object

bstr_t sConString;
bstr_t sSQLString;

// create a variable to hold the result to function calls

HRESULT hr = S_OK;

// long variable needed for Execute method of Connection object

VARIANT *vRecordsAffected = NULL;

// create a new instance of an ADO Connection object

hr = con.CreateInstance(__uuidof(ADODB::Connection));

acutPrintf("Connection object created.\n");

// open the BiblioDSN data source with the Connection object

sConString = L"Provider=Microsoft.Jet.OLEDB.4.0; "
L"Data Source=C:\\Temp\\mydb.mdb";

con->Open(sConString, L"", L"", -1);

acutPrintf("Connection opened.\n");

// create a Recordset object from a SQL string

sSQLString = L"SELECT password FROM tbl_master where user_id=='mal';";

rec = con->Execute(sSQLString,
vRecordsAffected,
1);

acutPrintf("SQL statement processed.\n");

// point to the Author field in the recordset

pAuthor = rec->Fields->GetItem("Author");

// retrieve all the data within the Recordset object

acutPrintf("Getting data now...\n\n");

while(!rec->ADOEOFile) {

// get the Author field's value and change it
// to a multibyte type
vAuthor.Clear( );

vAuthor = pAuthor->Value;

WideCharToMultiByte(CP_ACP,
0,
vAuthor.bstrVal,
-1,
sAuthor,
sizeof(sAuthor),
NULL,
NULL);

acutPrintf("%s\n", sAuthor);

rec->MoveNext( );

}

acutPrintf("\nEnd of data.\n");

// close and remove the Recordset object from memory

rec->Close( );
rec = NULL;

acutPrintf("Closed an removed the "
"Recordset object from memory.\n");

// close and remove the Connection object from memory

con->Close( );
con = NULL;

acutPrintf("Closed and removed the "
"Connection object from memory.\n");

}


Please help me.
ObjectARX 2000
VS 6.0
Windows 2000 SP4
ADO 2.8

Regards

Alam
0 Likes
495 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Thanx to google after many ours of searching with various combinations of keywords I found that it was due to naming conflict and modifying my #import directive to :

#import "c:\\program files\\common files\\system\\ado\\msado15.dll"
\
rename ("EOF", "adoEOF") \
rename("EOS","AdoEOS")

solved my problem.

Regards

Alam