943,981 Members | Top Members by Rank

Ad:
Oct 7th, 2007
0

Passing Variants from VB to VC++

Expand Post »
I created one Function in VC++(which is COM EXE) which i want to call from my VB code.
I am passing Arguements as Variants from VB.
In VC++ i filled SafeArray in those Argument.But after returning its showing Empty..
Here is my VB Code

Private Sub Form_Load()
Dim obj As Object
Dim varTemp As Variant

Dim a As Integer
'Set obj = CreateObject("VBVCConflict.CVBAccess.1")
Set obj = CreateObject("VCServer.VBAccess.1")

If obj Is Nothing Then
MsgBox "object creation failed"
Else
MsgBox "object creation succeeded"
End If

obj.AutoDiscovery (varTemp)

If IsEmpty(varTemp) Then
MsgBox "VarTemp is Empty"
End I

End Sub


/************************************************/

here is my VC++ code

STDMETHODIMP CVBAccess::AutoDiscovery(VARIANT *psaPoints)
{

// TODO: Add your implementation code here
try
{
if(NULL == psaPoints)
MessageBox(NULL,"Invalid Argument","VC",NULL);
else
MessageBox(NULL,"Valid Argument","VC",NULL);



SAFEARRAYBOUND psaBounds[1];
HRESULT hr;
psaBounds[0].lLbound = 0;
psaBounds[0].cElements = 1;
SAFEARRAY *psa = NULL;
VARIANT vGetVal;
VariantInit(&vGetVal);
psa = SafeArrayCreate(VT_VARIANT,1,psaBounds);
if(!psa)
MessageBox(NULL,"Safe Array Creation Failed","VC",MB_OK );

long lputindex[1];
long lgetindex[1];
lputindex[0] = 0;
lgetindex[0]=0;


CComVariant varValue;
varValue.vt = VT_INT ;
varValue.intVal = 5;
hr = SafeArrayPutElement(psa,lputindex,&varValue);
if(SUCCEEDED(hr))
MessageBox(NULL,"Put Array Succeeded","VC",MB_OK );
hr=SafeArrayGetElement(psa,lgetindex,&vGetVal);
if(SUCCEEDED(hr))
MessageBox(NULL,"Get Element Succeeded","VC",MB_OK );



//here is the place i am assigning safe array to VARIANT

VariantInit(psaPoints);
psaPoints->vt = VT_ARRAY | VT_VARIANT ;
psaPoints->parray = psa;


return S_OK;
}
catch(...)
{
MessageBox(NULL,"Exception occured",NULL,MB_OK );
return E_FAIL;
}

return S_OK;

}

In Vb i am getting the Varinat as Empty after Calling this function in VC++ COM EXE..
I have built the Proxy/Stub dll also..

Please help me in this regard....

The same thing i tried in VB.Net and VC++ .Net also (VC 7.0)..its working fine..(but Variant will be treated as Object in VB.Net)

I tried with VB 6.0 and VC++ 7 ..passed Variants from VB6.0 to the same function but which is in VC++ 7.0 ..Its getting as NULL in VC++..Is there anything i am missing when i access a function in VC++(VS .Net 2003 Environment) from VB 6.0

please help me...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zanaja is offline Offline
4 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: DropList Help?
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: multiple parameters to data report





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC