ProductsTechnical SupportDownloadsPurchasingSearch EngineNewsHomeE-mail Us


The easiest way to use ACE/400 DAO with Visual C++ is to use the #import pragma. At the beginning of each module using ACE/400 DAO, some code must be added:

#include "stdafx.h" // if MFC project only
#include <atlbase.h> // if using ATL objects only (useful to enable
// CcomVariant classes)
#ifdef EOF // we must disable EOF macro
#undef EOF
#endif

#import "C:\\RELEASE\\EACDAO\\EACDAO.OCX" exclude("_DACE400")


Please note that includes are optional (if not using MFC), but must be included before the #import directive. Once this #import is done, there is automatic access to the interfaces of the Type library.
Here are some interface/class relationships:

ACE400 IACE400Ptr
Database IACE400DatabasePtr
Databases IACE400DatabasesPtr
Recordset IACE400RecsetPtr
Field IACE400Field
Fields IACE400Fields

With visual C++, we must declare the variables with interface names convensions. Here is a sample of code made with Visual C++:

using namespace EACDAO;
HRESULT hret;
IACE400Ptr ace400;
IACE400DatabasePtr db;
IACE400DatabasesPtr dbs;
IACE400RecsetPtr tb;
IACE400FieldPtr fld;

VARIANT fldvalue; BSTR fldname;

CoInitialize(NULL); // init of Com
VariantInit(&fldvalue);

hret = ace400.CreateInstance("ACE400.ACE400");
db = ace400->OpenDatabase("",&vtMissing,0,"");
tb = db->OpenRecordSet("P$CLIENT",(RecordsetOptionEnum)0);

tb->MoveFirst();

while (!tb->EOF)

for (int i=0;i<tb->Fields->Count;i++)
fld = tb->Fields->Item[CComVariant(i)];
VariantCopy(&fldvalue,&fld->Value);
// Convert it to strings to display it!
VariantChangeType(&fldvalue,&fldvalue,0,VT_BSTR);
fldname = fld->Name;
TRACE("Field %S, value %S\n",fldname,fldvalue.bstrVal);

tb->MoveNext();

Back Visual Basic Excel and VBA Applications VBScript Powerbuilder