One more question about the line:
According to the Microsoft Documentation, this line is needed to initialize the COM library.
Do I have to ensure that this function is only called once? When reading out multiple files, could it be a problem to call it before each file processing or do I even have to?
It needs to be called once *per thread*. It CAN be called more than once per thread, but if you try to specify a different threading model than the used by the 1st call, you will get an
RPC_E_CHANGED_MODE error. Every *successful* call to
CoInitialize/Ex() requires a matching
CoUninitialize() call.
For example, when putting the reading process into a function like GetFilePropertyX(AFileName: string): string, would it be a problem/performance hit to call CoInitialize each time calling the function from within the function?
Don't do that. It is the calling thread's responsibility to initialize COM, not your function's. And if the thread hasn't initialized COM yet when your function is called, and you silently initialize COM on the caller's behalf, unexpected things *may* happen later on in the thread's code long after your function has exited. So just don't do it. If COM hasn't been initialized yet, you should just fail and exit. And document that your function requires COM to be initialized before called.
The backgound is: The function will not be called every time the program is started, so I do not want to call CoInitialize each time at program startup but only when needed.
The calling thread should initialize COM before calling your function. If the thread doesn't call your function, it doesn't need to initialize COM.