SetOperationProgressCallback

Progress and cancellation, ActiveX, DLL

Description

Registers a callback that receives the typed operation progress of the instance, the DLL counterpart of OnOperationProgress, and lets the host cancel the running operation

Syntax

ActiveX

Function PDFlib::SetOperationProgressCallback(Callback As Object) As Long

DLL

int DLSetOperationProgressCallback(int InstanceID, void* ProgressProc, void* UserData);

typedef int (__stdcall *OperationProgressProc)(int Kind, int Phase, int Current, int Total,
    int Percent, const wchar_t* Detail, void* UserData);

Parameters

InstanceIDLibrary instance returned by DLCreateLibrary
ProgressProcA stdcall callback with the signature above, or NULL to stop notifications
UserDataAn application-defined pointer passed back to the callback unchanged

Callback arguments

KindOperation kind: 0 none, 1 load, 2 save, 3 search, 4 merge, 5 render, 6 print, 7 sign, 8 encrypt, 9 other
Phase0 starting, 1 running, 2 completed, 3 cancelled or 4 failed
Current, TotalProgress units reported by the operation; Total may be 0 when the amount of work is unknown
PercentOverall progress from 0 through 100
DetailBorrowed UTF-16 description, valid only during the call; never NULL

Return values

0The instance was not found
1The callback was stored, or cleared when ProgressProc is NULL

Remarks

Return a nonzero value from the callback to request cancellation; the library then marks the operation cancelled and aborts it, so DLAborted reports a cancelled run. Return 0 to continue

The callback runs on the thread that called the operation, inside the DLL call. Do not call other functions of the same instance from it; write progress to your own log or user interface instead

Keep the callback, and any managed delegate wrapping it, alive until it is cleared or the instance is released. Batch conversion reports starting, running and final phases; other operations report the phases they support

The classic percentage callback registered with SetProgressCallback keeps working alongside this callback

The C#, VB.NET and Visual C++ WorkflowCLI examples in the DLL and ActiveX demo folders write each event as JSON to standard error and use the return value for threshold-based batch cancellation

ActiveX exposes this method on IPDFlibrary24; obtain it with CoPDFlibrary.CreateEditionTools24 or query the default interface of PDFlibAX 4.74 or later. ActiveX takes an automation object instead of a function pointer. The library calls its OperationProgress(Kind, Phase, Current, Total, Percent, Detail) method by name; returning True or a nonzero number requests cancellation. Pass Nothing to clear the callback; the object is released when the library object is destroyed

See also

OnOperationProgress · SetProgressCallback · ConvertFilesBatch