Search code examples
delphiautomationole

EOleSysError with message 'Invalid number of parameters' when automating PDFCreator from Delphi app


I am trying to automate PDFCreator from a Delphi application with the following sample code:

procedure TForm13.Button1Click(Sender: TObject);
var
  PDFCreatorQueue,
  job: OleVariant;
begin
  PDFCreatorQueue := CreateOleObject('PDFCreatorBeta.JobQueue');

  if not VarIsNull(PDFCreatorQueue)then
  begin
    try
      PDFCreatorQueue.Initialize();
//
//      if not PDFCreatorQueue.WaitForJob(15) then
//        MessageDlg(SPDFCreatorTimeout, mtError, [mbOK], 0)
//      else
//      begin
//        job := PDFCreatorQueue.NextJob();
//        job.ConversionProfileByGuid := 'DefaultGuid';
//        job.ConvertTo(FilePath);
//
//        if(not job.IsJobFinished or not job.JobSucceed) then
//          MessageDlg(Format(SPDFCreatorCouldNotConvertFile, [FilePath]), mtError, [mbOK], 0);
//      end;
    finally
      PDFCreatorQueue.ReleaseCom();
    end;
  end
  else
    MessageDlg(SPDFCreatorConnectionError, mtError, [mbOK], 0);
end;

At the line PDFCreatorQueue.Initialize(); an exception occurs:

EOleSysError with message 'Invalid number of parameters'

The method Initialize on the PDFCreator side does not have any parameters:

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[Guid("66A9CAB1-404A-4918-8DE2-29C26B9B271E")]
[ProgId("PDFCreatorBeta.JobQueue")]
public class Queue : IQueue
{

...

    /// <summary>
    ///     Initializes the essential components like JobInfoQueue for the COM object
    /// </summary>
    public void Initialize()
    {

What am I missing?


Solution

  • There is specific behavior of calling COM from Delphi.

    When You implement parameter less method of .net com visible assembly

    class CShaprClass
    {
      Initialize();
    }
    

    When You calling such parameter less method in Delphi code:

      PDFCreatorQueue.Initialize();
    

    You will get Invalid Parameters Error. Delphi in this calling method transcription inform COM that will be sending parameters.

    You should call

      PDFCreatorQueue.Initialize;