Solved

Array Pointer

Posted on 2006-11-13
1
4,563 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
[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
1 Comment
 
LVL 28

Accepted Solution

by:
2266180 earned 50 total points
ID: 17932838
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

617 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