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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:12:45+00:00 2026-05-13T12:12:45+00:00

I need call a DLL file in my delphi code, here is the code

  • 0

I need call a DLL file in my delphi code, here is the code snippet of the DLL Head file:

#define BookInfoDLL __declspec(dllexport)

struct _BookTime
{
    unsigned char day;
    unsigned char month;
    unsigned short year;
};

struct _stBookData
{
    unsigned char encrypt;
    _BookTime bkTime;
    unsigned int  PageCount;
};

int BookInfoDLL UpdateBooks(const char * const pBookID, 
  const char cBookTypeWord, 
  const _stBookData * const pBookData, 
  const int nBookDataCounter);

I need invoke the dll function “UpdateBooks” in my delphi code.
How can I convert those code into delphi? Thank you!

  • 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-13T12:12:46+00:00Added an answer on May 13, 2026 at 12:12 pm

    Snippet for non-managed Delphi code (not tested, but compiles and changed according suggestions in comments):

    interface
    
    type
    
      TBookTime = packed record
        day   : byte; // unsigned 8-bit  
        month : byte;
        year  : word; // unsigned 16-bit
       end;
    
      TBookData = packed record
        encrypt   : byte;
        bkTime    : TBookTime;
        PageCount : LongWord;   // unsigned 32-bit
      end;
    
      TBookDataPtr = ^TBookData;
    
    function UpdateBooks(
               pBookID          : PChar;
               cBookTypeWord    : byte;
               pBookData        : TBookDataPtr;
               nBookDataCounter : integer
             ) : integer; stdcall; external 'dll_file_name.dll' name 'UpdateBooks';
    
    implementation
    
     // ... 
    
    end;
    

    Simple call UpdateBooks(...) from delphi code.


    Update: code changed, thanks for commenting!

    Below is snippets for sample calls …

    Common functions and constants for all snippets:

    // --- Test data fill utility and constants -----------------------------------
    
    const
      BOOK_ID         = 'Test Book ID';
      BOOK_TYPE_WORD  = 'T';
      BOOK_DATA_COUNT = 5;
    
    procedure FillTestBookData(pBookData : TBookDataPtr; iTestNum : integer);
    begin
      if(pBookData = nil) then exit;
    
      pBookData^.encrypt := iTestNum;
      pBookData^.bkTime.day := iTestNum;
      pBookData^.bkTime.month := iTestNum;
      pBookData^.bkTime.year := 2000 + iTestNum;
      pBookData^.PageCount := iTestNum;
    
    end;
    

    Calling function in common Delphi style:

    // --- Test procedure in Delphi style -----------------------------------------
    
    procedure TestBookUpdate_DelphiStyle;
    var
      bookArray   : array of TBookData;
      iBookNumber : integer;
    begin
    
      SetLength(bookArray, BOOK_DATA_COUNT);
      try
    
        for iBookNumber := Low(bookArray) to High(bookArray) do begin
          FillTestBookData( @(bookArray[iBookNumber]), iBookNumber );
        end;
    
        UpdateBooks( 
          PChar(BOOK_ID), ord(BOOK_TYPE_WORD), 
          @(bookArray[Low(bookArray)]), BOOK_DATA_COUNT 
        );
    
      finally
        SetLength(bookArray, 0); // no explicit requirement to include in code
      end;
    
    end;
    

    Bonus: same test calls in C-style and Pascal-style 🙂

    // --- Test procedure in Old Delphi (plain Pascal) style ----------------------
    
    type
      TBookDataOldArray = array[0..0] of TBookData;
      TBookDataOldArrayPtr = ^TBookDataOldArray;
    
    // Store range checking compiler option state
    {$IFOPT R+}
      {$DEFINE RANGE_CHECK_ON}
    {$ENDIF}
    
    procedure TestBookUpdate_OldDelphiStyle;
    var
      bookArrayPtr : TBookDataOldArrayPtr;
      iBookNumber  : integer;
    begin
    
      GetMem(bookArrayPtr, BOOK_DATA_COUNT*sizeof(TBookData));
      try
        // Disable range checking compiler option
        {$R-}
    
        for iBookNumber := 0 to BOOK_DATA_COUNT - 1 do begin
          FillTestBookData(@(bookArrayPtr^[iBookNumber]), iBookNumber);
        end;
    
        // Restore range checking compiler option if turned on before disabling
        {$IFDEF RANGE_CHECK_ON}{$R+}{$ENDIF}
    
        UpdateBooks(
          PChar(BOOK_ID), ord(BOOK_TYPE_WORD), TBookDataPtr(bookArrayPtr), BOOK_DATA_COUNT
        );
    
      finally
        FreeMem(bookArrayPtr);
      end;
    
    end;
    
    // --- Test procedure in C style ---------------------------------------------
    
    procedure TestBookUpdate_CStyle;
    var
      bookArrayPtr  : TBookDataPtr;
      curBookPtr    : TBookDataPtr;
      curBookNumber : integer;
    begin
    
      bookArrayPtr := AllocMem( BOOK_DATA_COUNT * sizeof(TBookData) );
      try
        curBookNumber := 0;
        curBookPtr := bookArrayPtr;
        while(curBookNumber < BOOK_DATA_COUNT) do begin
          FillTestBookData( curBookPtr, curBookNumber );
          inc(curBookNumber);
          inc(curBookPtr, 1);
          // Another pointer increment solution is :
          // curBookPtr := PChar(curBookPtr) + sizeof(TBookData);
        end;
    
        UpdateBooks( PChar(BOOK_ID), ord(BOOK_TYPE_WORD), bookArrayPtr, BOOK_DATA_COUNT );
    
      finally
        FreeMem(bookArrayPtr);
      end;
    
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my C# code, I need to call a function from a C++ Dll
I need to use a DLL file from qsBarcode http://www.qsbarcode.de/en/index.htm (here is the download
Question: I need to call a C# dll from a C++ executable. I use
I need to call some methods in Wininet.dll from a Java program. I can
I need to call a function in an unmanaged .dll written in C lang
I have a third party DLL i need to call from my C# program.
Hi I use interop to call C# code in Delphi. C# code has a
I need to implement a Win32 DLL and need call it by C# DllImport
I'm attempting to call a method on the ssdeep fuzzy.dll The .h file is
I have a C# dll that I need to call from unmanaged C++. 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.