Subject UDF, how to get i right...
Author Henrik Sitter
Hi, I've written a function in c(++) that converts hexadecimal numbers
to ordinary numbers. It compiles (MSVC 6.0) as a DLL and I'm pretty sure
the function works as it should. It's comipled with the setting "Debug
Multithreaded". The c looks something like this:

hexUDF.h :
#include <cmath>
#include <string>
#include <sstream>
#include <ib_util.h>
#define FUNC_EXPORT __declspec(dllexport)

hexUDF.cpp :
#include "hexUDF.h"

extern "C" FUNC_EXPORT double __stdcall hexUDF_hexToDec(const char*
hexvalue)
{
double decvalue = 0;
.
.
return decvalue;
}

hexUDF.def :
IBRARY hexUDF
DESCRIPTION 'hexUDF.dll'
EXPORTS
hexUDF_hexToDec


This all compiles fine. I then copy hexUDF.dll to .\firebird\udf. I also
made a hexUDF.sql file:

/* convert from hex to decimal */

declare external function hexToDec
varchar(256) by descriptor
returns double precision by value
entry_point 'hexUDF_hexToDec' module_name 'hexUDF';


Then it's time to run ISQL and execute hexUDF.sql against my database:

connect "c:\firebird 1.5\test\test.fdb" USER 'sys' PASSWORD 'pwd';
in "c:\firebird 1.5\udf\hexUDF.sql";

This also seems to perform as expected. When I now start Database
Workbench I can see my UDF showing up nicely in the UDF "folder".

I then write a test stored procedure with the DLL looking something
like:


CREATE PROCEDURE P_TEST_HEXTODEC (
IN_HEXVALUE VarChar(100))
returns (
OUT_DECVALUE Double Precision)
AS
begin
OUT_DECVALUE = HEXTODEC(IN_HEXVALUE);
end


This also "compiles". The only thing left is to call this stored
procedure from my application. This is where I get the error:

*** An exception occurred:
*** Type: com.sun.star.sdbc.SQLException
*** Message: GDS Exception. Error reading data from the connection.

The next thing which happens is the server is closing down. I called the
stored procedure from my application like I call all my other stored
procedures, so I don't think this is the problem.

Does anyone have any ideas?

Henrik




[Non-text portions of this message have been removed]