We help IT Professionals succeed at work.

I encapsulate ADO in my dll,but no array returned in ASP.

CFree
CFree asked
on
Medium Priority
290 Views
Last Modified: 2010-04-02
what's wrong with the following code?
in idl:
HRESULT readdata([out,retval] VARIANT* varData);

in cpp:
......
_RecordsetPtr m_pRecordset;
_variant_t avarRecords;
......
avarRecords = m_pRecordset->GetRows(-1);
.....
hr= SafeArrayGetElement(avarRecords.parray, rgIndices, &result);
//the currect value of result can be shown by MessageBox(NULL,(LPCSTR)(_bstr_t)result,"",MB_OK);
//so the above should be correct

varData->parray=avarRecords.paaray;
return S_OK;

in ASP
<%
set obj=createobject("myproj.myclass.1")
a=obj.readdata()
response.write "a is:"&vartype(con)
set obj=nothing
%>
a is 0

Thanks!
Comment
Watch Question

Hi,
Instead of assigning values to out parameter like what u have done, do a VariantCopy.

eg:

avarRecords = m_pRecordset->GetRows(-1);
VariantCopy(varData,&avarRecords.Detach());

this should work.

karthik

Author

Commented:
karthik:
it still doesn't work.
Is there something else wrong?
Thank you very much.
hi,
getrows returns a 2 dimensional array whose dimensions
are (no of rows returned * no of columns specified in the query).
So, u try getting values in ASP  like
a=obj.readdata()
response.write(a(0,0))

like that.

Good Luck
karthik

Author

Commented:
hi,karthik
I add "response.write(a(0,0))" in my ASP,the following error occurs:
Microsoft VBScript runtime error(0x800A000D)
Thank you.

Commented:
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points since nobody had a satisfying answer for you.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
Per recommendation, points refunded and question closed
Netminder
CS Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.