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
Solved

Array Pointer

Posted on 2006-11-13
1
4,560 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:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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