Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: PL/SQL: Calling external C-functions in DLLs with struct as parameters

Re: PL/SQL: Calling external C-functions in DLLs with struct as parameters

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 24 Nov 2001 09:29:34 -0800
Message-ID: <9toldu01gf7@drn.newsguy.com>


In article <acab6080.0111240300.1f8a2826_at_posting.google.com>, stefan.misch_at_gmx.de says...
>
>Hi all PL/SQL Gurus !
>
>Is it possible to call external functions in a DLL written in C
>which has pointers to C-structs as parameter? Can you point me to
>an example or extended documentation about this?
>
>I had a look at the Oracle doc's but found no examples about structs.
>There is someting mentioned like "INDICATOR [{STRUCT | TDO }]" but I
>couldn't figure out how this is related to a C-struct.
>
>The DLL I'm trying to use is part of a function library we use in our
>normal programming. Now somebody came up with the idea to incorporate
>this functionality into the database (Oracle8i 8.1.7.0.0 on W2K-SP2).
>This library is from an external vendor, so we have no access to the
>source code. However we could write a C-function wrapper DLL if this
>would be neccessary. I included an example of one of the structs
>(typVertrag) which is passed as second parameter to a function named
>"BerechneVertrag". Another problem is that some functions get a
>pointer to a function for debugging purposes. So I think I won't get
>arround writing this wrapper DLL....
>
>Any help is welcome
>Stefan.
>
>/* type definitions */
>typedef struct {
> long lDatum;
> double dRate1;
> double dRate2;
> double dRate3;
> double dRate4;
>} typRaten;
>
>
>typedef struct {
> long lDatum;
> double dZins;
>} typZins;
>
>
>typedef struct {
> char sVertragNr[8];
> double dBetragDM;
> double dBetragEUR;
> ...
> typRaten *Raten;
> typZins *Zins;
> ...
>} typVertrag;
>
>/* Function prototype, pointer to C-struct typVertrag is passed as 2.
>param */
>DllExport short BerechneVertrag(int, void*, int, DEBUG_FCT*);

You'll need to write a C wrapper to call those, You cannot pass C structs (especially POINTERS to C structs) back and forth between SQL and C.

The C wrapper would use simple scalar types that can easily be mapped to.

--
Thomas Kyte (tkyte@us.oracle.com)             http://asktom.oracle.com/ 
Expert one on one Oracle, programming techniques and solutions for Oracle.
http://www.amazon.com/exec/obidos/ASIN/1861004826/  
Opinions are mine and do not necessarily reflect those of Oracle Corp 
Received on Sat Nov 24 2001 - 11:29:34 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US