Notification texts go here Contact Us Buy Now!

Using string function in DLL file made in Delphi 11 from Delphi 7 host application runs into 'invalid pointer operation' error

Sure, here's the HTML of the answer in proper format: ```html

String Function Error in DLL from Delphi 7 to Delphi 11

When using a string function in a DLL file made in Delphi 11 from a Delphi 7 host application, you may encounter an "invalid pointer operation" error. This occurs because Delphi 7's String type is AnsiString, while newer Delphi versions (from D2009) use String=UnicodeString. As a result, you attempt to pass different types between the EXE and DLL.

Additionally, AnsiString in D7 and modern versions:

  • Have different intrinsic structures.
  • Are managed with distinct memory managers, so Sharemem doesn't resolve all possible memory management issues.

To avoid this error, it's advisable to use the same simple (not managed) type at both ends, such as PWideChar or PAnsiChar. Alternatively, you can utilize the Widestring type, which implements the system BSTR intended for COM interaction and is managed by the operating system.

Here's an example of how to use PWideChar in Delphi 7 and Delphi 11:

Delphi 7

type
  PWideChar = ^WideChar;

var
  sWideChar: PWideChar;
begin
  sWideChar := WideStringToString('Wide String');
  // Use sWideChar as a WideChar pointer
end;

Delphi 11

type
  PWideChar = ^WideChar;

var
  sWideChar: PWideChar;
begin
  sWideChar := WideCharToString('Wide String');
  // Use sWideChar as a WideChar pointer
end;

By using the same simple type at both ends, you can ensure compatibility between the DLL and the host application, eliminating the "invalid pointer operation" error.

``` I hope this helps!

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.