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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:00:59+00:00 2026-06-12T10:00:59+00:00

I have to use an encoding function from an external C++ DLL in Delphi

  • 0

I have to use an encoding function from an external C++ DLL in Delphi 6.
Following is the declaration provided :

long <Function Name> (char *Data, long &Apply, char *ReturnVal, long &Size)

Data is the input value, Apply is a boolean value (default : FALSE), ReturnVal is the return value from the DLL and Size is the length of the ReturnVal.

To use this in Delphi 6, I wrote following Code:

implementation
   const
     EncoderDLL = '<DLL NAME>';
     FunctionName = 'FUNCTION NAME';
   var
      _TEST : function(const Data : PChar; Apply : PInteger;stOutput : Pchar;
          iSize : PInteger) : integer; stdcall;
   .....
   .....
   var
     stInput,stOutput : string;
     iLength,i1,iResult : integer;
     hnd : THandle;
   begin
     iLength := 0;
     i1 := 0;
     stInput := Trim(edtInput.Text);
     hnd := SafeLoadLibrary(EncoderDLL);
     if hnd > 0 then
     begin
       @_TEST := GetProcAddress(hnd,FunctionName);
       if @_TEST <> nil then
       begin
         iResult := _TEST(PChar(stInput),@i1,PChar(StOutput),@iLength); // ERROR
       end;
     end;
     FreeLibrary(hnd);
  end;

I am getting Access Violation in the line having ‘ERROR’ as comments.

If I replace PChar in the function declaration with string, then the access violation does not come at the same line. It comes while freeing the library. Also, the value of the iLength parameter is populated correctly.

Can anyone please provide pointers to resolve this issue.

  • 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-12T10:01:00+00:00Added an answer on June 12, 2026 at 10:01 am

    Keep PChar, and initialize StOutput to a non-empty string (of a sufficient length) before the call.

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

Sidebar

Related Questions

I have the following in myserver/index.js (which I run with node): server.configure(function() { server.use(express.methodOverride());
I have a question, which Unicode encoding to use while encoding .NET string into
I'm trying to use eclipse encoding UTF-8, for polish characters. Unfortunately, I still have
I have a file UTF-8 encoding in windows, and when i use it under
I have use semantic-analyze-proto-impl-toggle to switch between the function's proto and impl, but when
I get a ISO-8859-1-encoded string from an exernal DLL, and I must use it
I have tried to write an utility function that can convert my custom data
I have a program that reads arbitrary data from a file system and outputs
I have an unmanaged DLL that gets called from .NET with pre-allocated buffers to
I have to unmarshal and process XML from an external system over which 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.