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 6988883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:08:21+00:00 2026-05-27T19:08:21+00:00

OK – So I never seem to have a simple question. I have a

  • 0

OK – So I never seem to have a simple question.

I have a custom library (which is not written by me) written in C++. This library does some network comms and I just pass some data to it as a byte array and retrieve a byte array from it on the other side. The library handles all the network stuff for me the sending/receiving of data to/from client/server.

So for example, I can write a client and a server. From the client I produce a byte array, the library takes the byte array and sends it to a server. The server I’ve written uses the same library to do the reverse, ie handle all the receiving of traffic and eventually passes back a byte array.

The library defines the byte array as part of a struct as follows… (I’m loading the library statically in Delphi, don’t think that’ll make a difference, but I am using FastMM4 – is this going to affect the memory sharing model between app and dll? Far as I’m aware using FastMM should be OK, have also tried ShareMem to no avail)

struct content {
  void *data;
  int size;
}

Anyway, from my client I am attempting to send “Hello”… the accepted wisdom is that the byte array data is copied into this struct by using memcpy like so…

char *data = "Hello";
memcpy((void *)content.data(), data, strlen(data)); // last parameter is length, ie 5
// network.sendrequest(content);
// where content.data() returns the aforementioned pointer

On my server I reply with “World”. So the server replies as follows…

char *data = "World";
memcpy((void *)content.data(), data, strlen(data)); // last parameter is length, ie 5
// network.sendreply(content);

From a C++ client communicating with a C++ Server I receive this data on the server…

0x0035fdf6 "Hello" (or in Bytes... 72, 101, 108, 108, 111)

So after that essay, I think the C++ server code is correct because I can communicate correctly if I write a client in C++… But replacing the C++ client with a client written in Delphi doesn’t work. I’ve replaced memcpy with CopyMemory, which I thought did the same thing but somehow my byte array is different by the time it reaches the C++ server… My Delphi client does the following…

// lDataPointer is a retrieved reference to the 
// pointer (void *data; see above) defined in the 
// C++ library. It appears to be a valid pointer at runtime...
lContentPointer := content.data(); // from DLL
// Where ByteArray is populated with byte data of "Hello" 
CopyMemory(lContentPointer, @ByteArray, 5); // Copy from Exe to DLL
// network.sendrequest(lContentPointer);

// I have printed the byte array before the CopyMemory to check 
// its contents before sending, which is '72 101 108 108 111'

So the data from the Delphi client appears correct, but the data received on the server is incorrect… Somehow “Hello” (’72 101 108 108 111′) becomes

0x003efd96 "h,H" (or in Bytes 104, 19, 44, 2, 72)

I suspect I am doing something wrong with CopyMemory…? Or have I got the memory sharing wrong between the exe and the dll? How do I know what kind of memory model the C++ networking library uses? Or have I just copied that byte array incorrectly? Any help much appreciated…

  • 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-27T19:08:22+00:00Added an answer on May 27, 2026 at 7:08 pm
    CopyMemory(lContentPointer, @ByteArray, 5);
    

    The error is that ByteArray is, effectively, a pointer to the first element of the array. You are thus passing the address of the pointer to the first element of the array. In other words you have an extra, spurious, level of indirection. You need

    CopyMemory(lContentPointer, @ByteArray[0], 5);
    

    or

    CopyMemory(lContentPointer, Pointer(ByteArray), 5);
    

    As for CopyMemory vs memcpy, the former is a Win32 API function and the latter is a C standard library function. The two functions perform identical tasks and are interchangeable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple restful service that transforms a JAXB-anntotated beans to response XML
i have this code: <?php $valid_ext = array(pdf, doc); $args = array( 'post_type' =>
My NSXMLParser breaks on this string: <title>AAA &#8211; BCDEFGQWERTYUIO</title> I parsed it in this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We have different types of hyphens/dashes (in some text) populated in db. Before comparing
So to start, I have an array of XML files. These files need to
Have a webpage that will be viewed by mainly IE users, so CSS3 is
i have a text file with the following data: Calculated Concentrations 30.55 73.48 298.25
An extension to my previous question: Text cleaning and replacement: delete \n from a
I was beta-testing my iPhone App (not through xcode), and the app crashed. I

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.