Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 871905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:42:30+00:00 2026-05-15T10:42:30+00:00

i use to send a data on two separate process but it fails. it

  • 0

i use to send a data on two separate process but it fails. it works only under same process… this is concept.

//———————————————————————————–
MainApps
//———————————————————————————–

Type
   PMyrec = ^TMyrec; 
   TMyrec = Record
   name : string;
   add : string;
   age : integer;
end;

:OnButtonSend
var aData : PMyrec;
begin
   new(aData);
   aData.Name := 'MyName';
   aData.Add := 'My Address';
   aData.Age : 18;
   SendMessage(FindWindow('SubApps'),WM_MyMessage,0,Integer(@aData));
end;

//———————————————————————————–
SubApps
//———————————————————————————–

Type
   PMyrec = ^TMyrec; 
   TMyrec = Record
   name : string;
   add : string;
   age : integer;
end;

:OnCaptureMessage

var
  aData : PMyrec;
begin
  aData := PMyrec(Msg.LParam);
  showmessage(aData^.Name);
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:42:31+00:00Added an answer on May 15, 2026 at 10:42 am

    You’re right. Addresses only have meaning within a single process. The PMyRec value you create in the first process is just a garbage address in the target process.

    To send an arbitrary block of memory to another process via a window message, you should use the wm_CopyData message. You give that message the address of the data and the size, and the OS takes care of copying it into the target process’s address space.

    Since your data includes a string, which is represented internally as a another pointer, it won’t be enough to just copy the 12 bytes of your record. You’ll need to allocate additional memory to hold the record and the string data in a single block of memory so wm_CopyData can copy it and the target process can read it.

    Here’s one way to do it, using a stream to collect the data into a single block of memory.

    procedure SendRecord(Source, Target: HWnd; const Rec: TMyRec);
    var
      Buffer: TMemoryStream;
      Len: Integer;
      CopyData: TCopyDataStruct;
    begin
      Buffer := TMemoryStream.Create;
      try
        Len := Length(Rec.name);
        Buffer.Write(Len, SizeOf(Len));
        if Len > 0 then
          Buffer.Write(Rec.name[1], Len * SizeOf(Char));
        Len := Length(Rec.add);
        Buffer.Write(Len, SizeOf(Len));
        if Len > 0 then
          Buffer.Write(Rec.add[1], Len * SizeOf(Char));
        Buffer.Write(Rec.age, SizeOf(Rec.age));
        CopyData.dwData := 0;
        CopyData.cbData := Buffer.Size;
        CopyData.lpData := Buffer.Memory;
        SendMessage(Target, wm_CopyData, Source, LParam(@CopyData));
      finally
        Buffer.free;
      end;
    end;
    

    We write the lengths of the strings in addition to the strings’ characters so that the recipient knows how many characters belong to each one. The recipient’s code will look like this:

    procedure TBasicForm.WMCopyData(var Message: TWMCopyData);
    var
      Rec: TMyRec;
      Len: Integer;
      Buffer: TStream;
    begin
      Buffer := TReadOnlyMemoryStream.Create(
        Message.CopyDataStruct.lpData, Message.CopyDataStruct.cbData);
      try
        if Message.CopyDataStruct.dwData = 0 then begin
          Buffer.Read(Len, SizeOf(Len));
          SetLength(Rec.name, Len);
          if Len > 0 then
            Buffer.Read(Rec.name[1], Len * SizeOf(Char));
    
          Buffer.Read(Len, SizeOf(Len));
          SetLength(Rec.add, Len);
          if Len > 0 then
            Buffer.Read(Rec.add[1], Len * SizeOf(Len));
    
          Buffer.Read(Rec.age, SizeOf(Rec.age));
    
          // TODO: Do stuff with Rec here.
    
          Message.Result := 1;
        end else
          inherited;
      finally
        Buffer.Free;
      end;
    end;
    

    I’ve used the non-standard TReadOnlyMemoryStream since it makes everything easier. Here’s a simple implementation for it:

    type
      TReadOnlyMemoryStream = class(TCustomMemoryStream)
      public
        constructor Create(Mem: Pointer; Size: LongInt);
        function Write(const Buffer; Count: LongInt): LongInt; override;
      end;
    
    constructor TReadOnlyMemoryStream.Create;
    begin
      inherited Create;
      SetPointer(Mem, Size);
    end;
    
    function TReadOnlyMemoryStream.Write;
    begin
      Result := 0;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 457k
  • Answers 457k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Is that service / respository container fine ? The RepositoryContainer… May 15, 2026 at 10:56 pm
  • Editorial Team
    Editorial Team added an answer A couple of things: You can read a number with… May 15, 2026 at 10:56 pm
  • Editorial Team
    Editorial Team added an answer Nope... they will remain the same. May 15, 2026 at 10:56 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.