Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do I generate new GUID's for COM Servers? (Examples in Python)

I’m new at making COM servers and working with COM from Python so I want to clarify a few things I could not find explicit answers for:

Creating GUID’s Properly for COM servers

Do I generate:

  1. The GUID for my intended COM server manually, copy it and use that # for the server from then on in? Therefore, when I distribute the application the other users will use the same GUID I created during development.

  2. A new GUID each time the application or COM server object is initialized?

  3. A new GUID on a per computer basis, only once during the initial setup then have the app save the GUID # and on future loads it pulls that # from the users setup file?

Example Scenario 1:

i)  print(pythoncom.CreateGuid())   #in interpreter
ii) _reg_clsid_ = copy  above GUID into your app

Example Scenario 2:

i)_reg_clsid_ = pythoncom.CreateGuid()

Example Scenario 3:

if self.isfile = os.path.isfile(url):
    load_previous_generated_GUID(url)
else:
    #first time running application or setup file is missing
    GUID = pythoncom.CreateGuid()
    save_GUID_to_setup_file(GUID)

Can I use GUID’s for tracking program/COM server versions?

If scenario #1 above is correct then: When I make an upgrade I can test for the old GUID so I can interact with it correctly?

TODO: How do I get the GUID of a COM server from Python and/or VBA?

like image 419
Steve Lee Avatar asked Nov 02 '22 13:11

Steve Lee


1 Answers

You definitely want scenario 1. You should generate a CLSID once during development, and use that until you change the set of functions your class exports (to COM).

Not only can you use CLSIDs for tracking versions, you must change the CLSIDs whenever you release a new version, or else you break COM identity rules; breaking the rules usually results in obscure failure modes when invoking your object out-of-process.

Typically, however, you don't expose CLSIDs directly to code, you expose PROGIDs instead, which are human-readable strings with embedded versioning information, and use the Win32 API CLSIDFromProgID to convert between the two. (VBA will do this for you; Python may do this too.)

like image 181
Eric Brown Avatar answered Nov 15 '22 06:11

Eric Brown