Click to See Complete Forum and Search --> : ADO: _ConnectionPtr::OpenSchema() help in C++?


TomMck
April 14th, 1999, 11:17 AM
I _really_ need help in VC++ 6.0 accessing the Schema in ADO.
I am trying to use the OpenSchema() function of the Connection
object in ADO.

The help is all in VB. The "Restrictions" (sometimes called "Criteria") parameter is an "Array" in VB, but it is passed in as a "_variant_t&" in the C++ classes (I'm using the #import method for ADO).

Can ANYONE tell me how to put an array of data into a C++ _variant_t for this function?

I'll give you my firstborn son if you can answer this for me.

Alvaro
April 14th, 1999, 11:40 AM
I think it's done through a SAFEARRAY. There's an article in this month's issue of C/C++ User's Journal that talks about creating a SAFEARRAY using an std::vector-derived class. There's also the MFC "COleSafeArray" class which you can look at.

Good luck!

Alvaro

April 14th, 1999, 01:13 PM
I'm not using MFC, so I can't use COle classes.
Also, a SAFEARRAY does not translate into a _variant_t object.

P.S. this thing wouldn't let me log in...

Bob Place
April 15th, 1999, 07:32 AM
Isn't a SAFEARRAY stored in a VARIANT object as vt = VT_ARRAY? And can't you send that into the call as a _variant_t?

April 21st, 1999, 12:47 PM
Hi,
just have a look to http://www.support.microsoft.com/download/support/mslfiles/Adochunk.exe

It uses a lot of Arrays (SAFEARRAY) in VARIANT or _variant_t such as :

<<
// Function which creates a safe array and initializes the data with the data present in one of the edit boxex
void CAdoVcChunkDlg::BlobToVariant(VARIANT &varArray)
{
BYTE *pByte;


try
{
SAFEARRAY FAR* psa;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = m_csValue.GetLength() * sizeof(TCHAR) + sizeof(TCHAR);

// create a single dimensional byte array
psa = SafeArrayCreate(VT_I1, 1, rgsabound);

// set the data of the array with data in the edit box
if(SafeArrayAccessData(psa,(void **)&pByte) == NOERROR)
memcpy((LPVOID)pByte,(LPVOID)m_csValue.GetBuffer(m_csValue.GetLength()),m_csValue.GetLength()+1);
SafeArrayUnaccessData(psa);

varArray.vt = VT_ARRAY | VT_UI1;
varArray.parray = psa;
}
catch(_com_error &e)
{
DumpError(e);
}
}

>>

Good luck !!!!