Solved

Passing arguments from VBscript (VARIANT)

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

821 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