Home/ Reference/ Connection & Init

win32com.client.Dispatch("CorelDRAW.Application")

No version number, so it binds to whatever version is registered as default. On a machine with several versions installed you may not get the one you wanted.

Signature

win32com.client.Dispatch("CorelDRAW.Application")

Notes

No version number, so it binds to whatever version is registered as default. On a machine with several versions installed you may not get the one you wanted.

Python example (runnable)

Requires pywin32. The example assumes app / doc / page / layer are already connected. See Connection & Init
Python
import win32com.client

# no version number: connects to the default registered version
# with several versions installed you may land on the wrong one
app = win32com.client.Dispatch("CorelDRAW.Application")

print("Actually connected to version: ", app.Version)   # check app.Version to see which one you got

Without a version suffix, Windows makes the decision for you

Drop the version from the ProgID and the registry leaves you one layer of indirection:

Registry path
HKEY_CLASSES_ROOT\CorelDRAW.Application
  └─ CurVer  (default value) = "CorelDRAW.Application.24"

Dispatch("CorelDRAW.Application") reads that CurVer and then resolves the concrete version it points at. So "no version" does not mean "any version works" — it means "whichever one the registry currently names".

Who writes CurVer, and when it changes

Each version's installer, plus the COM self-registration that runs the first time that version starts. The important part: the last writer wins, not the highest version.

So this is a real scenario, and a hard one to notice. Both 2019 and 2023 are installed. One day you double-click an old file, or launch 2019 from an old shortcut, and it re-registers the ProgID. Now CurVer points back at .21. Your script has not changed a character, but its behaviour has — enum constants differ, arguments are rejected, export options are missing.

That is the argument against versionless ProgIDs in production: it turns a reproducible script into something that depends on machine state.

Reading the real value

Instead of guessing a version number, ask the registry:

Python
import winreg

def current_progid():
    key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, r"CorelDRAW.Application\CurVer")
    value, _ = winreg.QueryValueEx(key, "")
    winreg.CloseKey(key)
    return value            # e.g. "CorelDRAW.Application.24"

print(current_progid())

Log that value. The next time something misbehaves, you will know which version you were actually talking to.

Enumerating the versions registered on a machine

Walk the HKEY_CLASSES_ROOT subkeys starting with CorelDRAW.Application.. One caveat you must keep in mind: present in the registry does not mean launchable. CorelDRAW uninstalls routinely leave their COM registration behind, and those orphan keys keep showing up in the list. Treat the result as candidates, not facts — each one has to survive an actual Dispatch before you count it.

32-bit versus 64-bit: the quiet trap

CorelDRAW has been 64-bit since X6, and its COM registration lives in the 64-bit registry view. 32-bit Python reads the WOW6432Node branch and cannot see those keys.

The result is not a helpful message. Dispatch simply throws:

Error
pythoncom.com_error: (-2147221164, 'Class not registered', None, None)

-2147221164 / 0x80040154 is REGDB_E_CLASSNOTREG. When you see it, check your interpreter's bitness before you go hunting for a typo in the ProgID:

Shell
python -c "import struct,sys; print(sys.version); print(struct.calcsize('P')*8, 'bit')"

If it says 32 bit, that is your answer. Switch to 64-bit Python — COM has no cross-bitness shortcut.

When to use it, when not to

The recommended pattern: read, connect, confirm

Python
import logging
import winreg
import win32com.client

log = logging.getLogger(__name__)

def cur_ver():
    try:
        k = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, r"CorelDRAW.Application\CurVer")
        v, _ = winreg.QueryValueEx(k, "")
        winreg.CloseKey(k)
        return v
    except OSError:
        return None            # not installed, or the registration was cleaned

progid = cur_ver()
if not progid:
    raise SystemExit("No CorelDRAW COM registration found - install it and run it once")

log.info("connecting via %s", progid)
app = win32com.client.Dispatch(progid)
log.info("connected, app.Version=%s", app.Version)

app.Version returns the application's own version string, which is not the same thing as the number in the ProgID — do not compare them directly. Its value is in the log line: when something goes wrong later, you know exactly which build was running.

About this section: Connection & Init

Connection & Init — connecting to CorelDRAW over COM.

Other entries in this section