VARIANT __stdcall SBCallBackEx(int EntryPoint, VARIANT *pVal)
{
#pragma EXPORT
pSupportTable pSt = g_pSt;
VARIABLE FunctionResult;
_variant_t vRet;
if(pSt==NULL){
MessageBox(0,"pSupportTable is not set?","",0);
return vRet.Detach();
}
USES_CONVERSION;
char buf[1024]={0};
HRESULT hr;
long lResult;
long lb;
long ub;
SAFEARRAY *pSA = NULL;
//we only accept variant arrays..
if (V_VT(pVal) == (VT_ARRAY | VT_VARIANT | VT_BYREF)) //24588
pSA = *(pVal->pparray);
//else if (V_ISARRAY(pVal) && V_ISBYREF(pVal)) //array of longs here didnt work out maybe latter
// pSA = *(pVal->pparray);
else
{
if (V_VT(pVal) == (VT_ARRAY | VT_VARIANT))
pSA = pVal->parray;
else
return vRet.Detach();//"Type Mismatch [in] Parameter."
};
long dim = SafeArrayGetDim(pSA);
if(dim != 1) return vRet.Detach();
lResult = SafeArrayGetLBound(pSA,1,&lb);
lResult = SafeArrayGetUBound(pSA,1,&ub);
lResult=SafeArrayLock(pSA);
if(lResult) return vRet.Detach();
_variant_t vOut;
_bstr_t cs;
int sz = ub-lb+1;
VARIABLE pArg = besNEWARRAY(0,sz);
//here we proxy the array of COM types into the array of script basic types element by element.
// note this we only support longs and strings. floats will be rounded, objects converted to objptr()
// bytes and integers are ok too..basically just not float and currency..which SB doesnt support anyway..
for (long l=lb; l<=ub; l++) {
if( SafeArrayGetElement(pSA, &l, &vOut) == S_OK ){
if(vOut.vt == VT_BSTR){
char* cstr = __B2C(vOut.bstrVal);
pArg->Value.aValue[l] = besNEWMORTALSTRING(slen);
memcpy(STRINGVALUE
(pArg
->Value.
aValue[l
]),cstr
,slen
); }
else{
if(vOut.vt == VT_DISPATCH){
//todo register handle? but how do we know the lifetime of it..
//might only be valid until this exits, or forever?
}
pArg->Value.aValue[l] = besNEWMORTALLONG;
LONGVALUE(pArg->Value.aValue[l]) = vOut.lVal;
}
}
}
lResult=SafeArrayUnlock(pSA);
if (lResult) return vRet.Detach();
besHOOK_CALLSCRIBAFUNCTION(EntryPoint,
pArg->Value.aValue,
sz,
&FunctionResult);
for (long l=0; l <= sz; l++) {
besRELEASE(pArg->Value.aValue[l]);
pArg->Value.aValue[l] = NULL;
}
if(FunctionResult->vType == VTYPE_STRING){
char* myStr = GetCString(FunctionResult);
vRet.SetString(myStr);
}
else{
switch( TYPE(FunctionResult) )
{
case VTYPE_DOUBLE:
case VTYPE_ARRAY:
case VTYPE_REF:
MessageBoxA(0,"Arguments of script basic types [double, ref, array] not supported","Error",0);
break;
default:
vRet = LONGVALUE(FunctionResult);
}
}
besRELEASE(pArg);
besRELEASE(FunctionResult);
return vRet.Detach();
}