 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Siney Guest
|
Posted: Thu Mar 04, 2004 9:20 am Post subject: why behavior is different in same code from VC 2 BCB???????? |
|
|
I written same code like below in vc:
long CFuckYouCtrl::GetDataV(VARIANT FAR* pvData)
{
pvData->vt=VT_I2;
pvData->iVal=111;
return 0;
}
and call it in BCB:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
VARIANT v;
ZeroMemory(&v,sizeof(v));
FuckYou1->GetDataV(&v);
Caption=(short)v.iVal;
}
the result is 0, but correct in VC??
then written code in vc:
long CFuckYouCtrl::GetDataV(VARIANT FAR* pvData)
{
pvData->vt = VT_UI1 | VT_ARRAY;
SAFEARRAYBOUND bound;
bound.cElements = strlen(m_Fuckyou);
bound.lLbound = 0;
pvData->parray = SafeArrayCreate(VT_UI1, 1, &bound); // Create it
void* pDest;
SafeArrayAccessData(pvData->parray, &pDest);
memcpy(pDest, m_Fuckyou, strlen(m_Fuckyou)); // Copy into array
SafeArrayUnaccessData(pvData->parray);
return 0;
}
call it in bcb:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
char msg[100];
VARIANT V;
FuckYou1->GetDataV(&V);
void* pDest;
SafeArrayAccessData(V.parray, &pDest); // there is an exception thrown,
why???
memcpy(msg, pDest, V.parray->rgsabound[0].cElements);
SafeArrayUnaccessData(V.parray);
SafeArrayDestroy(V.parray);
ShowMessage(msg);
}
but, I can get msg VALUE in VC?
|
|
| Back to top |
|
 |
Michael Harris Guest
|
Posted: Thu Mar 04, 2004 12:53 pm Post subject: Re: why behavior is different in same code from VC 2 BCB???? |
|
|
perhaps VC does not want to be the recipient of your aggressive behavior.
Please help keep this kind of crap of the NG.
thanks.
--
Michael
"Siney" wrote in message
| Quote: | F#######->GetDataV(&V);
|
|
|
| Back to top |
|
 |
Siney Guest
|
Posted: Thu Mar 04, 2004 6:00 pm Post subject: Re: why behavior is different in same code from VC 2 BCB???? |
|
|
hehe, sorry, I hate BCB's bug(maybe).
"Michael Harris" <techonos-NO-SPAM- (AT) attbi (DOT) com> 写入消息新闻
:404726a3$1 (AT) newsgroups (DOT) borland.com...
| Quote: | perhaps VC does not want to be the recipient of your aggressive behavior.
Please help keep this kind of crap of the NG.
thanks.
--
Michael
"Siney" wrote in message
F#######->GetDataV(&V);
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Mar 04, 2004 6:46 pm Post subject: Re: why behavior is different in same code from VC 2 BCB???? |
|
|
"Siney" <siney (AT) yeah (DOT) net> wrote
| Quote: | VARIANT v;
ZeroMemory(&v,sizeof(v));
|
You need to use VariantInit(), not ZeroMemory().
| Quote: | the result is 0, but correct in VC??
|
You aren't checking the return value of GetDataV() to make sure it succeeded
in the first place, ie:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
VARIANT v;
VariantInit(&v);
if( SUCCEEDED(F1->GetDataV(&v)) )
Caption = v.iVal;
}
| Quote: | VARIANT V;
FuckYou1->GetDataV(&V);
|
You did not initialize the VARIANT first.
| Quote: | SafeArrayAccessData(V.parray, &pDest); // there is an exception thrown,
why???
|
You did not check the return value of GetDataV() again,nor did you check the
vt memberr first to make sure the array was even present.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|