Generates a package of PL/SQL code for all the functions defined in the specified library. You must first load the library, register all of the functions you want to invoke, and register their parameter and return values.
PROCEDURE Ora_Ffi.Generate_Foreign
(handle libHandleType);
PROCEDURE Ora_Ffi.Generate_Foreign
(handle libHandleType,
pkgname VARCHAR2);
Parameter | Description |
---|---|
handle | A library handle returned by Ora_Ffi.LoadLibrary or Ora_Ffi.Find_Library. |
pkgname |
The name of the package to be generated. If you do not specify a package name, the name of the library, prefixed with FFI_, is used. For example, if the library name is LIBTEST, the package name will be FFI_LIBTEST. |
Packages generated by the Ora_Ffi.Generate.Foreign function are created in your current name space and will appear under the Program Units node of the Procedure Builder Object Navigator. Once a package has been generated, you can copy it to the Program Units node of a PL/SQL Library or to the Stored Program Units node of a database, and you can export it to a text file using File > Export, just like any other new package or procedure that you have defined.
A PL/SQL package generated by the Ora_Ffi.Generate_Foreign function automatically includes the required PRAGMA compiler directives for each of the registered functions:
PRAGMA interface (C, func_name, 11265);
where func_name is the name of a registered foreign function from a dll library that has already been loaded. You can specify the name of the generated PL/SQL package, but within that package, each of the entry points will match the names of the foreign functions they map to.
/* Define components of package test */
PACKAGE test IS
...
END;
/*Define package body procedures */
PACKAGE BODY test IS
PRODEDURE register_libs IS
BEGIN
/* Load the test library */
testlib_lhandle := Ora_Ffi_.load_library
('c:/orawin95/oralibs/','testlib.dll')
END;
PROCEDURE define_c_funcs IS
getresult_fhandle Ora_Ffi.Funchandletype;
foo_handle Ora_Ffi.Funchandletype;
BEGIN
/* Register the info for function getresult */
getresult_fhandle := ora_ffi.register_function
(testlib_lhandle,'getresult');
...
/* Register the info for function foo */
foo_fhandle := ora_ffi.register_function
(testlib_lhandle,'foo');
...
/* Generate PL/SQL package containing all
functions defined in test library */
ora_ffi.generate_foreign
(testlib_lhandle, 'test_ffi_pkg');
...
END;
END;