Solved

Named array

Posted on 2006-07-03
5
311 Views
Last Modified: 2012-05-05
Hi,

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?

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

Thanks,
Giedrius
0
Comment
Question by:GiedriusS
  • 2
  • 2
5 Comments
 
LVL 18

Assisted Solution

by:JoseParrot
JoseParrot earned 50 total points
ID: 17030770
Hi,

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

Ex.:

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;
}

Jose
0
 

Author Comment

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

Expert Comment

by:JoseParrot
ID: 17033588
No.
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
http://support.microsoft.com/kb/q197956/

Jose
0
 
LVL 25

Accepted Solution

by:
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:  https://filedb.experts-exchange.com/incoming/ee-stuff/328-Q_21906708.zip

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.CreateInstance("Scripting.Dictionary");
          m_Dictionary->Add((VARIANT*) &key, (VARIANT*) &val);


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

     }

     m_Dictionary.AddRef();

     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)
next
0
 

Author Comment

by:GiedriusS
ID: 17035968
thanks.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

758 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

19 Experts available now in Live!

Get 1:1 Help Now