Article ID: 142223
Article Last Modified on 11/21/2006
LPDISPATCH Add(const VARIANT FAR& varTest);Given the following code in Visual Basic, it may pass the parameter either by reference or by value:
Dim doc As Object
Set doc = CreateObject("TestVar.Document")
Dim docDispatch As Object
Dim varParam As Variant
varParam = 2
Visual Basic will pass the parameter by reference in these cases:
Set docDispatch = doc.Add(varParam) doc.Add varParamVisual Basic will pass the parameter by value in these cases:
Set docDispatch = doc.Add((varParam)) doc.Add (varParam) Set docDispatch = doc.Add(2) doc.Add 2From these examples, you may notice that Visual Basic will pass all variables by reference unless the () operator is used to indicate that the variable should be passed by value. Moreover, Visual Basic will pass all constants by value.
LPDISPATCH CTestVarDoc::Add(const VARIANT FAR& varTest)
{
HRESULT hr;
VARIANT var;
VariantInit(&var);
hr = VariantCopyInd(&var, (LPVARIANT)&varTest);
if (FAILED(hr))
return NULL;
// Now use var instead of varTest
...
}
Additional query words: kbinf
Keywords: kbautomation kbcode kbinfo KB142223