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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:55:12+00:00 2026-06-08T16:55:12+00:00

I have a delphi application that uses BTMemoryModule and imports/calls functions from a DLL.

  • 0

I have a delphi application that uses BTMemoryModule and imports/calls functions from a DLL.
The DLL is written in C/C++.

The delphi application sends an original pwidechar (array of 4 bytes or array of widechars) to a function.

I have no C/C++ pseudo code but it looks like this:

type
 TMyFunc = function ( p  : pointer ): pointer; stdcall;

procedure anynamehere();
var
 Addr     : TMyFunc;
 MyString : WideString;
begin
 [...]
  Addr := BTMemoryGetProcAddress('mydll.dll', 'ExportedFunc');
  MyString := 'TEST';
 [...]
 ExportedFunc (pwidechar(MyString));
 MessageBoxW (0, pwidechar(MyString), '', 0);
end;

The DLL should now have the original pointer to the MyString var.
The procedure in the delphiapp stays active (until the dll ExportedFunc is finished).
So the MyString var gets NOT disposed after the procedure ends.
My question now is:
Is it possible to CHANGE the value of MyString within the DLL? (technically possible…) But How? The string is null terminated so the user knows how long the pointer length is. But if the C++ DLL changes the value , doesn’t have the user also alloc new space or something? Or does this happen automatically?

Thanks for your help.

  • 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-08T16:55:15+00:00Added an answer on June 8, 2026 at 4:55 pm

    The DLL is welcome to change the pointed-to memory if it wants, and it doesn’t need to know the address of MyString, either. It only needs to know the address stored in MyString, which is exactly what you pass to it already. Since the function receives a pointer to a null-terminated array of WideChar values, the function should be declared like this:

    void* __stdcall ExportedFunc(wchar_t* arg);
    

    It can find out the length of the buffer with wcslen, and then modify the contents of the buffer in the usual ways. For example:

    {
      size_t const len = wcslen(arg);
      for (size_t i = 0; i < len; ++i)
        if (arg[i] == 'a')
          arg[i] = 'e';
      return 0;
    }
    

    You can have it return some other pointer value if you wish, but since the caller ignores it, it doesn’t really matter in this situation.

    When the caller assigned a value to MyString, space was allocated automatically by the OS on the program’s behalf via SysAllocString. The caller then passes that buffer to the DLL, and the DLL can modify it. The caller doesn’t need to do anything special with the buffer afterward. Delphi will call SysFreeString automatically when the calling function ends and MyString goes out of scope.

    You could also remove the PWideChar type cast and declare the function to receive a WideString in Delphi, a BSTR in C++. You could do all the same string manipulations in the DLL in addition to using SysStringLen instead of wcslen. You could pass MyString directly to the function:

    ExportedFunc(MyString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a console application in Delphi that queries information from several locations.
Background: I have an application written in Delphi that uses the Borland Database Engine
I have an application written in Delphi 6 that uses the Indy 9.0.18 HTTP
I have a Delphi 6 application that uses the Indy 9 components to maintain
I have an ISAPI Application in Delphi 6 that uses WebBroker. I need to
I have an application that called several other .exe components written in delphi. The
I have an application written in Delphi that adds / updates contacts in outlook.
We have a Windows desktop application written in Delphi that works fine on Windows
I have a Delphi (5) application that uses a log-in screen (standard user name/password)
I have an application that uses Rave Reports on Delphi 7. I want the

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.