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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:12:08+00:00 2026-05-29T23:12:08+00:00

Could anyone provide me with working example of passing arbitrary number of bytes through

  • 0

Could anyone provide me with working example of passing arbitrary number of bytes
through the parameter to a dll function?

I would like to do it without any extra memory unit, just only operate on basic windows types.

I need to “send” about 300 kb data per each call.

Should the memory allocated on the client side be free also on the client side?

  • 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-29T23:12:09+00:00Added an answer on May 29, 2026 at 11:12 pm

    The DLL function should look like this:

    procedure Test(Buffer: Pointer; Length: Integer); stdcall;
    begin
      //Buffer points to the start of the buffer. 
      //The Buffer size if Length bytes.
    end;
    

    Assuming you are calling it from another Delphi module the call could look like this:

    procedure Test(Buffer: Pointer; Length: Integer); stdcall; external 'test.dll';
    
    procedure CallTest;
    var
      Buffer: array of Byte;
    begin
      SetLength(Buffer, 1000);
      //populate Buffer
      Test(@Buffer[0], Length(Buffer));
    end;
    

    It is always preferable to define an interface which requires memory to be allocated and deallocated in the same module.

    The above example allocates and deallocates in the caller’s module. This means that the Test method would either have to process the Buffer completely before returning, or take a copy of the contents of Buffer before returning.

    Now, whilst it is possible to have the allocation and deallocation in the callee’s module, this is less common. It is less common because it is typically less convenient to do it this way. It often entails more API functions, or perhaps more a complex interface. You will be pushed into the route of callee allocation when the caller is not able to determine an appropriate size for the buffer.

    When data is being passed from caller to callee than caller allocate is invariably the best choice. When the data flows in the other direction it is more likely that callee allocates would be appropriate.

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

Sidebar

Related Questions

Could anyone provide working example in C++ with event handling for Skype4COM, i.e. incoming
I could really use an example of this. Can anyone provide me with a
Could anyone provide me with the pointers to source code for linux commands such
http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/trace.html Could anyone please provide me couple of examples of how to use Java
I've struggled a lot with Java but could not combine a working example of
Could anyone guide me in created a simple app in JS? What the app
Could anyone please let me know if there is a way to programatically determine
Could anyone explain to me in noob way what the difference is betweeen ImageIcon
Could anyone give me some help with this please? The content needs to appear
could anyone please clarify the meaning of line generalizes the tag object's storage of

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.