Por si ayuda en algo, te paso un script, que llamado de powercobol, devuelve el resultado de una operacion aritmetica utilizando ROUND_HALF_EVEN para el resultado, y otra que llama y ejecuta un link web, nada que extraordinario pero que te facilitara ver la mecanica de llamadas y respuestas via COM, tenia mas funciones que entregaban diferentes resultados, pero para mejor analisis las exclui y veas que no es dificil interacturar desde powercobol.
Código PYTHON:
import win32com.client as wc
import win32com.server.register
import time
import sys
from decimal import *
import os
import winreg
import pythoncom
class MODULOSCOM:
_public_methods_ = ['Calculo', 'Navegador']
_reg_progid_ = "MODULOS.COM"
_reg_clsid_ = "{80317A85-F824-45CD-82AC-3B3546C359EE}"
_reg_desc_ = "Servidor COM Python Para PowerVISUAL"
def Navegador(self, Texto):
import webbrowser
webbrowser.open(Texto)
return True
def Calculo(self, NumeroA, NumeroB, Operador, CantidadDecimales=2):
if type(NumeroA) != Decimal:
try:
NumeroA = Decimal(str(NumeroA))
except:
return 0
if type(NumeroB) != Decimal:
try:
NumeroB = Decimal(str(NumeroB))
except:
return 0
if Operador == '+':
Operacion = NumeroA + NumeroB
elif Operador == '-':
Operacion = NumeroA - NumeroB
elif Operador == '*':
Operacion = NumeroA * NumeroB
elif Operador == '/':
try:
Operacion = Decimal(str(NumeroA)) / Decimal(NumeroB)
except:
return 0
ResultadoPrevio = Decimal(str(Operacion))
Resultado = ResultadoPrevio.quantize(Decimal('1') / Decimal('10') ** Decimal(str(CantidadDecimales)),
rounding=ROUND_HALF_EVEN)
return Resultado
def remove_registry_entry(clsid):
try:
reg_key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, f"CLSID\\{clsid}", 0, winreg.KEY_SET_VALUE)
winreg.DeleteKey(reg_key, "")
print(f"Clave de registro de {clsid} eliminada.")
winreg.CloseKey(reg_key)
except Exception as e:
print(f"Error al eliminar la clave de registro: {e}")
def check_registry_clsid(clsid):
try:
reg_key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, f"CLSID\\{clsid}")
winreg.CloseKey(reg_key)
return True
except FileNotFoundError:
return False
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1].lower() == "register":
# Registra el servidor COM
win32com.server.register.UseCommandLine(MODULOSCOM)
print("Servidor COM registrado.")
elif len(sys.argv) > 1 and sys.argv[1].lower() == "unregister":
try:
print("Desregistrando el servidor COM...")
# Intentamos desregistrar usando UseCommandLine
win32com.server.register.UseCommandLine(MODULOSCOM, unregister=True)
print("Desregistro usando UseCommandLine completado.")
# Ahora eliminamos manualmente la clave del registro
remove_registry_entry(MODULOSCOM._reg_clsid_)
# Verificamos si la clave ha sido eliminada
if not check_registry_clsid(MODULOSCOM._reg_clsid_):
print("Servidor COM desregistrado correctamente.")
else:
print("El servidor COM sigue registrado.")
# Liberar las instancias COM si están en memoria
pythoncom.CoUninitialize()
print("Instancias COM liberadas.")
except Exception as e:
print(f"Error al desregistrar el servidor COM: {e}")
else:
print("Usar 'register' o 'unregister' como argumento.")
desde POWERCOBOL
Código COBOL:
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Objeto pic x(14) value "MODULOS.COM".
01 ModulosCom object reference COM.
01 NumeroA Pic X(15).
01 NumeroB Pic X(15).
01 Operador Pic X.
01 Resultado Pic X(15).
PROCEDURE DIVISION.
invoke COM "CREATE-OBJECT" using Objeto returning ModulosCom. *> creo el objeto
move "Text" OF CmText3 to NumeroA
move "Text" OF CmText5 to NumeroB
move "Text" OF CmText4 to Operador
invoke ModulosCom "Calculo" using NumeroA NumeroB Operador returning Resultado
move Resultado to "Caption" OF CmStatic6
move Resultado to "Text" OF pasartexto
* INVOKE pow-self "DisplayMessage" USING resultado
set ModulosCom to null
LLAMADO AL NAVEGADOR VIA COM
Código COBOL:
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Objeto pic x(14) value "MODULOS.COM".
01 ModulosCom object reference COM.
01 cuit pic x(11).
01 Resultado Pic X(15).
01 Texto pic x(100).
PROCEDURE DIVISION.
invoke COM "CREATE-OBJECT" using Objeto returning ModulosCom. *> creo el objeto
move spaces to texto
move "Text" OF dire to texto
invoke ModulosCom "Navegador" using texto returning Resultado
set ModulosCom to null
Espero que te sea util la información, no hay mucho en la web que nos pueda ayudar.
Suerte.