calling dll from oracle
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: calling dll from oracle

  1. #1
    Join Date
    Oct 2001
    Posts
    8

    Question

    Hi,

    I have a dll which can be called from either c/c++ or VB. Can any one help me how to call the same dll Using Oracle.

    Regards,
    Nageswara Rao

  2. #2
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,684
    Not a problem as long as your server is running on NT/2000.

    You can call it using EXTPROC but it is easier to get hold of the COM automation stuff from OTN:

    http://otn.oracle.com/software/tech/...o/content.html

    This hides alot of the rubbish and makes the code look simpler. It's just like most Oracle interfaces. Get a handle to the DLL, define the methods you wish to interact with, define any parameters and bang!

    I've used it a couple of times in previous jobs and never had any problems. If you've used the Foreign Function Interface in Oracle Forms you'll find it very similar!

    Cheers

    Tim...
    Tim...
    OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
    OCA PL/SQL Developer
    Oracle ACE Director
    My website: www.oracle-base.com
    My blog: www.oracle-base.com/blog

  3. #3
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,684

    Quick Example

    Hi.

    I've just knocked something up to show you:

    I've made a DLL referenced using 'HostCommand.clsHostCommand' that contains:

    Sub HostCommand(sCommand As String)
    Dim result As Double
    result = Shell(sCommand, vbHide)
    End Sub

    The I ran the ORACLE_HOME\com\comwarap.sql to create all the COM cartridge stuff.

    Then I created the following PL/SQL:

    CREATE OR REPLACE PROCEDURE HostCommand(p_command IN varchar2) IS
    v_dummy binary_integer;
    v_app binary_integer:=-1;
    v_i binary_integer;
    v_err_src varchar2(255);
    v_err_desc varchar2(255);
    v_err_helpfile varchar2(255);
    v_err_helpid binary_integer;
    BEGIN
    v_i := ORDCOM.CreateObject('HostCommand.clsHostCommand', 0, '', v_app);
    IF v_i != 0 THEN
    ORDCOM.GetLastError(v_err_src, v_err_desc, v_err_helpfile, v_err_helpid);
    Dbms_Output.Put_Line(v_err_src);
    Dbms_Output.Put_Line(v_err_desc);
    Dbms_Output.Put_Line(v_err_helpfile);
    ELSE
    ORDCOM.InitArg();
    ORDCOM.SetArg(p_command, 'BSTR');
    v_i := ORDCOM.Invoke(v_app, 'HostCommand', 1, v_dummy);
    IF v_i != 0 THEN
    ORDCOM.GetLastError(v_err_src, v_err_desc, v_err_helpfile, v_err_helpid);
    Dbms_Output.Put_Line(v_err_src);
    Dbms_Output.Put_Line(v_err_desc);
    Dbms_Output.Put_Line(v_err_helpfile);
    END IF;
    END IF;
    v_i := ORDCOM.DestroyObject(v_app);
    END HostCommand;
    /

    Finally call it like:

    EXEC HostCommand('Something.exe');

    I know it's a crap example, but you get the idea. There are some examples in the ORACLE_HOME\com\demos directory.

    Remember, the extproc process remains until the session ends. If you try to do anything with the DLL before the session ends you'll get a sharing violation.

    Good Luck.
    Tim...
    OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
    OCA PL/SQL Developer
    Oracle ACE Director
    My website: www.oracle-base.com
    My blog: www.oracle-base.com/blog

  4. #4
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,684
    comwrap.sql not comwarap.sql

    Spot the crappy typist
    Tim...
    OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
    OCA PL/SQL Developer
    Oracle ACE Director
    My website: www.oracle-base.com
    My blog: www.oracle-base.com/blog

  5. #5
    Join Date
    Oct 2001
    Posts
    8
    Hi Tim,

    Thanks for the information.

    Regards,
    Nageswara Rao

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width