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

  • SEARCH
  • Home
  • 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 8590987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:25:20+00:00 2026-06-11T23:25:20+00:00

i am sending data to a delphi app using WM_COPYDATA from vb6 app. in

  • 0

i am sending data to a delphi app using WM_COPYDATA from vb6 app. in my system which local is english, i receive the data correctly, but on another system with dutch local, the receive text is garbled.

the receiving app is the delphi, the code is

procedure TReceiverMainForm.WMCopyData(var Msg: TWMCopyData);
var
  copyDataType: TCopyDataType;
begin
  copyDataType := TCopyDataType(Msg.CopyDataStruct.dwData);

  //Handle of the Sender
  mmoResult.Lines.Add(Format('WM_CopyData from: %d', [msg.From]));

  case copyDataType of
    cdtString: HandleCopyDataString(Msg.CopyDataStruct);
  end;

  //Send something back
  msg.Result := mmoResult.Lines.Count;
end;

procedure TReceiverMainForm.HandleCopyDataString(
  copyDataStruct: PCopyDataStruct);
var
  s: string;
begin
  s := PChar(copyDataStruct.lpData);
  mmoResult.Lines.Add(s);
end;

EDIT

here is the vb6 code that is sending the data, the data am sending is string

Dim buf() As Byte
ReDim buf(1 To LenB(Message))
Call CopyMemory(buf(1), ByVal Message, Len(Message))
cds.dwData = 0
cds.cbData = Len(Message) + 1
cds.lpData = VarPtr(buf(1))
' Send the string.
Dim i As Long
i = SendMessage(lHwnd, WM_COPYDATA, MainForm.hwnd, cds)

can anyone tell me what am doing wrong?

  • 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-06-11T23:25:21+00:00Added an answer on June 11, 2026 at 11:25 pm

    VB strings are based on the COM BSTR string type, just like Delphi’s WideString string type is. A BSTR is a UTF-16 encoded Unicode string. LenB() returns the number of bytes that a VB string occupies when converted to the local machine’s current locale. You are not taking that into account. You are not copying the string bytes into your buffer correctly, and you are not setting the cds.cbData field to the correct value, either. Len() returns the number of UTF-16 encoded characters in the String, whereas LenB() returns the number of bytes instead. For an English string, Len() and LenB() will return the same value, but for a foriegn language that is not guaranteed.

    I suggest you send the original VB Unicode encoded data as-is, and change your Delphi code to treat the incoming data as Unicode instead of Ansi like it is currently doing (PChar is Ansi in Delphi 7, but is Unicode in Delphi 2009+).

    You also need to assign a unique value to the cds.dwData field. WM_COPYDATA is used by the VCL for some of its own internal data, so you have to differentiate between your WM_COPYDATA messages and the VCL’s messages.

    Try this instead:

    cds.dwData = RegisterWindowMessage("MyWMCopyData")
    If cds.dwData <> 0 Then
      cds.cbData = Len(Message) * 2 ' characters are 2-bytes each
      cds.lpData = StrPtr(Message) ' access the string's character buffer directly
      ' Send the string. 
      Dim i As Long 
      i = SendMessage(lHwnd, WM_COPYDATA, MainForm.hwnd, cds) 
    End If
    

    .

    var
      uMyWMCopyDataMsg: UINT = 0;
    
    procedure TReceiverMainForm.WMCopyData(var Msg: TWMCopyData); 
    var 
      s: WideString; // you can use UnicodeString in D2009+ 
    begin 
      if (uMyWMCopyDataMsg = 0) or (Msg.CopyDataStruct.dwData <> uMyWMCopyDataMsg) then
      begin
        inherited;
        Exit;
      end;
    
      mmoResult.Lines.Add(Format('WM_CopyData from: %d', [msg.From])); 
    
      SetString(s, PWideChar(Msg.CopyDataStruct.lpData), Msg.CopyDataStruct.cbData div SizeOf(WideChar)); 
      mmoResult.Lines.Add(s); 
    
      msg.Result := mmoResult.Lines.Count; 
    end; 
    
    initialization
      uMyWMCopyDataMsg := RegisterWindowMessage('MyWMCopyData');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When sending data from one iOS device to another, I receive these errors. 2012-06-21
I'm sending data from one page to the next in an MVC2 app. Page
we are sending data trough MQ from a z/OS/CICS system to an AS400. Original
I have problem with sending data from one form to another (using formhandler). I
I am sending data from iphone application to server but when it reads post
I am sending Data from a Server to a Client over the Internet using
Im sending data from one class to another, Its working but I have a
I am sending data using the HTTP POST verb . But I am not
am sending data using this code in vb6 cds.dwData = CLng(RegisterWindowMessage(MyWMCopyData)) cds.cbData = Len(Message)
I'm sending data from my Android app to my REST Service written as a

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.