Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marshalling between threads when using COM4J.wrap #68

Open
tonyroberts opened this issue May 25, 2018 · 0 comments
Open

Marshalling between threads when using COM4J.wrap #68

tonyroberts opened this issue May 25, 2018 · 0 comments

Comments

@tonyroberts
Copy link

When constructing a wrapper from a C pointer to an interface using COM4J.wrap, all subsequent method calls on that object are done on a com4j.ComThread. This isn't the same thread that was used to create the object, and so it will cause problems.

When wrapping the pointer, com4j should marshal the object across to its com4j.ComThread instead of just taking the pointer.

One possible solution would be to use RegisterInterfaceInGlobal/GetInterfaceFromGlobal to pass a handle across the thread boundary and add a call to RevokeInterfaceFromGlobal when releasing the native object.

Is this something that anyone else has come across? Have I missed something, or is using COM4J.wrap not the right thing to be using for this purpose?

I'm happy to make the changes necessary, but is this project still being actively maintained by anyone? Are my changes likely to be merged?

tonyroberts added a commit to exceljava/com4j that referenced this issue May 29, 2018
Objects wrapped in this way can only be called from the same thread they
were created by (and wrapped in).

When using these wrapped objects calls to the COM object are done in the
same thread instead of using a second thread. This has the disadvantage
that these objects can't be passed around and used from anywhere, but
where a COM object has to be called from a specific thread it means they
can be used (mostly only a problem when the Java code is running in the
same process as an in-process COM server).

Fixes kohsuke#68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant