Solved

RecordSet from COM in C++

Posted on 2009-06-30
14
594 Views
Last Modified: 2013-11-26
I am accessing a DLL written in VB which has a number of methods.  This DLL is designed to sign onto a sqlserver database and return various information depending on the methods called.

To date I have managed to CoCreateInstance and successfully access several of these methods.

My issue is this:   Several of these methods return a record set with possibly multiple rows of data and I have no idea how to create a record set in VC++ and how access it.

This is the description of one of the methods I am trying to use:

GetCustomerList()
   Returns a RecordSet of all customer fields

Required Properties
  LastName

RecordSet Layout
  uidCustomerID
  strCustNo
  strMem_Ext
  strTitle
  strFirstName
  strMiddleInitial
  strLastName


In the attached code (I have removed pieces to make it easier to read), you can see how I have accessed some of the methods:

The method GetCustomerList requires the property of LastName to be set prior to calling and will  return a RecordSet of all the Customers with the last name given.

How do I construct this record set and walk through it?

Thanks for all help
Phil


_WebRes *wr;

		hresult=CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, __uuidof(_WebRes), (LPVOID *)&wr);

//	

		bool bCon = wr->Connect("GXX", "");

		bool bSUser = wr->SetUser("GXX");

//

		BSTR bstrMess;

//

		wr->FirstName = "Davis";

		wr->LastName = "Phil";

		wr->PhoneNo = "123 456 7890";

		wr->Display = "Davis, Phil";

		wr->Email = "phil@email.com";

//

		bool bCust = wr->CreateCustomer(&bstrMess);

//

		CString str(bstrMess);

		MessageBox(str);       // this works fine

//

		wr->LastName = _bstr_t ("Davis");

		Record Set = wr->GetCustomerList();  // what to do here.
 

//

//  the above call to GetCustomerList will return a RecordSet of all the customers with a 

//  last name  Davis.  The Record set will contain the information about each individual customer

//

//  How do I create and access this recordset in 'C' 

//

Open in new window

0
Comment
Question by:BeerFizz
  • 7
  • 5
  • 2
14 Comments
 
LVL 5

Assisted Solution

by:iUsername
iUsername earned 50 total points
ID: 24746475
import ADO:

#import "C:\Program Files\Common Files\System\ADO\msado15.dll" rename("EOF", "ADOEOF") rename("Property", "PProperty")

Create a recordset instance:

using namespace ADODB;

_RecordsetPtr ptrRS;
HRESULT hr = ptrRS.CreateInstance(__uuidof(Recordset));
if(FAILED(hr)){ /* exception */ }

p.s.
Don't forget CoInitialize(), CoUnInitialize()!
0
 

Author Comment

by:BeerFizz
ID: 24746833
Hi,

Thanks for responding.   Unfortunately I am a beginner with all this...

having created the prtRS, how do I use it?  If you could supply some example code that would be great.

Thanks
Phil
0
 
LVL 5

Expert Comment

by:iUsername
ID: 24747258
Oh, okay, sure :-)

First of all, in order to use COM, you first need to call CoInitialize().
For most cases you don't need any special parameters for CoInitialize(), so just call CoInitialize(NULL). (so I won't get into that, but you are more than welcome to read the documentation for that function.)

When you're done with all the COM stuff, you must call CoUninitialize().

--------

When you use the #import of the msado15.dll you import COM objects that provides you ADODB functionality (connecting to databases, performing queries etc.).

Now, You wrote that some of the functions return a recordset object.
ADODB has a recordset object which is called Recordset.

ADODB::_RecordsetPtr is a smart pointer to a Recordset object.
So, we declare that smart pointer in this line:
_RecordsetPtr ptrRS;

Now, we need to create an instance of RecordSet that ptrRS will point to.
We do this using this line:
HRESULT hr = ptrRS.CreateInstance(__uuidof(Recordset));

The __uuidof(), in a very very short explanation, returns a GUID (unique "number") that tells the CreateInstance() function to attach ptrRS pointer an instance of Recordset.

We need to check if everything worked fine, and we do this using this line of code:
if(FAILED(hr)){ /* exception */ }

The HRESULT object (hr) contains a number that says if the function succeeded or failed.
using FAILED macro we can tell if the function failed.
If there is a failure, and the number of the HRESULT is the error number.

Now, if everything works fine, you have an instance of Recordset.

------

In your case, you said that you get the recordset from a function, so "wr->GetCustomerList();" should return an ADODB::_RecordsetPtr object.

(if it is not that object, or any ADODB object, it might be something that is uniquely been created for your project.)
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24747890
>>>> having created the prtRS, how do I use it?  
You can use the methods defined for RecordSet like


  prtRS->MoveFirst();

which would move to the first record of an opened recordset (if any).

Look at http://msdn.microsoft.com/en-us/library/ms677527(VS.85).aspx or get index 'Recordset object [ADO], members' in MSDN help.

There are a lot of sample code as links.
0
 

Author Comment

by:BeerFizz
ID: 24749392
Thanks guys for the help so far.

So, in the code attached, this is as far as I've gotten.


		wr->LastName = _bstr_t ("Davis");
 

		using namespace ADODB;
 

		ADODB::_RecordsetPtr ptrRS;

		hresult = ptrRS.CreateInstance(__uuidof(ADODB::Recordset));

		if(FAILED(hresult)) {

			MessageBox("ptrRS.CreateInstance Failed *****");

		}
 

		ptrRS = wr->GetCustomerList();

		ptrRS->MoveFirst();
 

///////////////////////////////////////////////////
 

gotten this far without a crash...
 

//////////////////////////////////////////////////
 

so how do I get at the data?
 

I could do this, but it crashes:
 
 

		_bstr_t  bstrFName;

		bstrFName = ptrRS->Fields->Item["FirstName"]->Value;
 
 

or I could do this, which doesn't crash, but how do I get the data out of the variant?
 
 

	_variant_t vtRows = ptrRS->GetRows(ADODB::adGetRowsRest);

Open in new window

0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24749515
>>>> I could do this, but it crashes:
I have little to no experiences with ADODB  (actually I always was using MFC CRecordset class, which was much more straight-forward than the COM variant). But it shouldn't crash.

You may check which of the ptrRS, ptrRS->Fields, ptrRS->Fields->Item["FirstName"] is NULL (I would guess the last one), what is the reason why it crashes.

If it is the  ptrRS->Fields->Item["FirstName"], the recordset probably wasn't fully defined til now, i. e. the ptrRS doesn't know the column names so far. If I was right, we need to check how we can add field information to a recordset, what surely could be found out when looking at a more complete sample code.



   
0
 

Author Comment

by:BeerFizz
ID: 24749719
When I import the ttext.dll a .tlh and a .tli are created.

I am attaching the .tlh to see if the helps any...
// Created by Microsoft (R) C/C++ Compiler Version 14.00.50727.42 (2ecf2b05).

//

// c:\documents and settings\phild\my documents\visual studio code\vbdll\vcclient\debug\ttext.tlh

//

// C++ source equivalent of Win32 type library TTExt.dll

// compiler-generated file created 06/26/09 at 13:23:52 - DO NOT EDIT!
 

#pragma once

#pragma pack(push, 8)
 

#include <comdef.h>
 

//

// Forward references and typedefs

//
 

struct __declspec(uuid("e897466c-75b0-459f-9512-21d42e1f5703"))

/* LIBID */ __TTExt;

struct __declspec(uuid("dc8718c4-d07f-4542-a799-f2015a0614cf"))

/* dual interface */ _WebRes;

struct /* coclass */ WebRes;
 

//

// Smart pointer typedef declarations

//
 

_COM_SMARTPTR_TYPEDEF(_WebRes, __uuidof(_WebRes));
 

//

// Type library items

//
 

struct __declspec(uuid("dc8718c4-d07f-4542-a799-f2015a0614cf"))

_WebRes : IDispatch

{

    //

    // Property data

    //
 

    __declspec(property(get=GetLastError))

    _bstr_t LastError;

    __declspec(property(get=GetDatabase,put=PutDatabase))

    _bstr_t Database;

    __declspec(property(get=GetServer,put=PutServer))

    _bstr_t Server;

    __declspec(property(put=PutResNotes))

    _bstr_t ResNotes;

    __declspec(property(get=GetReservationID))

    _bstr_t ReservationID;

    __declspec(property(get=GetConfirmationNumber))

    _bstr_t ConfirmationNumber;

    __declspec(property(put=PutVoucherNo))

    long VoucherNo;

    __declspec(property(put=PutNumberOfPlayers))

    long NumberOfPlayers;

    __declspec(property(put=PutSelectedSlot))

    _bstr_t SelectedSlot;

    __declspec(property(put=PutPlayDate))

    DATE PlayDate;

    __declspec(property(put=PutEndTime))

    DATE EndTime;

    __declspec(property(put=PutStartTime))

    DATE StartTime;

    __declspec(property(put=PutTee))

    _bstr_t Tee;

    __declspec(property(put=PutFacility))

    _bstr_t Facility;

    __declspec(property(get=GetCustomerID,put=PutCustomerID))

    _bstr_t CustomerID;

    __declspec(property(put=PutCreditCardExpDate))

    _bstr_t CreditCardExpDate;

    __declspec(property(put=PutCreditCard))

    _bstr_t CreditCard;

    __declspec(property(put=PutEmail))

    _bstr_t Email;

    __declspec(property(put=PutFaxNo))

    _bstr_t FaxNo;

    __declspec(property(put=PutPhoneExt))

    _bstr_t PhoneExt;

    __declspec(property(put=PutPhoneNo))

    _bstr_t PhoneNo;

    __declspec(property(put=PutCountry))

    _bstr_t Country;

    __declspec(property(put=PutState))

    _bstr_t State;

    __declspec(property(put=PutCompany))

    _bstr_t Company;

    __declspec(property(put=PutCity))

    _bstr_t City;

    __declspec(property(put=PutZip))

    _bstr_t Zip;

    __declspec(property(put=PutDisplay))

    _bstr_t Display;

    __declspec(property(put=PutAddress2))

    _bstr_t Address2;

    __declspec(property(put=PutAddress1))

    _bstr_t Address1;

    __declspec(property(put=PutMidInitial))

    _bstr_t MidInitial;

    __declspec(property(put=PutFirstName))

    _bstr_t FirstName;

    __declspec(property(get=GetLastName,put=PutLastName))

    _bstr_t LastName;
 

    //

    // Wrapper methods for error-handling

    //
 

    _variant_t GetCustomerList ( );

    VARIANT_BOOL CreateCustomer (

        BSTR * ReturnMessage );

    _variant_t GetFacilityList ( );

    _variant_t GetSlotsAvailable ( );

    VARIANT_BOOL CreateReservation (

        BSTR * ReturnMessage );

    _variant_t GetReservationsForConfirmationNo (

        _bstr_t ConfirmationNo );

    VARIANT_BOOL CancelReservation (

        _bstr_t ReservationID,

        BSTR * ReturnMessage );

    _variant_t GetServers ( );

    VARIANT_BOOL Connect (

        _bstr_t vendor_name,

        _bstr_t ini_path );

    VARIANT_BOOL Connect1 (

        _bstr_t Server,

        _bstr_t Database );

    _bstr_t GetLastName ( );

    void PutLastName (

        _bstr_t _arg1 );

    void PutFirstName (

        _bstr_t _arg1 );

    void PutMidInitial (

        _bstr_t _arg1 );

    void PutAddress1 (

        _bstr_t _arg1 );

    void PutAddress2 (

        _bstr_t _arg1 );

    void PutDisplay (

        _bstr_t _arg1 );

    void PutZip (

        _bstr_t _arg1 );

    void PutCity (

        _bstr_t _arg1 );

    void PutCompany (

        _bstr_t _arg1 );

    void PutState (

        _bstr_t _arg1 );

    void PutCountry (

        _bstr_t _arg1 );

    void PutPhoneNo (

        _bstr_t _arg1 );

    void PutPhoneExt (

        _bstr_t _arg1 );

    void PutFaxNo (

        _bstr_t _arg1 );

    void PutEmail (

        _bstr_t _arg1 );

    void PutCreditCard (

        _bstr_t _arg1 );

    void PutCreditCardExpDate (

        _bstr_t _arg1 );

    _bstr_t GetCustomerID ( );

    void PutCustomerID (

        _bstr_t _arg1 );

    void PutFacility (

        _bstr_t _arg1 );

    void PutTee (

        _bstr_t _arg1 );

    void PutStartTime (

        DATE _arg1 );

    void PutEndTime (

        DATE _arg1 );

    void PutPlayDate (

        DATE _arg1 );

    void PutSelectedSlot (

        _bstr_t _arg1 );

    void PutNumberOfPlayers (

        long _arg1 );

    void PutVoucherNo (

        long _arg1 );

    _bstr_t GetConfirmationNumber ( );

    _bstr_t GetReservationID ( );

    void PutResNotes (

        _bstr_t _arg1 );

    void PutServer (

        _bstr_t _arg1 );

    void PutDatabase (

        _bstr_t _arg1 );

    VARIANT_BOOL SetResellerCode (

        _bstr_t InterfaceResellerCode );

    VARIANT_BOOL SetUser (

        _bstr_t Name );

    _bstr_t GetLastError ( );

    _bstr_t GetServer ( );

    _bstr_t GetDatabase ( );
 

    //

    // Raw methods provided by interface

    //
 

      virtual HRESULT __stdcall raw_GetCustomerList (

        /*[out,retval]*/ VARIANT * _arg1 ) = 0;

      virtual HRESULT __stdcall raw_CreateCustomer (

        /*[in,out]*/ BSTR * ReturnMessage,

        /*[out,retval]*/ VARIANT_BOOL * _arg2 ) = 0;

      virtual HRESULT __stdcall raw_GetFacilityList (

        /*[out,retval]*/ VARIANT * _arg1 ) = 0;

      virtual HRESULT __stdcall raw_GetSlotsAvailable (

        /*[out,retval]*/ VARIANT * _arg1 ) = 0;

      virtual HRESULT __stdcall raw_CreateReservation (

        /*[in,out]*/ BSTR * ReturnMessage,

        /*[out,retval]*/ VARIANT_BOOL * _arg2 ) = 0;

      virtual HRESULT __stdcall raw_GetReservationsForConfirmationNo (

        /*[in]*/ BSTR ConfirmationNo,

        /*[out,retval]*/ VARIANT * _arg2 ) = 0;

      virtual HRESULT __stdcall raw_CancelReservation (

        /*[in]*/ BSTR ReservationID,

        /*[in,out]*/ BSTR * ReturnMessage,

        /*[out,retval]*/ VARIANT_BOOL * _arg3 ) = 0;

      virtual HRESULT __stdcall raw_GetServers (

        /*[out,retval]*/ VARIANT * _arg1 ) = 0;

      virtual HRESULT __stdcall raw_Connect (

        /*[in]*/ BSTR vendor_name,

        /*[in]*/ BSTR ini_path,

        /*[out,retval]*/ VARIANT_BOOL * _arg3 ) = 0;

      virtual HRESULT __stdcall raw_Connect1 (

        /*[in]*/ BSTR Server,

        /*[in]*/ BSTR Database,

        /*[out,retval]*/ VARIANT_BOOL * _arg3 ) = 0;

        

      virtual HRESULT __stdcall get_LastName (

        /*[out,retval]*/ BSTR * _arg1 ) = 0;

      virtual HRESULT __stdcall put_LastName (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_FirstName (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_MidInitial (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_Address1 (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_Address2 (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_Display (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_Zip (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_City (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_Company (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_State (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_Country (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_PhoneNo (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_PhoneExt (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_FaxNo (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_Email (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_CreditCard (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_CreditCardExpDate (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall get_CustomerID (

        /*[out,retval]*/ BSTR * _arg1 ) = 0;

      virtual HRESULT __stdcall put_CustomerID (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_Facility (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_Tee (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_StartTime (

        /*[in]*/ DATE _arg1 ) = 0;

      virtual HRESULT __stdcall put_EndTime (

        /*[in]*/ DATE _arg1 ) = 0;

      virtual HRESULT __stdcall put_PlayDate (

        /*[in]*/ DATE _arg1 ) = 0;

      virtual HRESULT __stdcall put_SelectedSlot (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_NumberOfPlayers (

        /*[in]*/ long _arg1 ) = 0;

      virtual HRESULT __stdcall put_VoucherNo (

        /*[in]*/ long _arg1 ) = 0;

      virtual HRESULT __stdcall get_ConfirmationNumber (

        /*[out,retval]*/ BSTR * _arg1 ) = 0;

      virtual HRESULT __stdcall get_ReservationID (

        /*[out,retval]*/ BSTR * _arg1 ) = 0;

      virtual HRESULT __stdcall put_ResNotes (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_Server (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall put_Database (

        /*[in]*/ BSTR _arg1 ) = 0;

      virtual HRESULT __stdcall raw_SetResellerCode (

        /*[in]*/ BSTR InterfaceResellerCode,

        /*[out,retval]*/ VARIANT_BOOL * _arg2 ) = 0;

      virtual HRESULT __stdcall raw_SetUser (

        /*[in]*/ BSTR Name,

        /*[out,retval]*/ VARIANT_BOOL * _arg2 ) = 0;

      virtual HRESULT __stdcall get_LastError (

        /*[out,retval]*/ BSTR * _arg1 ) = 0;

      virtual HRESULT __stdcall get_Server (

        /*[out,retval]*/ BSTR * _arg1 ) = 0;

      virtual HRESULT __stdcall get_Database (

        /*[out,retval]*/ BSTR * _arg1 ) = 0;

};
 

struct __declspec(uuid("d00de9f1-98eb-4cd9-8685-0ea4f283971f"))

WebRes;

    // [ default ] interface _WebRes
 

//

// Wrapper method implementations

//
 

#include "c:\documents and settings\phild\my documents\visual studio code\vbdll\vcclient\debug\ttext.tli"
 

#pragma pack(pop)

Open in new window

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:BeerFizz
ID: 24749749
There is no much to the code...  as I writing a test application at the moment.   See attached.
void CVCClientDlg::OnButton1() 

{

	HRESULT hresult;

	CLSID clsid;

	//CLSID clsid2;
 

		CoInitialize(NULL);
 

		hresult=CLSIDFromProgID(OLESTR("TTExt.WebRes"), &clsid);

		if(FAILED(hresult))

		{

			switch (hresult) {

				case CO_E_CLASSSTRING:

					AfxMessageBox("CLSID Failed -- registered CLSID for the ProgID is invalid");

					break;

				case REGDB_E_WRITEREGDB:

					AfxMessageBox("CLSID Failed -- error occurred writing the CLSID to the registry.");

					break;

				default:

					AfxMessageBox("CLSID Failed -- unknown reason");

					break;

			}

		}

		

		_WebRes *wr;

		IClassFactory *pCF;
 

		//hresult=CoGetClassObject(clsid, CLSCTX_INPROC_SERVER, NULL, IID_IClassFactory, (LPVOID *)&pCF);	

		//clsid2 = __uuidof(_WebRes);

		//hresult = pCF->CreateInstance(NULL, __uuidof(_WebRes), (LPVOID *)&wr);
 

		hresult=CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, __uuidof(_WebRes), (LPVOID *)&wr);

		

		if(FAILED(hresult))

		{

			switch (hresult) {

				case REGDB_E_CLASSNOTREG:

					AfxMessageBox("Creation Failed -- Class not registered");

					break;

				case CLASS_E_NOAGGREGATION:

					AfxMessageBox("Creation Failed -- class cannot be created as part of an aggregate.");

					break;

				case E_NOINTERFACE:

					AfxMessageBox("Creation Failed -- class does not implement the requested interface");

					break;

				case E_POINTER:

					AfxMessageBox("Creation Failed -- ppv parameter is NULL");

					break;

				default:

					AfxMessageBox("Creation Failed -- unknown reason");

					break;

			}

			return;

		}
 

		//bool bCon = wr->Connect("GEX", "c:/GolfExtra/TeeTimes.ini");

		bool bCon = wr->Connect("GEX", "");

		if (bCon)

			MessageBox("Connect Succceded\n");

		else 

			MessageBox("Connect Failed **********\n");
 

		bool bSUser = wr->SetUser("GEX");

		if (bSUser)

			MessageBox("SetUser Succceded\n");

		else 

			MessageBox("SetUser Failed **********\n");
 

		BSTR bstrMess;
 

		wr->FirstName = "Davis";

		wr->LastName = "Phil";

		wr->PhoneNo = "123 456 7890";

		wr->CreditCard = "123456789012345";

		wr->CreditCardExpDate = "01/01/11";

		wr->Display = "Davis, Phil";

		wr->Email = "phil@email.com";
 

		bool bCust = wr->CreateCustomer(&bstrMess);

		if (bSUser)

			MessageBox("CreateCustomer Succceded\n");

		else 

			MessageBox("CreateCustomer Failed **********\n");
 

		CString str(bstrMess);

		MessageBox(str);
 

		wr->LastName = _bstr_t ("Davis");
 

		using namespace ADODB;
 

		_RecordsetPtr ptrRS;

		hresult = ptrRS.CreateInstance(__uuidof(Recordset));

		if(FAILED(hresult)) {

			MessageBox("ptrRS.CreateInstance Failed *****");

		}
 

		ptrRS = wr->GetCustomerList();

		ptrRS->MoveFirst();
 

		_variant_t vtRows = ptrRS->GetRows(adGetRowsRest);
 

		_bstr_t  bstrFName;

		bstrFName = ptrRS->Fields->Item["strFirstName"]->Value;  // this crashes.

		

		USES_CONVERSION;

		CString str2(W2A(bstrFName));

		MessageBox(str2);
 

		wr->Release ();

		CoUninitialize();

}

Open in new window

0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24749966
Did you find out which of the three pointers is NULL?
0
 

Author Comment

by:BeerFizz
ID: 24749972
Sorry, I missunderstood.  I'll do that now.
0
 

Author Comment

by:BeerFizz
ID: 24750024
It crashes on an attempt to access:

ptrRS->Fields->Item["FirstName"]

0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24752126
>>>> ptrRS->Fields->Item["FirstName"]
That means the recordset the pointer is pointing to has no field mapping until now (or the fields have different names).

I checked some sample code (given by the link above) and found sequences like

      TESTHR(pRstAuthors.CreateInstance(__uuidof(Recordset)));
      pRstAuthors->CursorType = adOpenStatic;

      // Use client cursor to enable AbsolutePosition property.
      pRstAuthors->CursorLocation = adUseClient;
      pRstAuthors->Open("Authors", strCnn, adOpenStatic, adLockBatchOptimistic, adCmdTable);

      // Show current record information and get user's method choice.
      while (true) {   // Continuous loop.
         // Convert variant string to convertable string type.
         bstrFName = pRstAuthors->Fields->Item["au_fName"]->Value;
         bstrLName = pRstAuthors->Fields->Item["au_lName"]->Value;


The CreateInstance is similar to your code (beside it was wrapped to a function which throws a com exception in case of an error).

But then, the sample code *opens* the recordset specifying a table "Authors" while your code calls 'wr->GetCustomerList()'. What is 'wr' and what is the relation to the record set? I checked your header and saw that GetCustomerList returns a HRESULT while you were assigning it to ptrRS what IMO shouldn't compile. As you didn't pass the pointer to  'wr->GetCustomerList() the pointer created with CreateInstance was lost and you got that whatever the wr->GetCustomerList() has returned as a new pointer. It is no wonder that it crashes after that ....

Can you post the code for the GetCustomerList() ?
0
 

Author Comment

by:BeerFizz
ID: 24755361
Hi itsme.

Thanks for your patience and continued persistence.

I couple of posts up, I posted the source the the test code I'm using and also to the .tlh.  Unfortunately I do not have the source of the DLL which contains GetCustomerList(), or things might be easier.

GetCutomerList returns a variant.

wr is a smart pointer to the class WebRes which contains the method GetCustomerList().

since we last posted, I have tried several things, for example, this should have worked:

bstrFName = ptrRS->Fields->Item[0]->Value

using an index instead of a field name should have worked, but it crashes also.

I found this function:

bstrT = ptrRS->GetString(adClipString, 1, ",", "|", "NULL");

believe it or not, this will actually return the contents of one row in a string, each column separated with ','.    So the data is there.

I can do this:

hresult = ptrRS->MoveNext();
bstrT = ptrRS->GetString(adClipString, 1, ",", "|", "NULL");

and cycle through the rows which have been selected, but it crashes when it moves past the last one.

Thoughts?  Suggestions?





0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 450 total points
ID: 24756683
>>>> So the data is there.
Good. The problem is that by going the way via wr->GetCustomerList, the record set pointer was not bound to the table and has no fields!!

What about commenting the wr->GetCustomerList and calling 'Open' like it is in the sample code?

>>>> but it crashes when it moves past the last one.
Yes, you need to check for IsEOF and break before.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now