Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Formbuilder call VC++ function ? 1

Status
Not open for further replies.

ora06

Programmer
Feb 11, 2004
15
FR
I am Using FormBuilder 6.0 to manipulate database Oracle
I want to call some functions,procedures written in visual C++6.0 and then pass
some parametters to insert , update into database

First , i run in Client/Server mode
My hardware is not good enough for Web running , but i can try in school

With FormBuilder i can manipulate data
And i develloped some VC++ function checking data before insert , update.
So i want to call them from Formbuilder in runtime

Help me how to handle it ?
Thanks in advance
 
Use ORA_FFI package. Heres an example of code I wrote for a form. The prototype of the function call in the dll is

[tt]int splitstr (char *str, int len, int bold, int start);[/tt]

This returns a number and modifies the string passed in, hence the first parameter is a char pointer.

The first function loads the DLL into the form workspace.

Code:
FUNCTION Fn_Load_Function (p_func_name IN VARCHAR2)
RETURN ORA_FFI.FuncHandleType IS
  l_lib  ORA_FFI.LibHandleType;
  l_func ORA_FFI.FuncHandleType;
BEGIN
  BEGIN
    l_lib := ORA_FFI.Find_Library('MYDLL.dll');
  EXCEPTION
    WHEN OTHERS
    THEN
      l_lib := ORA_FFI.Load_Library('.\','MYDLL.dll');
  END;
--
  l_func := ORA_FFI.Register_Function(l_lib,p_func_name,ORA_FFI.C_STD);
--
  Return l_func;
EXCEPTION
  WHEN OTHERS
  THEN
    FOR c IN 1..Tool_Err.NErrors
    LOOP
      Message(Tool_Err.Message); 
      Tool_Err.Pop; 
    END LOOP;
END Fn_Load_Function;

And now the form function to actually make the call to the DLL.

Code:
FUNCTION Fn_Split (p_text  IN OUT VARCHAR2,
                   p_wid   IN     BINARY_INTEGER,
                   p_att   IN     VARCHAR2,
                   p_start IN     BINARY_INTEGER)
RETURN NUMBER IS
  l_fn   ORA_FFI.FuncHandleType;
--
  FUNCTION dll_split(pFh  IN     ORA_FFI.funcHandleType,
                     str  IN OUT VARCHAR2,
                     wid  IN     BINARY_INTEGER,
                     bld  IN     BINARY_INTEGER,
                     strt IN     BINARY_INTEGER)
  RETURN pls_integer; 
--
  PRAGMA interface( c, dll_split, 11265);
BEGIN
  IF  p_text IS NULL
  THEN
    Return NULL;
  END IF;
--
  l_fn := Fn_Load_Function('splitstr');
--
  ORA_FFI.register_parameter(l_fn,ORA_FFI.C_CHAR_PTR );
  ORA_FFI.register_parameter(l_fn,ORA_FFI.C_INT );
  ORA_FFI.register_parameter(l_fn,ORA_FFI.C_INT );
  ORA_FFI.register_parameter(l_fn,ORA_FFI.C_INT );
  ORA_FFI.register_return(l_fn,ORA_FFI.C_INT );
--
  Return dll_split(l_fn,p_text,p_wid,p_att,p_start);
END Fn_Split;

If you have a function in your library that returns nothing, you do not need to register a return value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top