Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing arguments from VBscript (VARIANT)

Posted on 1998-08-11
1
Medium Priority
?
236 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 100 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

916 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