Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Extracting data from pointer using CopyDataStruct

126 views
Skip to first unread message

Jeremiah Ross

unread,
Jun 15, 2000, 3:00:00 AM6/15/00
to
I have sendmessage working using wmCopyData in the second parameter,
and using the lParam parameter to hold a pointer to a CopyDataStruct.
Within the CopyDataStruct is information about an array, and in the
lpData field is a pointer to an array. On the receiving end, I'm having
trouble extracting data from the pointer to the array in the
CopyDataStruct. Does anyone have a way to extract the data from the
array?

Jeremiah


Steve Schafer (TeamB)

unread,
Jun 15, 2000, 3:00:00 AM6/15/00
to

Is it a dynamic array? If so, the problem is probably that the array
is going out of scope (and therefore being destroyed) in the sender
before the receiver has a chance to look at it.

If the problem is not a dynamic array or string, please show us what
kind of data you're actually passing.

-Steve


Jeremiah Ross

unread,
Jun 15, 2000, 3:00:00 AM6/15/00
to

"Steve Schafer (TeamB)" wrote:

The array is static and contains integer values.

Jeremiah


Steve Schafer (TeamB)

unread,
Jun 15, 2000, 3:00:00 AM6/15/00
to
On Thu, 15 Jun 2000 18:51:51 -0500, Jeremiah Ross
<jrb6...@worldnet.att.net> wrote:

> The array is static and contains integer values.

Show us what you're doing. We can't read your mind.

-Steve


Jeff

unread,
Jun 15, 2000, 3:00:00 AM6/15/00
to

On the sending side I have this function that sends the message:

var
  ReturnValue: LResult;
  cds: CopyDataStruct;
begin
  AutoTestArray[0] := 10;
  AutoTestArray[1] := 48;
  cds.dwData := 0;
  cds.cbData := sizeof(@AutoTestArray);
  cds.lpData := @AutoTestArray;
  UserMessage1 := RegisterWindowMessage('Test1');
  Hndle := FindWindow('TfrmAutoTest',nil);
  If Hndle > 0 then
    begin
    ReturnValue :=  SendMessage(Hndle, wm_CopyData,0,Integer(@cds));
    Result :=  ReturnValue;
    end
      else
        Result := Hndle;
end;

AutoTestArray and Hndle are global variables and are declared as follows:

var
Hndle: THandle;
AutoTestArray: Array [0..1] of integer;

So far on the receiving end I have a function that is receiving data:

procedure TfrmAutoTest.CopyData(var Msg: TWmCopyData);
var
  Filename: string;
  PArray: pointer;
begin
  // extract the filename from the data
  PArray:= (Msg.CopyDataStruct.lpData);
  filename := PChar(PArray);
  ShowMessage('OK:' + filename);
end;

The fact that they do talk is all good and fine.  My problem is is that I need to know what type to replace PArray with and what to do to use the lpData pointer to extract the data from the AutoTestArray.  Hope this helps!

  Jeremiah
 
 
 
 

Peter Below (TeamB)

unread,
Jun 16, 2000, 3:00:00 AM6/16/00
to
In article <394995B0...@worldnet.att.net>, Jeff wrote:

PLease don't post in HTML, it is against the newsgroup guidelines and
causes problems for some newsreaders.

> So far on the receiving end I have a function that is receiving data:
>
> procedure TfrmAutoTest.CopyData(var Msg: TWmCopyData);
> var
>
> Filename: string;

> PArray: ^Array [0..1] of Integer;

> begin
> // extract the filename from the data

What filename?

PArray:= Pointer(Msg.CopyDataStruct.lpData);

ShowMessage('OK:' + Format('%d; %d', [pArray^[0], pArray^[1]]));
> end;

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!


Jeremiah Ross

unread,
Jun 16, 2000, 3:00:00 AM6/16/00
to

Sorry about the HTML. I switched it over to plaintext. As far as
that filename stuff goes, just ignore it. I was using it to get stuff
running and display data onscreen.
For some reason the code you gave me didn't work. In your declaration
of PArray I get this error:

Identifier expected by 'ARRAY' found

And then with the showmessage line at the spot with the pArray^[0],
pArray^[1] I get these errors:

Array type required
Array type required

I know that this probably isn't done too often, but it shouldn't be this
hard. I think that it may be time to go back to the drawing board.

Peter Below (TeamB)

unread,
Jun 17, 2000, 3:00:00 AM6/17/00
to
In article <394AC68A...@worldnet.att.net>, Jeremiah Ross wrote:
> For some reason the code you gave me didn't work. In your declaration
> of PArray I get this error:
>
> Identifier expected by 'ARRAY' found

Try do declare a type explicitely:

Type
TIntArray = array [1..2] of Integer;
PIntArray = ^TIntArray;
Var
pArray : PIntArray;

Steve Schafer (TeamB)

unread,
Jun 17, 2000, 3:00:00 AM6/17/00
to
On Fri, 16 Jun 2000 19:30:02 -0500, Jeremiah Ross
<jrb6...@worldnet.att.net> wrote:

>I know that this probably isn't done too often, but it shouldn't be this
>hard. I think that it may be time to go back to the drawing board.

I don't know if the things Peter suggested were enough to get you
going, but I want to emphasize that we need to see the _real_ code
that you're using, or else we're going to spend all of our time trying
to correct problems that aren't really there. In the first code
example that you posted, you had the sender trying to send an array of
two integers, and the receiver trying to interpret that array as a
filename, of all things.

That can't work, obviously, and I assume that you know that, so if
you're still having trouble getting things to work, please post the
GENUINE code that you're using so that we can try to diagnose the
problem.

-Steve


Jeremiah Ross

unread,
Jun 18, 2000, 3:00:00 AM6/18/00
to

Peter's code worked, thanks for the help.

0 new messages