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...