Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Array Pointer

Posted on 2006-11-13
1
Medium Priority
?
4,566 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 200 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
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

705 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