Subject Re: UDF does not work
Author Andrew Monteith
Hi

I use this calling method.

************* Test_udf.dpr **************


library Test_udf;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any
procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit
to
the BORLNDMM.DLL shared memory manager, which must be deployed
along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes,
Test_unit in 'Test_unit.pas';

{$R *.res}

exports
udf_Test;

begin
end.


*************** Test_unit; ********************8

unit Test_unit;

interface

function udf_Test( vMultiPack : PChar; vRes : PChar ): PChar; cdecl;
export;

implementation

uses
SysUtils, StrUtils, Classes;

//*****************************************************************//
//** **//
//** udf_Test **//
//** **//
//**SQL: declare external function udf_Test **//
//** cstring(255), cstring(255) **//
//** returns parameter 2 **//
//** entry_point 'udf_Test' module_name 'Test_udf'; **//
//** **//
//*****************************************************************//
function udf_Test( vMultiPack : PChar; vRes : PChar ): PChar; cdecl;
export;
var
lsResult : String;
begin
lsResult := '';
Result := vRes;

if vMultiPack = ('Y') then
lsResult := PChar('Ja')
else
lsResult := PChar('Nee');
StrPCopy( vRes, lsResult );
end;

End.

HTH

Andrew Monteith


--- In ib-support@yahoogroups.com, "supertokkie" <martinstuij@c...>
wrote:
> I have a function in an UDF.dll
>
> But it gives not the correct information. Could somebody tell me
what
> I'm doing wrong?
>
>
> library UDF;
>
> uses
> SysUtils,
> Classes,
> Proc in 'Proc.pas';
>
> {$R *.res}
>
> exports
> CONVERTMULTIPACK;
>
> begin
>
> end.
>
>
>
>
>
>
> unit Proc;
>
> interface
>
> function CONVERTMULTIPACK(var MultiPack: PChar): PChar; cdecl;
export;
>
> implementation
>
> uses SysUtils, ib_util;
>
> function CONVERTMULTIPACK(var MultiPack: PChar): PChar;
> var Test: PChar;
> begin
> Result := IB_UTIL_malloc(3);
> try
> if MultiPack = ('Y') then
> Result := PChar('Ja')
> else
> Result := PChar('Nee');
> except
> end;
> end;
>
>
> initialization
> IsMultiThread := True;
>
> end.
>
>
>
>
>
>
> DECLARE EXTERNAL FUNCTION FCONVERTMULTIPACK
> VARCHAR(1)
> RETURNS VARCHAR(3) FREE_IT
> ENTRY_POINT 'CONVERTMULTIPACK' MODULE_NAME 'UDF.dll'