Madman wrote:Concerning COM, yes, I have full control over it, but it requires some refactoring for thread safety.
Trivially it should be just adding critical sections/locks on each methods that need to access member variables.
Madman wrote:Also COM can fire up dialogs, so if everything I read is true, then it has to be Apartment threaded, and it has to have a message loop.
Huh? Usually it is ActiveX controls or object embedding then you will get a dialog. What are you talking about? The client/host program? If it is multithreaded it shouldn't be GUI in nature...
Madman wrote:And since it's a dll, I think there will be problems if I'll create threads there. Also, I couldn't find any documentation that confirms this, but it seems that if I'll create the dll as free threaded, I won't be able to use Apartment threaded COMs from within it (containment), and also, dialogs will deadlock or crash the consumer.
Yes, since you don't own the process spawning threads is typically bad form. However, the situation you described basically indicates that you need to implement your COM object as Both?
Madman wrote:The next idea was to create EXE COM, make it register as Free or Both threaded, and then create an additional thread, initialize it to STA and do the wrapping this way.
Let's try not go there yet.
Madman wrote:Unfortunately, the more I read the more confused I get, and each additional layer, workaround seems to bring only new problems (permissions for local server COM, deadlocks in consumer if I just change the COM to Free threaded) and so on.
Are you sure your object is going to be used all these different ways? Usually scripting/VB is not MTA, then what is being multithreaded there on the client/host side?
Madman wrote:I scanned through "Inside COM", read the whole relevant documentation I could find by googling, but I'm still afraid that I'll write something that will work on test system and will crash in the production environment for good because of some strange COM feature. All the time when I search for something I only get blog entries that says "Don't do that".
Sounds to me your test vs production environments are different in the sense that the production app is MT and your test app is AT? Sounds like a mess to begin with.
Madman wrote:So right now I'm torn between trying Local server workaround and digging though custom marshaling. And I have no idea if these approaches are valid.
May need a bit more background before I can comment further. It sounds like a mess.
The Model M is not for the faint of heart. You either like them or hate them.
Gerbils unite! Fold for UnitedGerbilNation, team 2630.