Page 1 of 1

Marshalling COM-objects to threads

PostPosted: October 8th, 2008, 4:57 pm
by smelis
Hello all,

Does anybody have any experience with marshalling interfaces accross threads?

Problem description:

Application starts and creates 5 threads.
Each thread creates 5 "triggers", a COM-object and a timer.
OnTimer the thread loops through the triggers. If the triggers get triggered they call the COM-object belonging to its owning thread.

At this point I get message, saying that the COM-object was marshalled to a different thread. So I'm guessing I should be "marshalling" it to this thread (which I don't get, since the trigger operates within the context of the owning thread, which also owns the COM-object - but what the heck).

How should I do this? I've read the help and googled for it quite a bit, but I just don't understand the CoMarshalInterface() functions at all, so any help would be much appreciated.

If code is needed, I would be happy to post it here, but it is quite a lot, so I'll start work on a simple "produce.dpr"...

Thanks.
Stefan

PostPosted: October 9th, 2008, 9:43 am
by Kambiz
I have had tasks like this but never got such a message.

It is very difficult to guess what's wrong without seeing the code, but maybe this helps: If you create an object in the constructor of a thread, the main VCL thread is the owner.

PostPosted: October 9th, 2008, 12:56 pm
by smelis
Yes, I found that out yesterday. I've got the thread working now (by creating the COM-object at a later point than the thread-constructor), but now the problem's the other way around (when I call the COM-object from the main VCL thread).

Anyway, I'm still working on a little program that produces the error, but even that is a challenge, so I'll just post the entire code tonight..

Anyway thanks for the help so far..

PostPosted: October 10th, 2008, 7:26 pm
by smelis
Nevermind, I've found another way to do it... Anyway, thank you for your interest!

PostPosted: October 10th, 2008, 10:06 pm
by Kambiz
I'm glad to hear that.

Are you going to share it with us?

PostPosted: October 28th, 2008, 7:54 pm
by smelis
Messages :) PostThreadMessage() etc..
I figured I had to use them sooner or later, so here they were and now it works great!

PostPosted: October 28th, 2008, 8:27 pm
by Kambiz
Thank you!