Named array


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"

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose ParrotGraphics ExpertCommented:

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;

GiedriusSAuthor Commented:
remote function call is the only way?
Jose ParrotGraphics ExpertCommented:
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

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)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GiedriusSAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.