Solved

Passing arguments from VBscript (VARIANT)

Posted on 1998-08-11
1
226 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now