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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:10:36+00:00 2026-06-12T16:10:36+00:00

I have a Delphi 2010 DLL that will be used to compress some data

  • 0

I have a Delphi 2010 DLL that will be used to compress some data from a C# APP. The DLL function looks like this:

function CompressString(aInputString: PAnsiChar; aInputStringSize: Integer; 
  var aOutPutString: PAnsiChar; var aOutPutStringSize: Integer; 
  var aErrorMsgBuffer: PAnsiChar; var aErrorMsgBufferSize: integer): Integer; 
  stdcall; export;

The C# method looks like this:

[DllImport("MyDLL.dll", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Ansi)]
public static extern int CompressString(string aInputString, 
  int aInputStringSize, ref string aOutPutString, 
  out int aOutPutStringSize, ref string aErrorMsgBuffer, 
  out int aErrorMsgBufferSize);

My problem is that aOutPutString is being truncated, only part of the data is being seen by the C# App. If I change aOutPutString inside the Delphi DLL to be a simple literal constant (only for testing) it works fine.

Inside the DLL, I am working with strings. In the end of the function, I call:

StrPCopy(aOutPutString, vOutOutAnsiStr);

To convert an AnsiString do PAnsiChar.

I guess I should not be using PAnsiChar but an array of byte, but I am not sure how to do that.

  • 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-12T16:10:37+00:00Added an answer on June 12, 2026 at 4:10 pm

    Using PAnsiChar makes the string truncate at the first ‘0’ byte.

    Instead of having an out parameter of the type PAnsiChar, you can have two out parameters: one of them is a pointer to a byte array, and the other is an integer which will contain the size of the array.

    You have to be careful not to free the array on the DLL, once you need to access it later. On C# side, in the external function declaration, you’ll catch the pointer as IntPtr and use the Marshal.Copy method to copy the content to a C# byte array.

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

Sidebar

Related Questions

I have written an application in Delphi 2010 that imports data from one database
I have Delphi 2007 code that looks like this: procedure WriteString(Stream: TFileStream; var SourceBuffer:
I have a Delphi 2010 DLL loaded in a Delphi 2010 app. It works
I have ported our project from Delphi 7 to Delphi 2010. After adding some
I have Delphi 2010 built DLL with two methods: function Foo1(a, b: Integer):PChar; export;
does Delphi 2010 have C# Style XML comments that show up when hovering over
I have just installed Delphi 2010 and got some troubles with idHTTP component. If
Delphi 2010 Windows 7 - 64 bit. I have an app which is reasonably
We have recently upgraded from Delphi 2009 to 2010. One of the things in
I have some MSVC++ compiled DLL's for which I have created COM-like (lite) interfaces

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.