How can I add new methods to a COM server that I have already registered?
Question: **EDIT** : turns out VBA can see the new methods if I restart Excel. My
question still stands, though, albeit in a different form: how can I force
Excel to see the new methods without restarting it?

I have a simple COM server that looks something like this:

    
    
    class COMServerThing:
        _public_methods_ = ["DoStupidThing"]
        _reg_progid_ = "COMServerThing.Utilities"
        _reg_clsid_ = "{A9DAECC7-2154-42E6-95B3-53A27EAB63E2}"
    
        def DoStupidThing(self):
            return 'foo'
    

I register it like this:

    
    
    import win32com.server.register
    win32com.server.register.UseCommandLine(COMServerThing)
    

This lets me create a new COMServerThing object from VBA and call my Python
code from Excel. Now I want to add a new method to this server. I've tried
doing the obvious thing:

    
    
    class COMServerThing:
        # Add the new method to the list of public methods ...
        _public_methods_ = ["DoStupidThing", "AnotherStupidThing"]
        _reg_progid_ = "COMServerThing.Utilities"
        _reg_clsid_ = "{A9DAECC7-2154-42E6-95B3-53A27EAB63E2}"
    
        def DoStupidThing(self):
            return 'foo'
    
        # ... and implement it on the class.
        def AnotherStupidThing(self):
            return 42
    

After doing this, I still can't access the newly registered method from VBA.
Here are some other things I've tried that didn't work:

  * I re-registered the server.
  * I unregistered and then re-registered the server.
  * I unregistered the server, changed the class ID, and then re-registered it.

The only thing that worked was renaming the server, changing its class ID,
renaming the source file that the server is in, and registering the new server
– at which point we're looking at a whole new COM server.

I'm not a Windows/COM developer, so I'm pretty sure I'm missing something
blatantly obvious. How can I add new methods to a COM server that I've already
registered?


Answer: Are you exposing your methods via [IDispatchEx](http://msdn.microsoft.com/en-
us/library/sky96ah7%28VS.94%29.aspx), or are you exposing them through custom
interfaces derived from IUnknown?

If you're exposing custom interfaces, then you'll most likely have to restart
Excel, since you're breaking [COM identity
rules](http://msdn.microsoft.com/en-
us/library/windows/desktop/ms686590%28v=vs.85%29.aspx). Even with
[IDispatch](http://msdn.microsoft.com/en-
us/library/windows/desktop/ms221608%28v=vs.85%29.aspx), the documentation
explicitly says

> The member and parameter DISPIDs must remain constant for the lifetime of
> the object. This allows a client to obtain the DISPIDs once, and cache them
> for later use.

