Page 1 of 1

PDF-XChange / Multithreaded COM

Posted: Fri Jan 12, 2007 10:23 am
by DISystemer
Several of our applications use PDF-XChange. We have implemented the communication with PDF-XChange in a DLL and tried using both message-based communication and the CPXCControl, and it all has been working well.

However, one our applications now need to use multithreaded COM, and then the communication with PDF-XChange doesn't work as it should anymore.

We have written a small test application that use automation to open a Word document and print it to PDF-XChange. When we use "CoInitialize()" to initialize COM it works well, but when we call "CoInitializeEx(nil, COINIT_MULTITHREADED) it fails.

Debugging shows that with multithreaded COM, the OnPrintingStarted event of the CPXCControl is never called, and if we use message-based communication the application never gets the pdfxcMsg_StartDoc message.

Hope you can help us with this problem.

Regards,
Arnstein

Posted: Fri Jan 12, 2007 10:32 am
by John - Tracker Supp
Hi,

Could you please provide us with the sample application you have created and any supporting additional files/instructions we may require to run and test here - please provide both compiled exe's' & dll's etc and source code for the project to allow us to modify if required.

Please zip any files uploaded - or emailed directly to us (usrfiles@tracker-software.com) also if posting here - please ensure your license codes are not included for general viewing.

Also please briefly outline the environment/system this is to be run on and Windows OS's in use.

thanks.

PDF-XChange / Multithreaded COM

Posted: Fri Jan 12, 2007 12:20 pm
by DISystemer
Please find attached a Delphi test project.
The program opens a document in Microsoft Word and prints it to PDF. It uses a DLL to do the actual communication with PDF-XChange. Please let me know if you need the source code for the DLL too.

Thanks,
Arnstein

Posted: Fri Jan 12, 2007 4:08 pm
by John - Tracker Supp
Hi,

Please do provide the source code for the DLL too - in the meantime I will ask our in-house Delphi Project dev to take a look at the project provided to date.

thanks.

Posted: Sat Jan 13, 2007 11:17 am
by DISystemer
Tracker Support wrote:Hi,

Please do provide the source code for the DLL too - in the meantime I will ask our in-house Delphi Project dev to take a look at the project provided to date.

thanks.
Will do, but since this is part of our commercial products I would prefer to send it directly to you rather than posting it in this forum. Is that possible?

Thanks,
Arnstein

Posted: Sat Jan 13, 2007 11:23 am
by John - Tracker Supp
Hi Arnstein,

Sure - please send direct to johnv@tracker-software.com - please do zip.

thanks.

Posted: Mon Jan 15, 2007 10:37 am
by John - Tracker Supp
Hi Arnstein,

Our project manager has now looked at this and advises that when using the ActiveX you should not use

CoInitializeEx(nil, COINIT_MULTITHREADED)

but should use

CoInitializeEx(nil, COINIT_APARTMENTTHREADED)

Unfortunately we could not rebuild and test your DLL as we are missing some project files - the first of which is ConfirmPasswordDialog.pas and most likely others ?

I hope the above helps.

Posted: Wed Jan 17, 2007 9:17 am
by DISystemer
I'm sending the missing files (ConfirmPasswordDialog) to you by email.

We have tried using apartment threading, and the communication with PDF-XChanage works well under this threading model. Unfortunately, the rest of our application doesn't, it demands multithreading.

What can we do to fix this? I suppose we could make a separate .exe to handle printing, but this means a lot of work for us as our application prints both using Microsoft Word and QuickReport (which gets data from various data sources).

Thanks,
Arnstein

Posted: Wed Jan 17, 2007 9:22 am
by John - Tracker Supp
Thanks Arnstein,

Unfortunately the received zip file when saved to disk here was corrupt - could you please re-send and as soon as received, will ask our Project Dev for Delphi to look into and advise.

Posted: Mon Jan 22, 2007 12:48 pm
by DISystemer
I have now made a simpler Delphi test project. It contains one form, and on this form I place a TCPXCControl (the PDF-XChange ActiveX control).

In the initialization code I initialize COM multithreaded:
"CoInitializeEx(nil, COINIT_MULTITHREADED);"

During startup, when the program tries to create the main form (the form with the ActiveX-control) the program fails with the following exception:
"EOleError: Could not obtain OLE control window handle". This occurs in the TOleControl.HookControlWndProc method in unit OleCtrls, which is part of Delphi VCL, and the program terminates.

The statement that fails is this: "FOleInPlaceObject.GetWindow(WndHandle)". It returns WndHandle=0, and this triggers an exception in the next statement.

In other words: The program fails before any of our printing code is executed, the only code that I have written in this test project is the call to CoInitialize.

If I change COM initialization to singlethreaded the program works fine, but as I said earlier we have to run our program multithreaded for other reasons so this is not an option.

At the moment, I'm not able to see what we can do to avoid this. Any help would be greatly appreciated.

My development machine runs Windows XP SP2 and I use Delphi 7.

Thanks,
Arnstein

Posted: Mon Jan 22, 2007 6:47 pm
by John - Tracker Supp
Hi Arnstein,

Later this month we will change the ActiveX from being a DLL to an Exe and we believe this will resolve this issue - we do not think there is any other way to satisfy your need without causing other issues.

Thanks for your patience.

Posted: Wed Feb 21, 2007 12:48 pm
by DISystemer
Where can we get the .exe version of the ActiveX control? We would like to test it as soon as it's available.

Thanks,
Arnstein

Posted: Wed Feb 21, 2007 5:18 pm
by John - Tracker Supp
Hi,

I am afraid it is not yet available as we are altering the JPEG2000 decoding encoding to resolve some important Viewing issues - until this is complete the ActiveX will not be released.

Thanks for your patience.