parameters: (
      prog_id, bForDemand=1
  )
return_statement: return disp
docstring: Given a COM prog_id, return an object that is using makepy support, building if necessary
docstring_summary: Given a COM prog_id, return an object that is using makepy support, building if necessary
docstring_tokens: Given a COM prog_id return an object that is using makepy support building if necessary
function: def EnsureDispatch(
      prog_id, bForDemand=1
  ):  # New fn, so we default the new demand feature to on!
      """Given a COM prog_id, return an object that is using makepy support, building if necessary"""
      disp = win32com.client.Dispatch(prog_id)
      if not disp.__dict__.get("CLSID"):  # Eeek - no makepy support - try and build it.
          try:
              ti = disp._oleobj_.GetTypeInfo()
              disp_clsid = ti.GetTypeAttr()[0]
              tlb, index = ti.GetContainingTypeLib()
              tla = tlb.GetLibAttr()
              mod = EnsureModule(tla[0], tla[1], tla[3], tla[4], bForDemand=bForDemand)
              GetModuleForCLSID(disp_clsid)
              # Get the class from the module.
              from . import CLSIDToClass
  
              disp_class = CLSIDToClass.GetClass(str(disp_clsid))
              disp = disp_class(disp._oleobj_)
          except pythoncom.com_error:
              raise TypeError(
                  "This COM object can not automate the makepy process - please run makepy manually for this object"
              )
      return disp
function_tokens: def EnsureDispatch ( prog_id , bForDemand = 1 ) : # New fn, so we default the new demand feature to on! disp = win32com . client . Dispatch ( prog_id ) if not disp . __dict__ . get ( "CLSID" ) : # Eeek - no makepy support - try and build it. try : ti = disp . _oleobj_ . GetTypeInfo ( ) disp_clsid = ti . GetTypeAttr ( ) [ 0 ] tlb , index = ti . GetContainingTypeLib ( ) tla = tlb . GetLibAttr ( ) mod = EnsureModule ( tla [ 0 ] , tla [ 1 ] , tla [ 3 ] , tla [ 4 ] , bForDemand = bForDemand ) GetModuleForCLSID ( disp_clsid ) # Get the class from the module. from . import CLSIDToClass disp_class = CLSIDToClass . GetClass ( str ( disp_clsid ) ) disp = disp_class ( disp . _oleobj_ ) except pythoncom . com_error : raise TypeError ( "This COM object can not automate the makepy process - please run makepy manually for this object" ) return disp