MuruganAD.Net


Using Active X Data objects . Reads the content of .mdb file and displays it .
----------------------------------------
Program  : ADO Win32 Console Application 
FileName : ADOTest.cpp
I/P 	 : Requieres an .mdf file
O/P 	 : Displays Fields from .mdf
By       : Murugan AD 
----------------------------------------

#include "stdio.h"
#include "afxdisp.h"
#include "stdlib.h"

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

struct InitOle {
    InitOle()  { ::CoInitialize(NULL); }
    ~InitOle() { ::CoUninitialize();   }
} _init_InitOle_;       // Global Instance to force load/unload of OLE


void main(){

    _RecordsetPtr   spRS;
    _ConnectionPtr  spCON;
 	spCON.CreateInstance(__uuidof(Connection));
    spCON->ConnectionString = L"driver={sql server};SERVER=(local);Database=pubs;"
                              L"UID=sa; PWD=;"; 
    spCON->ConnectionString =L"DRIVER={Microsoft Access Driver (*.mdb)};"
			                  L"DBQ=authors.MDB;DefaultDir=C:\\test;"; 
	spCON->Open( "", "", "", -1 );

	spRS.CreateInstance(__uuidof(Recordset));
	spRS->PutRefActiveConnection( spCON );
	spRS->Open("select au_lname, au_fname from authors", vtMissing, adOpenKeyset,
                    adLockBatchOptimistic, -1);
        
    while(spRS->adoEOF == false){															
        printf("au_lname = %s  au_fname = %s \n", (char *) _bstr_t(spRS->Fields->Item[_variant_t(0L)]->Value),
                                             (char *) _bstr_t(spRS->Fields->Item[_variant_t("au_fname")]->Value));
        spRS->MoveNext();
	}
    spRS->Close();
    spCON->Close();
    getchar();
}


Generete Executable using Visual C++ 
Version : 6.0


Test Code for using ACOSSmartCard Component
----------------------------------------
Program  : COM Win32 Application 
FileName : ADOTest.cpp
I/P 	 : 
Note 	 : Create A VC++ Win32 Hello World Application 
	   and add additional code as instructed
By       : Murugan AD 
----------------------------------------

Define Local Variables
	IACOSSmartcard	*SmartCard;
	wchar_t hello[100] = L"Hello World";
	BSTR bstrHello;

ADD CODE TO WM_CREATE
	::CoInitialize(NULL);
	HRESULT hr;
	hr=::CoCreateInstance(CLSID_ACOSSmartcard,NULL,CLSCTX_INPROC_SERVER,IID_IACOSSmartcard,(void **)&SmartCard);
	bstrHello = ::SysAllocString(hello);
 	SmartCard->PCSC_SCardEstablishContext(bstrHello);



Generete Executable using Visual C++ 
Version : 6.0

COM Test Code for passing structure using Variant data type
----------------------------------------
Program  : COM Win32 Application 
FileName : ADOTest.cpp
I/P 	 : 
Note 	 : Create A VC++ ATL Application 
	   and add additional code 
By       : Murugan AD 
----------------------------------------

// Test Data for Passing between args..
typedef struct sTest
{
 int X;
 int Y;
}Arg;
 
/*  TestMethod  Declaration ....
HRESULT TestMethod([in] VARIANT vtValue , [out] VARIANT* vtResult);
*/
STDMETHODIMP Citest::TestMethod(VARIANT vtValue, VARIANT* vtResult)
{
 // TODO: Add your implementation code here
 
 Arg *pData;
 if( vtValue.vt == (VT_BYREF|VT_UI1))
 {
  pData = (sTest *)vtValue.pbVal;
 
  pData->X += 100;
  pData->Y += 100;
  
  VariantInit(vtResult);
  vtResult->vt = VT_BYREF|VT_UI1;
  vtResult->pbVal = (BYTE *)pData;
 
 }
 
 return S_OK;
}

//CLIENT CALLING...
// include these files
#include "TEst_i.c"
#include "TEst.h"
 
//
typedef struct sTest
{
 int X;
 int Y;
}Arg;
 
void CTestMenuHandlesDlg::OnButton1() 
{
 CoInitialize(0);
 HRESULT hr = 0;
 Iitest *pTest;
 VARIANT vtVal , vtResult;
 Arg *pData = new Arg;
 
 pData->X = 10;
 pData->Y = 10;
 
 VariantInit(&vtVal );
 vtVal.vt = VT_BYREF|VT_UI1;
 vtVal.pbVal = (BYTE *)pData;
 
 hr = CoCreateInstance(CLSID_itest , 0, CLSCTX_ALL , IID_Iitest, (void **)&pTest);
 
 
 hr = pTest->TestMethod( vtVal,&vtResult);
 pData = (Arg *)vtResult.pbVal; 
 
}

Generete Executable using Visual C++ 
Version : 6.0


HOME ABOUT ME ARTICLES LINKS DOWNLOADS 8086 C++ VC++ SITEMAP INDEX