Solved

Passing arguments from VBscript (VARIANT)

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Want to delete all my personal data 13 138
how to understand recursion 12 219
Starting a function in a c++ application with a TCP command from C# 4 71
PDF library for Delphi 2 107
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

864 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

16 Experts available now in Live!

Get 1:1 Help Now