Solved

Passing arguments from VBscript (VARIANT)

Posted on 1998-08-11
1
228 Views
Last Modified: 2012-08-13
I am trying to call a COM object (written in C++) from VBSCRIPT embedded in an HTML page (IE 3.02).  The object method's signature is:   myfunc( [out] VARIANT* pVar,
     [in] VARIANT ccVar )

     If I call the method (from within VBSCRIPT) like this:

     myfunc( str, 10000 );

     (str is of VARIANT), the variant comes in (on the C++) side as VT_I4 as expected.

     However, if I pass it as:  myfunc( str, nNumber)

     (nNumber is of VARIANT set to 10000), the incoming VARIANT (in C++) actually is a byref ptr to another variant that contains the VT_I4 with the 10000.

     Why is this?   Do I have to code for all situations?  As I mentioned, my method expects an [in] only for the second parameter, I never want BYREF.
0
Comment
Question by:tdietz
1 Comment
 
LVL 3

Accepted Solution

by:
Norbert earned 50 total points
ID: 1169952
As you said nNumber has the type Variant.
Having a look to the definition of Variant you can see that a variant is only a struct with an embedded union.
The union does not have the space to store a complete variant in it there is only the space to hold a pointer to a variant.
Therefore the only way to transport a variant is byref.
if you only want to transport longs try to define
 myfunc( [out] VARIANT* pVar,    [in] long ccVar )
if you want to transport any kind of data you can store into a variant you have to code all situations that can occure
but that is not a big deal:
MyFunc(VARIANT* pVar, VARIANT ccVar)
{
       VARIANT* Helper=&ccVar;
       while(Helper.vt==VT_BYREF|VT_VARIANT)
             Helper=Helper->pvarVal;
      switch(Helper.vt)
      {
          case VT_I4:
              Do Things for longs
              break;
         case VT_ Other needed types
              .
              .
              .
         default: // Not needed types are error conditions
           Report error condition
       }
}

0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question