Teknik makale

PDFlibPas: DLL, ActiveX, and Dylib integration in Delphi

losLab PDF Library, Delphi ve C++Builder ekiplerine masaüstü, sunucu, DLL, ActiveX ve Dylib iş akışları için kaynak kodlu bir PDF motoru sağlar; dahili PDF/A ve PDF/UA kontrolleri, PAdES imzalama ve belgeleri harici PDF servisine göndermeden renderer seçimi sunar.

Bu yazı teams exposing PDF functionality across Delphi, C++Builder, scripting, legacy automation, or cross-platform components için hazırlanmıştır. DLL, ActiveX, and Dylib integration konusunu tek bir bileşen çağrısı olarak değil, üretim düzeyinde belge mühendisliği olarak ele alır.

Pratik risk şudur: native integration bugs often appear as memory corruption, string encoding issues, bitness mismatches, or exception-boundary failures rather than clear PDF errors. Bu nedenle akışın yazılı sözleşmeye, gözlemlenebilir tanılara ve gerçekçi regresyon dosyalarına ihtiyacı vardır.

Mimari kararlar

Define a binary contract before feature code. calling convention, bitness, thread model, and supported host languages / string encoding, path encoding, stream ownership, and buffer lifetime rules

  • calling convention, bitness, thread model, and supported host languages
  • string encoding, path encoding, stream ownership, and buffer lifetime rules
  • error reporting style, exception translation, and diagnostic callback behavior
  • deployment layout, dependency versioning, registration, and update policy

Uygulama akışı

Keep ownership and errors explicit at the boundary. Aşağıdaki sıra, iş akışını Delphi ve C++Builder ekipleri için incelenebilir tutar.

  1. publish a minimal binary contract before wrapping high-level PDF operations
  2. return explicit handles or result objects rather than sharing unmanaged pointers
  3. translate exceptions into stable error codes and diagnostic messages
  4. validate bitness and dependency versions during initialization
  5. ship sample calls that exercise Unicode paths, large buffers, and failure paths

Doğrulama kanıtı

Integration evidence for support cases. Bu alanları çıktı veya destek kaydıyla birlikte saklayın.

  • module version, host process bitness, calling convention, and dependency path
  • function name, input sizes, output buffer ownership, and returned status code
  • encoded path or string policy used for the call
  • diagnostic trace that does not cross memory ownership boundaries unsafely

The PDF API is only half of the contract

A DLL, ActiveX, or Dylib layer needs stable calling conventions, buffer ownership rules, string encoding, version reporting, error codes, and deployment checks. Treating it as a thin wrapper without those rules makes support difficult.

Decision table for DLL, ActiveX, and Dylib integration

A decision table keeps product ownership visible when the same workflow is reused by a desktop tool, service job, and support utility.

DecisionEngineering reasonEvidence
calling convention, bitness, thread model, and supported host languagespublish a minimal binary contract before wrapping high-level PDF operationsmodule version, host process bitness, calling convention, and dependency path
string encoding, path encoding, stream ownership, and buffer lifetime rulesreturn explicit handles or result objects rather than sharing unmanaged pointersfunction name, input sizes, output buffer ownership, and returned status code
error reporting style, exception translation, and diagnostic callback behaviortranslate exceptions into stable error codes and diagnostic messagesencoded path or string policy used for the call

Mühendislik inceleme notları: DLL, ActiveX, and Dylib integration

Özelliğin bir demoyu aşıp sürüm, destek ve müşteri eskalasyonu sırasında savunulabilir olduğunu doğrulamak için bu inceleme notlarını kullanın.

  • Karar: calling convention, bitness, thread model, and supported host languages. Uygulama baskı noktası: return explicit handles or result objects rather than sharing unmanaged pointers. Kabul kanıtı: encoded path or string policy used for the call. Regresyon tetikleyicisi: uncaught native exceptions can terminate hosts that cannot inspect Delphi state
  • Karar: string encoding, path encoding, stream ownership, and buffer lifetime rules. Uygulama baskı noktası: translate exceptions into stable error codes and diagnostic messages. Kabul kanıtı: diagnostic trace that does not cross memory ownership boundaries unsafely. Regresyon tetikleyicisi: ANSI paths may work in tests and fail for customer names or localized folders
  • Karar: error reporting style, exception translation, and diagnostic callback behavior. Uygulama baskı noktası: validate bitness and dependency versions during initialization. Kabul kanıtı: module version, host process bitness, calling convention, and dependency path. Regresyon tetikleyicisi: ActiveX registration can succeed for one bitness and fail for another host
  • Karar: deployment layout, dependency versioning, registration, and update policy. Uygulama baskı noktası: ship sample calls that exercise Unicode paths, large buffers, and failure paths. Kabul kanıtı: function name, input sizes, output buffer ownership, and returned status code. Regresyon tetikleyicisi: callbacks must not outlive buffers owned by the caller
  • Karar: calling convention, bitness, thread model, and supported host languages. Uygulama baskı noktası: publish a minimal binary contract before wrapping high-level PDF operations. Kabul kanıtı: encoded path or string policy used for the call. Regresyon tetikleyicisi: uncaught native exceptions can terminate hosts that cannot inspect Delphi state

Sınır durumları

  • ANSI paths may work in tests and fail for customer names or localized folders
  • ActiveX registration can succeed for one bitness and fail for another host
  • callbacks must not outlive buffers owned by the caller
  • uncaught native exceptions can terminate hosts that cannot inspect Delphi state

Delphi / C++Builder notes

PDFlibPas should sit behind a small service boundary that receives files, streams, profiles, and credentials, then returns output paths, warnings, metrics, and validation status. Important terms include DLL, ActiveX, Dylib, calling convention, buffer ownership, Unicode path.

Delphi kod örneği

Aşağıdaki Delphi taslağı bu konu için pratik bir servis sınırını gösterir. Politika kontrollerini, günlüklemeyi ve doğrulamayı dar ürün çağrısı bölümünün dışında tutarak akışı test edilebilir bırakın.

procedure LoadPdfEngineForHost(const LibraryPath: string);
begin
  RequireFileExists(LibraryPath);
  FEngine := TPDFlib.Create;
  FHostAdapter := CreateHostAdapter(FEngine);
  FHostAdapter.RegisterErrorCallback(LogPdfEngineError);
  FHostAdapter.RegisterBufferReleaseCallback(ReleaseReturnedBuffer);
end;

Üretim kontrol listesi

  • İş akışını boş bir dosyada, normal bir müşteri dosyasında ve en kötü durum dosyasında çalıştırın
  • Oluşturulan PDF'yi hedef görüntüleyici, doğrulayıcı, yazıcı veya aşağı akış uygulamasıyla açın
  • Ürün sürümünü, profil sürümünü, giriş karmasını, çıktı yolunu, geçen süreyi ve uyarı sayısını kaydedin
  • Parolaları, sertifikaları, geçici dosyaları ve müşteri verilerini açık saklama kuralları altında tutun
  • Bir müşteri dosyası yeni bir uç durum ortaya çıkardığında regresyon belgeleri ekleyin

Ürün belgeleri

PDFlibPas

Ek kod örnekleri

var
  Inst, Doc: Integer;
begin
  Inst := DLCreateLibrary;                       // one instance per worker thread
  try
    Doc := DLLoadFromFile(Inst, 'in.pdf', '');   // returns a DocumentID, 0 on failure
    if Doc <> 0 then
    begin
      DLEncrypt(Inst, 'owner-secret', 'user-secret', 3,
        DLEncodePermissions(Inst, 1, 0, 0, 0, 0, 0, 0, 1));
      DLSaveToFile(Inst, 'out.pdf');
    end;
  finally
    DLReleaseLibrary(Inst);                      // frees every document the instance owns
  end;
end;
var
  P: PWideChar;
  PageText: string;
begin
  P := DLGetPageText(Inst, 7);   // pointer into a library-owned buffer
  PageText := P;                 // copy now; a later call may reuse the buffer
end;