Solved

Array Pointer

Posted on 2006-11-13
1
4,553 Views
Last Modified: 2008-01-09
I have the following code in a compiled delphi dll.  

library wavelet;

uses
  SysUtils,math,Windows;

type
     aa1=array[0..1000000] of single;
     ar=^ aa1;
var
  MyArr:ar;

function RUNWVL(a:ar; nscales:word; ttc:single):single;stdcall;
begin
     // Do Some work and return a single
end;


I need to access this dll and call RUNWVL from another app.  I'm trying to do like below, but I'm having trouble getting the syntax correct to pass the pointer in. Can someone show me how to pass the pointer to my array into the function?

program testapp;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Unit1 in 'Unit1.pas';

procedure  RUNWVL( ptrArray:pointer; scales:Integer; stddev:double) ;  stdcall;far;external 'wavelet.dll';
procedure  GETALLVALUES( something:Integer; somethingelse:Integer) ;  stdcall;far;external 'wavelet.dll';

type
    aa1= array of double;
    pcloseList=^ aa1;

var
    f: TextFile;
    line:string;
    date:string;
    time:string;
    close:string;
    scale:string;
    scales:Integer;
    count:Integer;
    start:Integer;
    stop:Integer;
    closeList: aa1;
    scaleList: array of double;
    t: double;
    y: double;procedure ExecuteProgram;



  begin
      scales := 9;


          // Open file for reading
          AssignFile(f, 'c:\wavelet\testdata');
          Reset(f);

          count := 0;
          ReadLn(f, line);
          SetLength(closeList, scales * scales);
          SetLength(scaleList, scales * scales);

          // Read each line
          while not Eof(f) do
          begin
            if count = ( scales * scales ) then
            begin
              // Run Wavelet
              t := RUNWVL(closeList, scales, 3);
              for count := 1 to scales do
                begin
                  // Get the wavelet values
                  y := GETALLVALUES(1, count);
                end;


              count:=0;


            end
            else
            begin
            // Fill array with data from file
             ReadLn(f, line);

             stop:= pos(',', line);
             date:= copy(line, 0, stop - 1);
             line := copy(line, stop + 1);

             stop:= pos(',', line);
             time:= copy(line, 0, stop - 1);
             line := copy(line, stop + 1);

             stop:= pos(',', line);
             close:= copy(line, 0, stop - 1);
             line := copy(line, stop + 1);

             scale := line;

             scaleList[count] := StrToFloat(scale);
             closeList[count] := StrToFloat(close);

             count:= count + 1;

            end;





          end;

          CloseFile(f);
//           Close(f);

         WriteLn('running proggy');
  end;

begin
      try
        ExecuteProgram;
      except
        WriteLn('WTF');


      end;
      ExitCode := 1;
end.





0
Comment
Question by:darthg8r
1 Comment
 
LVL 28

Accepted Solution

by:
ciuly earned 50 total points
Comment Utility
first add to the library wavelet the following:

exports RUNWVL, GETALLVALUES;

at the end.

then call the function like:

t := RUNWVL(@closeList, scales, 3);

then declare your aa1 as array of single and not double. single is 4 bytes. double is 8 bytes. same goes for all other doble/single variables in your code.

that's what I see for now.

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How can I open IE in olecontainer? 7 108
Using FastMM4... should I enable MMX option? 9 68
IExtractImage Delphi 14 162
Magic Software info 18 100
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

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

11 Experts available now in Live!

Get 1:1 Help Now