How to create a SAFEARRAY??

Hey everyone,

Here is a quick question for all you C++ experts... I need to create a SAFEARRAY.. but not exactly sure how to do it.

I'm trying to call a VB DLL method that access a store procedure of a database.. I believe it should work.. but I don't know how to create a SAFEARRAY... can someone help please...

VB DLL method.. this is how it looks like
Set rsClaimErrors = objDBCalls.RunSPReturnRS("sp_get_claim_errors", _
                                                Array("@i_USER_ID", 200, 200, strClaimID))

in the C++ side this is what the method requires...

UB92Format = pDBCalls->RunSPReturnRS(_bstr_t spSTR, SAFEARRAY **params);

I know what to put in the _bstr_t part... but I need to create a SAFEARRAY in C++ that would store the simple value as in the VB DLL method.. how can I do this..

BLADE007
Blade007Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
YuriPutivskyConnect With a Mentor Commented:
In you case you need VARIANT vector as a SafeArray

unsigned int count = 4; // in your case
SAFEARRAY sa = SafeArrayCreateVector(VT_VARIANT, 0, 4);
if (!sa)
{
// handle error here
}

// How to assign the particular element in a Safe Array?
// OK, here is a code example
// lock array
SafeArrayLock(sa);
VARIANT* pvar = 0;

// get the pointer to the first element
long lx = 1;
SafeArrayPtrOfIndex(sa, &lx, (void**)&pvar);
// assign here for example string
pvar->vt = VT_BSTR;
pvar->bstrVal = ::SysAllocString(L"@i_USER_ID");

// get the pointer to the second element
lx = 2;
SafeArrayPtrOfIndex(sa, &lx, (void**)&pvar);
// assign here for example long
pvar->vt = VT_I4;
pvar->lVal = 200;

// ... and so on

// unlock array
SafeArrayUnlock(sa);
 
0
 
ExceterCommented:
What is a SAFEARRAY? What does it store?
0
 
Blade007Author Commented:
A SAFEARRAY is used in COM to pass array of variant datatype... I believe that's what I read up on.. I could be wrong.
0
All Courses

From novice to tech pro — start learning today.