Solved

sending arrays to dll from asp

Posted on 1998-06-13
8
193 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
Comment Utility
Edited text of question
0
 
LVL 6

Accepted Solution

by:
alamo earned 70 total points
Comment Utility
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
Comment Utility
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
 
LVL 6

Expert Comment

by:alamo
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Expert Comment

by:alamo
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 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

12 Experts available now in Live!

Get 1:1 Help Now