Solved

using DLL in D2k

Posted on 2002-04-23
4
1,112 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many‚Ķ
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to take different types of Oracle backups using RMAN.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now