Subject | IB and UDF |
---|---|
Author | Robert F. Tulloch |
Post date | 2001-01-05T04:51:29Z |
Hi:
Trying to call UDF in dll to clear IB log since I can't find anywhere to do it, not
in console nor in IBX components nor
anywhere in IB Docs I have seen. The dll works fine ut can't seem to get it to work
through IB. I can do this with a
shared dir and regular coding but I would really like to execute on server through tcp
call to IB. Anyway, a little help
with the IB error message would be appreciated.
Thanks.
Best regards
My call to an SP
select * from CLEARLOG('F:\\PROGRAM FILES\\INTERBASE CORP\\INTERBASE\\interbase.log');
The SP:
set term ## ;
create procedure ClearLog(Path varchar(64))
Returns(Result char(1))
as
begin <--Few extra begins, hah!
begin
Result = ClearIBLog(Path);
end
end ##
set term ; ##
The Delare External::
DECLARE EXTERNAL FUNCTION CLEARIBLOG
VARCHAR(64) CHARACTER SET NONE
RETURNS CHAR(1) CHARACTER SET NONE FREE_IT
ENTRY_POINT '_ClearIbLog' MODULE_NAME 'ltudf';
And the dll in the Interbase/UDF directory:
char ClearIbLog(char *Path)
{
String Result;
TStringList *IBLog = new TStringList();
try
{
IBLog->LoadFromFile(Path);
IBLog->Clear();
IBLog->Add(" ");
IBLog->SaveToFile(Path);
delete IBLog;
Result = "T";
}
catch(...)
{
delete IBLog;
Result = "F";
}
return *Result.c_str();
}
Results in:
Arithmetic exception, numeric overflow, or string truncation
Statement: select * from CLEARLOG('F:\\PROGRAM FILES\\INTERBASE
CORP\\INTERBASE\\interbase.log')
However, the following works fine and clears the log:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UDFTest.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
typedef char (__stdcall *pClearIbLog)(char*);
pClearIbLog fClearIbLog;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LoadDLLBtnClick(TObject *Sender)
{
// Attempt to load ltudf.dll. If this fails then raise an exception.
LibHandle = (int) LoadLibrary("F:\\Program Files\\InterBase
Corp\\InterBase\\UDF\\ltudf.dll");
if( LibHandle < 32 )
{
ShowMessage("Load dll Failed");
return;
}
ShowMessage("Load dll succeded");
fClearIbLog = (pClearIbLog)GetProcAddress((HINSTANCE)LibHandle, "_ClearIbLog");
if( !fClearIbLog)
{
ShowMessage("Failed to get process address");
return;
}
ShowMessage("Got Process Address");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CallBtnClick(TObject *Sender)
{
Edit1->Text = fClearIbLog("F:\\Program Files\\InterBase
Corp\\InterBase\\interbase.log");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
if( LibHandle >= 32 )
FreeLibrary((HINSTANCE)LibHandle);
}
//---------------------------------------------------------------------------
Trying to call UDF in dll to clear IB log since I can't find anywhere to do it, not
in console nor in IBX components nor
anywhere in IB Docs I have seen. The dll works fine ut can't seem to get it to work
through IB. I can do this with a
shared dir and regular coding but I would really like to execute on server through tcp
call to IB. Anyway, a little help
with the IB error message would be appreciated.
Thanks.
Best regards
My call to an SP
select * from CLEARLOG('F:\\PROGRAM FILES\\INTERBASE CORP\\INTERBASE\\interbase.log');
The SP:
set term ## ;
create procedure ClearLog(Path varchar(64))
Returns(Result char(1))
as
begin <--Few extra begins, hah!
begin
Result = ClearIBLog(Path);
end
end ##
set term ; ##
The Delare External::
DECLARE EXTERNAL FUNCTION CLEARIBLOG
VARCHAR(64) CHARACTER SET NONE
RETURNS CHAR(1) CHARACTER SET NONE FREE_IT
ENTRY_POINT '_ClearIbLog' MODULE_NAME 'ltudf';
And the dll in the Interbase/UDF directory:
char ClearIbLog(char *Path)
{
String Result;
TStringList *IBLog = new TStringList();
try
{
IBLog->LoadFromFile(Path);
IBLog->Clear();
IBLog->Add(" ");
IBLog->SaveToFile(Path);
delete IBLog;
Result = "T";
}
catch(...)
{
delete IBLog;
Result = "F";
}
return *Result.c_str();
}
Results in:
Arithmetic exception, numeric overflow, or string truncation
Statement: select * from CLEARLOG('F:\\PROGRAM FILES\\INTERBASE
CORP\\INTERBASE\\interbase.log')
However, the following works fine and clears the log:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UDFTest.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
typedef char (__stdcall *pClearIbLog)(char*);
pClearIbLog fClearIbLog;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LoadDLLBtnClick(TObject *Sender)
{
// Attempt to load ltudf.dll. If this fails then raise an exception.
LibHandle = (int) LoadLibrary("F:\\Program Files\\InterBase
Corp\\InterBase\\UDF\\ltudf.dll");
if( LibHandle < 32 )
{
ShowMessage("Load dll Failed");
return;
}
ShowMessage("Load dll succeded");
fClearIbLog = (pClearIbLog)GetProcAddress((HINSTANCE)LibHandle, "_ClearIbLog");
if( !fClearIbLog)
{
ShowMessage("Failed to get process address");
return;
}
ShowMessage("Got Process Address");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CallBtnClick(TObject *Sender)
{
Edit1->Text = fClearIbLog("F:\\Program Files\\InterBase
Corp\\InterBase\\interbase.log");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
if( LibHandle >= 32 )
FreeLibrary((HINSTANCE)LibHandle);
}
//---------------------------------------------------------------------------