Subject Re: [IBDI] UDF Questions
Author Robert F. Tulloch
Hi:

Still in need of a little information here.

The dll function works when called from test program. In IB, SELECT * FROM CLEARLOG
returns NULL and
does not clear the interebase.log file. The dll is in Interbase/UDF as it should be.
The declare external prepares fine indicating it recognizes the dll and the exported
function.

Don't know what IB is expecting but I assume it is the SP failing. Any thoughts
appreciated.

Best
regards

--------------------------------------------------------------------------
/* External Function declarations */

DECLARE EXTERNAL FUNCTION CLEARIBLOG
RETURNS CSTRING(80) CHARACTER SET NONE FREE_IT
ENTRY_POINT 'fn_ClearIbLog' MODULE_NAME 'ltudf';

---------------------------------------------------------------------------

set term ## ;
create procedure ClearLog
Returns(Result varchar(80))
as
begin
Result = ClearIBLog();
exit;
end ##
set term ; ##

----------------------------------------------------------------------------
.dll header

extern "C" __declspec(dllexport) char* __stdcall fn_ClearIbLog();

----------------------------------------------------------------------------
.dll cpp
//---------------------------------------------------------------------------
char *buf;
char* __stdcall fn_ClearIbLog()
{
char *s;
TStringList *IBLog = new TStringList();
try
{
IBLog->LoadFromFile("..\\interbase.log");
IBLog->Clear();
IBLog->Add(" ");
String NewHeader = "LTDMS Interbase.Log cleared on " + DateToStr(Date());
IBLog->Add(NewHeader);
IBLog->Add("------------------------------------------------------------");
IBLog->SaveToFile("..\\interbase.log");
delete IBLog;
s = "True";
}
catch(...)
{
delete IBLog;
s = "False";
}
char *p;
buf = (char*)malloc(strlen (s) + 1);
p = buf;
while (*s)
*p++ = *s++;
*p = '\0';

return buf;
}