Subject Re: [firebird-support] UDF - reading BLOB length
Author Danie Van Eeden
Hi,

I might be way off here - but exposed / exposed functions need to be called
with the correct calling convention.

Double check if it should be cdelc vs stdcall
Also check that you declare your EXTERNAL declaration with the same calling
convention (in your case: specify cdelc in your external declaration)

First things I could think of.

Regards
Danie

On Tue, Jul 31, 2012 at 1:47 PM, Josef KokeŇ° <j.kokes@...>wrote:

> Hi!
>
> What could possibly be wrong with the following UDF?
>
> * Function *
>
> type
> TBlob = {packed} record
> GetSegment: TISC_BlobGetSegment;
> BlobHandle: PInt;
> SegmentCount: LongInt;
> MaxSegmentLength: LongInt;
> TotalSize: LongInt;
> PutSegment: TISC_BlobPutSegment;
> end;
> PBlob = ^TBlob;
>
> function BLOBLEN(Value: PBlob): Integer; cdecl;
> begin
> if Value = nil then
> Result := 0
> else
> Result := Value^.TotalSize;
> end;
>
> * Declaration *
>
> DECLARE EXTERNAL FUNCTION BLOBLEN
> BLOB
> RETURNS INTEGER
> ENTRY_POINT 'BLOBLEN' MODULE_NAME 'pwIBUDF';
>
> * Usage *
>
> SELECT BLOBLEN(someblobfield) FROM sometable
>
> I expect to get a list of lengths of a particular BLOB field in the
> table. In reality, I get an error on Firebird 1.5, 2.1 and 2.5. Error
> log of FB 2.5 says:
>
> The user defined function: BLOBLEN
> referencing entrypoint: BLOBLEN
> in module: pwIBUDF
> caused the fatal exception: Access violation.
> The code attempted to access a virtual
> address without privilege to do so.
> This exception will cause the Firebird server
> to terminate abnormally.
>
> Which seems rather strange, considering that Firebird was supposed to
> pass me a valid BLOB descriptor - and in fact, in a similar function
> (but one which returns BLOB contents as a string) apparently does.
>
> I'd welcome any pointers (no pun intended).
>
> Thanks,
>
> Josef
>
>
> ------------------------------------
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Yahoo! Groups Links
>
>
>
>


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