Topic
  • No replies
jprof
jprof
14 Posts

Pinned topic Functions calling DLLs

‏2013-02-27T17:28:21Z |
Hello All,

This might not be the best place to ask the question, but here goes:

I've written a function in Delphi (2010) to get a Hash value that I need to pass back to DB2. Here's the prototype in the DLL:

function GetCheckSumValue(iInput_Text: PSQLLob; iSelective_Uppercase, iDebug, oResult: PAnsiChar): PAnsiChar; export; stdcall;

Note: The PSQLLob type is defined as follows (this is the Delphi equivalent of a CLOB, and works very well):

type
TSQLLob = record
Length: cardinal;
Data: array http://0 .. 0 of AnsiChar;
end;

PSQLLob = ^TSQLLob;

However, the problem is that no matter what I try, I can't get DB2 to read the result of the called function. I end up having to set the oResult value instead, and define an OUT parameter in DB2 to get the value:

CREATE OR REPLACE FUNCTION TM_GET_CHECKSUM_DLL(
IN iINPUT_TEXT CLOB(128k),
IN iSELECTIVE_UPPERCASE VARCHAR(5),
IN iDEBUG VARCHAR(5),
OUT oRESULT VARCHAR(50)
)
RETURNS VARCHAR(50)
SPECIFIC FN_TM_GET_CHECKSUM_DLL
EXTERNAL NAME 'CheckSumDLL!TMGetCheckSumValue'
LANGUAGE C PARAMETER STYLE SQL
NOT DETERMINISTIC
NO SQL
EXTERNAL ACTION
NO SCRATCHPAD NO FINAL CALL
ALLOW PARALLEL
NO DBINFO
@

I'd really like DB2 to understand that the called function returns a pointer. Instead, when I call this function in a SQL statement, it always returns NULL. I have to have a subsequent function that looks at the output parameter in order for me to use the value in a SQL statement.

Here are the lines of code that set the oResult value and the Result value:

StrCopy(oResult, PAnsiChar(HashValue));
Result := PAnsiChar(HashValue);

If I try StrCopy for Result, I get an access violation. If I try changing the return type to string, or AnsiChar, I still get nothing.

Hopefully this makes sense. Its been a frustrating exercise to try and get this to work. I have my workaround, but its not pretty, and I'd like to understand what I'm doing wrong.

Thanks

James