Solved

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

Posted on 2002-04-25
3
361 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 50 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using idhttp to login to instagram 2 118
How to renew a Delphi rad-studio licence? 5 75
Delphi...Split view - idea? 1 113
Browsing a TTreeView in Delphi 5 31
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

735 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