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

Do you have any ideas for a "Sample Python *server*" (and hooks in ctypes)? #35

Closed
junkmd opened this issue Dec 2, 2024 · 4 comments
Closed

Comments

@junkmd
Copy link

junkmd commented Dec 2, 2024

Hi @forderud,

I, as a maintainer of comtypes, would like to ask for your input on something.

Could you share your knowledge on implementing COM servers using comtypes and how the hooks ctypes.DllCanUnloadNow and ctypes.DllGetClassObject could work to this process?

You’ve located both COM client and server samples implemented in C# and C++ to this repository, but only client samples in Python.

comtypes documents a way to implement COM servers at https://pythonhosted.org/comtypes/server.html.
However, that documentation hasn’t been updated in a long time, and the tests verifying this functionality are currently broken.

If you are aware of methods for implementing COM servers in Python that may not be well known in the community, or if you’ve encountered challenges in doing so in the past, I’d appreciate it if you could share those insights.

In the CPython community, we’re exploring improvements to the hooks defined in ctypes, moving away from their current reliance on comtypes.

If you have any expertise or thoughts to share about these hooks, particularly from the perspective of someone with experience implementing COM servers in other languages, I’d be grateful if you could report them and participate in the discussion at python/cpython#127369.

@forderud
Copy link
Owner

forderud commented Dec 2, 2024

Hi @junkmd and thank you for reaching out. I fully acknowledge that this project is missing a Python-based COM server sample. There is a COM class implemented in MyClientImpl though, but this is of course not a full server since it lacks registry entries and a class factory.

I've never implemented a COM server myself in Python, so I'm currently unable to answer your questions related to that. However, let's keep this issue open, and I'll see if I'm able to take a stab at it within the next few months. No promises though...

@forderud
Copy link
Owner

forderud commented Dec 2, 2024

Status update: I've now added a small MyServerPy project that demonstrates how to implement COM servers in Python using comtypes. Most things seemed to work fine, but I stumbled across a TypeLib unregistration problem that I submitted a quick fix for in enthought/comtypes#677

@forderud
Copy link
Owner

forderud commented Dec 3, 2024

Closing issue, since there's now a sample Python server project in this repo.

I've only worked with EXE-based Python COM servers (CLSCTX_LOCAL_SERVER) myself, and not DLL-based (CLSCTX_INPROC_SERVER). I therefore lack experience with DllCanUnloadNow or DllGetClassObject from Python, and don't have much to contribute to that discussion.

@forderud forderud closed this as completed Dec 3, 2024
@junkmd
Copy link
Author

junkmd commented Dec 3, 2024

Thank you for your investigation, the sample, and the quick response.

Even if you don’t have experience with DllGetClassObject and DllCanUnloadNow, your research and sample will be helpful in the discussion of which layer those hooks should be implemented in.

As for UnRegisterTypeLib, let’s continue the discussion in enthought/comtypes#677.

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

2 participants