8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | 23c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux

Home » Articles » 8i » Here

COM Automation In Oracle8i

The COM Automation Cartridge simplifies PL/SQL access to COM objects by providing an API which masks most of the underlying EXTPROC interface. The cartridge can be installed by running the "ORACLE_HOME\com\comwrap.sql" script.

Assume you have a DLL registered on the Oracle server with a ProgID of Utils.clsUtils and a method called HostCommand which accepts a parameter string. To invoke this method you must define a PL/SQL procedure or function with the following basic format.

CREATE OR REPLACE PROCEDURE HostCommand(p_command  IN  varchar2) IS
  l_dummy           binary_integer;	
  l_app             binary_integer:=-1;
  l_i               binary_integer;
  l_err_src         varchar2(255);
  l_err_desc        varchar2(255);
  l_err_helpfile    varchar2(255);
  l_err_helpid      binary_integer;
BEGIN
  l_i := ORDCOM.CreateObject('Utils.clsUtils', 0, '', l_app);
  IF l_i != 0 THEN	
    ORDCOM.GetLastError(l_err_src, l_err_desc, l_err_helpfile, l_err_helpid);
    Dbms_Output.Put_Line(l_err_src);
    Dbms_Output.Put_Line(l_err_desc);
    Dbms_Output.Put_Line(l_err_helpfile);
  ELSE
    ORDCOM.InitArg();
    ORDCOM.SetArg(p_command, 'BSTR');
    l_i := ORDCOM.Invoke(l_app, 'HostCommand', 1, l_dummy);
    IF l_i != 0 THEN	
      ORDCOM.GetLastError(l_err_src, l_err_desc, l_err_helpfile, l_err_helpid);
      Dbms_Output.Put_Line(l_err_src);
      Dbms_Output.Put_Line(l_err_desc);
      Dbms_Output.Put_Line(l_err_helpfile);
    END IF;
  END IF;
  l_i := ORDCOM.DestroyObject(l_app);
END HostCommand;
/

Once this is compiled the HostCommand method can be invoked.

SQL> SET SERVEROUTPUT ON
SQL> EXEC HostCommand('Something.exe');

If you are planning to invoke multiple methods of multiple COM objects it would be advisable to place these calls into a package and centralise the error trapping (see "ORACLE_HOME\com\demos").

The EXTPROC process cannot invoke methods that instantiate windows on the server. Modifications to an invoked COM object will result in sharing violations until the session ends.

Hope this helps. Regards Tim...

Back to the Top.