[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Pass Array of doubles(using Delphi Dll)  to VB??

Posted on 2002-04-25
3
Medium Priority
?
381 Views
Last Modified: 2008-02-01
Hi All,

I built a win32 dll in delphi, then I want to use this
in my VB:
Delphi Dll code:
Function SumArray(ar : OleVariant): double;stdcall;
var r : double; i, h, l : integer;
begin
    try
        if TVarData(ar).VType=varArray then
        begin
            h := VarArrayHighBound(ar,1);
            l := VarArrayLowBound(ar,1);
            r := 0;
            for i := l to h do
            begin
                 r := r + ar[i];
            end;
            result := r;
        end
        else
            result := -1;
    except
        result := -1;
    end;
end;
Exports
    SumArray;
begin
end.

And this is my VB Code:
Private Declare Function SumArray Lib "ddll.DLL" _
    (db() as double) As Double

Sub SumArrayTest()
    Dim n(1000) As Double
    Dim i As Long
    Dim result As Double
    For i = 0 To 1000
        n(i) = 2.1235
    Next
    result = SumArray(n)
    MsgBox "Sum = " & result
End Sub

BUT I get this message!:
"....The Memory could not be read..."

Pls Help
0
Comment
Question by:eabell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 200 total points
ID: 6971436
you should either change Function SumArray(ar : OleVariant): double;stdcall;
to make ar a variable like :

Function SumArray(var ar : OleVariant): double;stdcall;
then you can use it with vb like:
Private Declare Function SumArray Lib "ddll.DLL" _
  (db() as double) As Double

like this you pass the variable by reference
and in delphi you accept it by reference with var

or leave delphi interface alone and change vb part

so you have :
Private Declare Function SumArray Lib "ddll.DLL" _
   (ByVal db() as double) As Double

haven't tested but it's how it should be done and it should work :)

if it doesn't work simplay pass a pointer to it like it's done in WinApi
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6975514
Has this helped you?  Assuming so, please convert the comment to the Accepted Answer to grade and close this item and award the points.  If more is needed, let us know.
Thanks,
Moondancer - EE Moderator
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9004161
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from Lee_Nover

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

656 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