Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

using DLL in D2k

Posted on 2002-04-23
4
1,140 Views
Last Modified: 2011-10-03
Hi all,

would you pls let me know that:

How can i use DLL in my application having database in Oracle 8i and D2k as front end? I have simple dll's as well as ATL com dll. I want to use some functions of these dll on the data stored in oracle and get result in d2k. I also require to call these dll's before dtoring the data in oracle from the d2k. Actually my requirement is to put these dll's in middle of d2k front end and oracle database.

Thanks.
0
Comment
Question by:Narender
4 Comments
 
LVL 3

Accepted Solution

by:
p_yaroslav earned 50 total points
ID: 6964744
Hi!

The ORA_FFI interface allows you to call functions in Windows DLLs directly from PL/SQL.  This interface allows you to integrate platform-specific features into your applications.

Here example:
----------------------------------------------------
Suppose you want to create an interface to the C function  pow, which is found in the Microsoft Windows runtime  llibrary:  C:\windows\system\msvcrt.dll. (The pow function raises x to the y power.)

int pow(int x, int y)

First, create a package specification that represents the  library and defines the PL/SQL function that you want to invoke:

PACKAGE mathlib IS
   FUNCTION pow(x NUMBER, y NUMBER)
     RETURN NUMBER;
END;

You would call the PL/SQL function mathlib.pow, defined above, to invoke the foreign function pow, from the dynamic library msvcrt.dll.

Notice that this subprogram does not require a handle to the library or foreign function.  For convenience, the various registrations are handled in the package body, defined below.

Note: This example uses a PRAGMA compiler directive  to tell the PL/SQL compiler that the function ff_to_power is actually to be compiled as a C function, rather than PL/SQL. Ora_Ffi Example 1B shows how to achieve the same result using the Ora_Ffi.Generate_Foreign function to generate a PL/SQL mathlib package.  In Example 1B,  the PRAGMA directive is handled automatically by the Ora_Ffi.Generate_Foreign function.

PACKAGE BODY mathlib IS
  /* Declare the library and function handles. */
  mathlib_lhandle   Ora_Ffi.Libhandletype ;
  to_power_fhandle  Ora_Ffi.Funchandletype ;

  /* Create the PL/SQL function that will actually */
  /* invoke the foreign function.                  */
  FUNCTION ff_to_power(fhandle Ora_Ffi.Funchandletype,
         x NUMBER, y NUMBER)RETURN NUMBER;
  PRAGMA interface(C, ff_to_power, 11265);

  /* Create the PL/SQL function that is defined in */
  /* the package spec.  This function simply       */
  /* passes along the arguments it receives to     */
  /* ff_to_power (defined above), prepending the   */
  /* foreign function handle to the argument List. */
  FUNCTION pow(x NUMBER, y NUMBER) RETURN NUMBER IS
  BEGIN
    RETURN(ff_to_power(to_power_fhandle, x, y));
  END pow;

/* Define the body of package mathlib */
BEGIN  

  /* Load the library. */
  mathlib_lhandle := Ora_Ffi.Load_Library
         ('C:\WINDOWS\SYSTEM\', 'msvcrt.dll');

  /* Register the foreign function. */
  to_power_fhandle := Ora_Ffi.Register_Function
         (mathlib_lhandle, 'pow', Ora_Ffi.C_Std);

  /* Register both parameters of function to_power. */
  Ora_Ffi.Register_Parameter (to_power_fhandle,
                             Ora_Ffi.C_DOUBLE);
  Ora_Ffi.Register_Parameter(to_power_fhandle,
                             Ora_Ffi.C_DOUBLE);

  /* Register the return type. */
  Ora_Ffi.Register_Return (to_power_fhandle, Ora_Ffi.C_DOUBLE);

END;  /* Package Body Mathlib */


To invoke the C  function pow from mscvrt.dll, you simply call the PL/SQL  function pow, defined in the mathlib package specification.  For example:


PL/SQL>

PROCEDURE raise_to_power (a in number, b in number) IS
   BEGIN
      text_io.put_line(mathlib.pow(a,b));
   END;

PL/SQL> raise_to_power(2,9);

Best regards!
Yaroslav.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7078618
Greetings.

This question has been locked with a Proposed Answer, and remains open today.

If the Proposed Answer did not serve your needs, please reject it and comment with an update.  If the Proposed Answer helped you, please accept it to grade and close this question.  If you need help splitting points between multiple experts, please comment here with details so we can help you.

EXPERTS ->  Please guide me here in terms of closing recommendations if the Asker does not respond in 4 days.

Thanks to all,
Moondancer - EE Moderator
0
 

Expert Comment

by:modulo
ID: 7429532
Dear: p_yaroslav

I've rejected your proposed answer as Experts Exchange holds an experiment to work without the answer button.

See:        http://www.experts-exchange.com/jsp/communityNews.jsp
Paragraph: Site Update for Wednesday, November 06, 2002

By this rejection the Asker will be notified by mail and hopefully he will take his responsibility to finalize the question or post an additional comment.
The Asker sees a button beside every post which says "Accept This Comment As Answer" (including rejected answers) -- so if he/she thinks yours is the best, you'll be awarded the points and the grade.

Thanks !

modulo

Community Support Moderator
Experts Exchange
0
 
LVL 13

Expert Comment

by:anand_2000v
ID: 9203607
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
points to be given to p_yaroslav
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

anand_2000v
EE Cleanup Volunteer
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle 12c database link between pdb not working 20 118
Distinct values from all columns in a table?? PL SQL 4 49
PL/SQL Two changes 7 34
oracle forms question 22 40
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to recover a database from a user managed backup

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question