In your Execute() method, you must call CoInitialize and CoUnitialize to install and tear down the COM library.
Your main thread automatically does this in the Application.Initialize() procedure, however other calls require a CoInitialize call before calling the COM functions.
Make sure you call CoInitialize in the Execute() method, and not in the constructor, because the constructor is executed in the parent thread (usually in the main thread). This is not where you need it. It must be called from the thread you plan to call COM calls.
I recommend using this format:
try // OleCheck will raise an error if the call fails OleCheck(CoInitializeEx(NIL, COINIT_MULTITHREADED or COINIT_SPEED_OVER_MEMORY)); try // Do work here finally CoUninitialize; end; except // We failed, do something end;
This allows you to catch an error if it is not initialized and ensures that you call CoUninitialize .
source share