Re: C++. Oracle & DLL

From: mark tomlinson <marktoml_at_gdi.net>
Date: Wed, 20 May 1998 14:30:46 GMT
Message-ID: <3569e869.159622474_at_newshost.us.oracle.com>


Here is an example, remember that the interface to FORMS must be 'C' calling convention - so if you write this in C++, rememeber to define the interface functions as 'C' :

  • ********************************************************* --
  • This would be the calling trigger's code --
  • ********************************************************* --

declare

  • Parameters parm1 VARCHAR2(200) := 'Something';
  • Return value rt PLS_INTEGER; begin rt := MyLib.MyFunc1( parm1 ); end;
    • ********************************************************* --
    • This would be the wrapper package header code --
    • ********************************************************* --

PACKAGE MYLIB IS
    FUNCTION MyFunc1( parm1 IN OUT VARCHAR2 )

                    RETURN PLS_INTEGER;  
END;
  • ********************************************************* --
  • This would be the wrapper package body code --
  • ********************************************************* --

PACKAGE BODY MYLIB IS
  lib_hndl ora_ffi.libHandleType;
  func_hndl ora_ffi.funcHandleType;   

  • Note that we always pass a function handle in as the first parameter FUNCTION i_MyFunc1( func_hndl IN ora_ffi.funcHandleType, parm1 IN OUT VARCHAR2 ) RETURN PLS_INTEGER;
  • This pragma is identical (except the function name) for all ORA_FFI functions PRAGMA INTERFACE(C,i_MyFunc1,11265);

  FUNCTION MyFunc1( parm1 IN OUT VARCHAR2 )

                    RETURN PLS_INTEGER   
  IS   
    rc       PLS_INTEGER;  

  BEGIN
  • Note that the function handle is the first parameter in the call rc := i_MyFunc1(func_hndl, parm1); RETURN (rc); END ;
BEGIN
  • Load the library ... like WinAPI LoadLibrary()
  • change the name and path to match yours... lib_hndl := ora_ffi.load_library(NULL,'D:\TESTCASE\MYDLL\DEBUG\MYDLL.DLL');
  • Register the target function ... like WinAPI GetProcAddress()
  • Note: The function name (eg. mytest) IS case sensitve in Win32 func_hndl := ora_ffi.register_function(lib_hndl,'mytest',ora_ffi.C_STD);
  • Denote the parameter list ora_ffi.register_parameter(func_hndl,ORA_FFI.C_CHAR_PTR);
  • Denote the return value ora_ffi.register_return(func_hndl,ORA_FFI.C_INT); END;
    • ********************************************************* --
    • This would be the C++ code for the Win32 DLL --
    • ********************************************************* --

/*

        MYDLL.CPP
*/

#include <windows.h>

extern "C"
{
int _declspec(dllexport) mytest(char* p_string); }

BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{

        if ( ul_reason_for_call == DLL_PROCESS_ATTACH )
                MessageBox(NULL,"Hello","Startup",MB_OK);

        return 1;

}

int _declspec(dllexport) mytest(char* p_string) {

                MessageBox(NULL,p_string,"Function",MB_OK);

        return 0;

} Received on Wed May 20 1998 - 16:30:46 CEST

Original text of this message