| | |
Passing Variants from VB to VC++
![]() |
•
•
Join Date: May 2007
Posts: 4
Reputation:
Solved Threads: 0
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...
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
- Passing data from forms from one page to another (JavaScript / DHTML / AJAX)
- Passing arrays of objects to functions (C++)
- Passing variables into form fields (PHP)
- w32.gaobot and variants still on network (Viruses, Spyware and other Nasties)
- message passing interfaces (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: DropList Help?
- Next Thread: multiple parameters to data report
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





