Solved

sending arrays to dll from asp

Posted on 1998-06-13
8
199 Views
Last Modified: 2013-12-25
I need to send a two dimensional array from a vb asp to a dll. How?? The dll is one i'm going to write myself. The asp has an array GraphSeries(5,10) which stores dataset and value for a series of graph points. I need to pass this data to the dll, which then goes off and draws the graph as a jpg and sends it back to the client. I currently achieve this by using a nested loop in the asp, which means calling the dll 50 times (for each seperate point). I'd like to add a function to the dll that accepts the whole array, so I only need to call it once. I've read that if you pass the first element of the array by reference, the dll can access the rest of it as numeric arrays are stored sequentially in memory, but I can't get it to work. I either get a type-mismatch or a subscript out of bounds error.
any ideas??
0
Comment
Question by:acsmith
  • 4
  • 4
8 Comments
 
LVL 1

Author Comment

by:acsmith
ID: 1858316
Edited text of question
0
 
LVL 6

Accepted Solution

by:
alamo earned 70 total points
ID: 1858317
You are correct, the simplest way to pass a numeric array is to pass the first element, since they are laid out sequentially in memory. The DLL needs to know the array dimensions to make this simple approach work.

Yes, as you say, your calling VB program must pass the first element of the array by reference. The receiving DLL must define that parameter as a pointer to the proper datatype.

It sounds like you have the right idea and are very close.. perhaps you could post the function declaration and call from the VB program, and the declaration from from the DLL. It's going to be tough to debug this without concrete examples.

The VB5 Professional version doc has a whole section on this sort of thing, in the component tools guide. ("Accessing DLLs and the Windows API"). It's a must-read if you want to do fancy things like pass the array as an array (a SAFEARRAY actually). But you shouldn't need all that, your current method should work.
0
 
LVL 1

Author Comment

by:acsmith
ID: 1858318
Apologies if this comment appears twice (i'm having trouble with my net connection). The line in the asp that calls the routine(after filling the GraphSeries array with appropriate data)
session("mygraph").SetGraphValue GraphSeries(0,0)
mygraph is declared in global.asa:
Set Session("mygraph") = Server.CreateObject("mydll.graphstuff")
then the dll sub:
Public Sub SetGraphValues(ByRef GraphValues() As Variant)
Dim SeriesIndex As Integer
Dim ValueIndex As Integer
For SeriesIndex = 1 To 5
    For ValueIndex = 1 To 10
        GraphValue(SeriesIndex, ValueIndex) = GraphValues(SeriesIndex, ValueIndex)
    Next ValueIndex
Next SeriesIndex
End Sub
there's probably some blindingly obvious reason that this doesn't work, but not being a vb programmer, I can't spot it. I've read the doc's you mentioned, but the examples they give are not very clear (to me, anyway). You said that the dll needs to know the dimension of the array, and that it needs to define the parameter as a pointer to the correct data type. How do I do this?
cheers for your help.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 6

Expert Comment

by:alamo
ID: 1858319
My comments were predicated upon the idea that the DLL was written in C or C++, which I now see is wrong. So forget about passing the first array element as being the easiest way to do it, if the DLL is done in VB you can pass the whole array just as easily.

Try defining the DLL sub as
Public Sub SetGraphValues(ByRef GraphValues())

and calling it with
SetGraphValues GraphSeries()

That's the syntax if both functions are within the same VB executable, so it's a good place to start. I haven't worked with VB in DLLs so I don't know for sure they accept this syntax, there are slight differences sometimes in the different flavours of VB has put out. If this doesn't work, tell me the exact errors you get, that will help.
0
 
LVL 6

Expert Comment

by:alamo
ID: 1858320
oops, that call should be
session("mygraph").SetGraphValues GraphSeries()

Forgot to change it when I copied from my test program. (By the way I assume the fact your sub was called SetGraphValues but was called as SetGraphValue (without the s) was a typo - if it isn't, it could be part of the problem).
0
 
LVL 1

Author Comment

by:acsmith
ID: 1858321
tried it, and got a subscript out of range error. The trouble is, I can't tell if it's the call thats incorrect (session("mygraph").SetGraphValues GraphSeries()) or the heading of the sub in the dll, as vbscript has next to no debugging facilities, and the dll is already compiled when it's called, so I can't single step through it.
0
 
LVL 6

Expert Comment

by:alamo
ID: 1858322
Sorry for the delay in getting back to this...

The first thing I would try is changing the call:
from SetGraphValues GraphSeries()
to SetGraphValues GraphSeries

VB5 accepts either, but perhaps VBScript cares. But I'll assume you've already tried this, and move on.

Next thing to try is changing how the Sub is defined.
Try: Public Sub SetGraphValues(GraphValues As Variant)

I am thinking that perhaps your original declaration defined an array of variants, rather than a variant holding an array.

If that doesn't work, try leaving the Sub defined as receiving a variant but also define a variant in your ASP and assign the array to it, then pass the variant.

I know when you asked this question you were expecting a nice tidy response :-) The difficulty (for me at least) is that MS has built three slightly different languages on the same base (VB5, VBA, VBScript) and it's tricky to keep it all straight. Also, sometimes VB will do automatic conversion of data types, sometimes it won't.

Hope this helps!
0
 
LVL 1

Author Comment

by:acsmith
ID: 1858323
cheers. apologies for keeping you waiting.
I changed the call as you suggested (SetgraphValues GraphSeries) and the header in the dll to Public Sub SetGraphValues(GraphValues as Variant), and it worked first time.
cheers for you help!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

830 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