Named array

Posted on 2006-07-03
Last Modified: 2012-05-05

Is there a posibility to return a named array from C++ COM dll to ASP?
I have a function that returns VARIANT value.
Can i set it up some how that it vould represent key and value mapping in ASP?

varRetValue("Key1") = "Value1"
varRetValue("Key2") = "Value2"
varRetValue("Key3") = "Value3"

Question by:GiedriusS
  • 2
  • 2
LVL 18

Assisted Solution

JoseParrot earned 50 total points
ID: 17030770

You may pass and return classes, arrays and structs values.


in the program:
int A[4];

A[1] = 0;
MyFunction(A); // call the function
// A[1] now is 10

at function code
void MyFunction(int B[])
  B[1] = 10;


Author Comment

ID: 17030932
remote function call is the only way?
LVL 18

Expert Comment

ID: 17033588
Classic (non .net) ASP passes a variant containing an array.
To better understand differences of passing parameters by value or by reference to/from ASP, take a look at

LVL 25

Accepted Solution

clockwatcher earned 75 total points
ID: 17035105
First off, in order to call anything from classic ASP, you're going to need to use an ActiveX DLL.  Assuming you know that and are doing that already, probably the easiest way to deal with returning a name/value collection to ASP is to use and return a scripting dictionary.  ASP programmers will be familiar with its use and you don't have to do any of the implementation yourself.  You just need to fill it with key/value pairs in your C++.

I posted an ATL sample (Visual C++ 6 project) at:

Here's the gist of it:

#import "C:\WINDOWS\system32\scrrun.dll" no_namespace rename("FreeSpace","FSpace") rename("Unknown", "Unk")

IDictionaryPtr m_Dictionary;

STDMETHODIMP CDictionarySample::GetDictionary(LPDISPATCH* retval)

     if (m_Dictionary.GetInterfacePtr() == NULL)
          _variant_t key("mykey");
          _variant_t val("myval");

          m_Dictionary->Add((VARIANT*) &key, (VARIANT*) &val);

          _variant_t key("addedanotherref");
          _variant_t value("again");
          m_Dictionary->Add((VARIANT*) &key, (VARIANT*) &value);



     m_Dictionary->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(retval));

     return S_OK;

Calling it from vbscript:

set collection = createobject("Q_21906708.DictionarySample.1")

set map = collection.GetDictionary()
wscript.echo map("mykey")
map.add "hello","there"

set anotherref= collection.GetDictionary()
wscript.echo anotherref("hello")

wscript.echo map("addedanotherref")

for each key in anotherref.keys
  wscript.echo key & " = " & anotherref(key)

Author Comment

ID: 17035968

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

895 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

22 Experts available now in Live!

Get 1:1 Help Now