Callbacks

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Callbacks

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:44 am

by The_Swami >> Fri, 5 Nov 1999 4:01:00 GMT

Hello,

I have been trying to do the callback thing using the API from an application wriiten in Pascal.

I don't want to write a DLL in C++ as I don't want the client to have to deploy DLL's along with the Exe (that starts to get messy), a single exe is the preferred option.

I have managed to reconstruct the function pointer for the DataHandlerCB as well as the DynamicDataHandlerStructure using records in Pascal.

I have managed also to do almost everything I need to do (incremental text searching retriving objects, running methods etc, etc). The only hurdle left is retrieving a string attribute that is of Maximum length (same problem occurs when running a method that returns a string).

In the header file jomstr.h there are two versions of an inline function called JADE_DEREF_STRING like so:

inline int
JADE_DEREF_STRING( const DynamicDataHandler *pDynaHandler, Character*& pData )
{
return pDynaHandler->callBack( JADE_DEREF_STRING_OP, pDynaHandler->pParam, (void**) &pData, 0 );
}

inline int
JADE_DEREF_STRING(DskParam* pParam, Character*& pData)
{
return pParam->body.dataHandler.callBack(JADE_DEREF_STRING_OP, pParam, (void**) &pData, 0);
}

Most of the paramGetString methods seem to be using the first version of this, which takes the dataHandler and not the DskParam, when dealing
with Jade Strings.

The question I have is regarding pDynaHandle->pParam fed into the callback method. I have treated this pParam is a pointer, in this case to a DskParam.

Is this DskParam set up for me by the param createJadeString API call I get out of jomutil.dll or do I have to set it up myself?

If I have to set it up myself what do I put in the header and the body
of it?

Any help would be greatly appreciated.

The Swami.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Callbacks

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:44 am

by Krull >> Sat, 6 Nov 1999 2:31:52 GMT

Yo Swami,
The question I have is regarding pDynaHandle->pParam fed into the callback method. I have treated this pParam is a pointer, in this case to a DskParam.

Is this DskParam set up for me by the param createJadeString API call I get out of jomutil.dll or do I have to set it up myself?

The pParam member of the DynamicDataHandler structure is a pointer to the DskParam containing the data handler. The first version of JADE_DEREF_STRING requires this to be setup; the second version does not because a pointer to the DskParam is passed as a parameter to the function instead. The data handler callback (pDynaHandler->callback) itself does not require the pParam member.

The paramCreateJadeString function exported by jomutil does set up pParam for you, along with creating a JadeString, assigning this to pItem and assigning a pointer to the jadeDataHandler callback to the callback member.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Callbacks

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:44 am

by The_Swami >> Sun, 7 Nov 1999 19:37:14 GMT

Krull,

OK I tried it and got an acess violation when using the callback. Here is the code though it's not particularly elegant.

function GetJadeString(TheObject:TDskObjectID;TheString:String):String; var
aInput : Array [0..255] of Char;
dskInput, dskReturn : TDskParam;
iError : Integer;
iLine : DWord;
pData : PChar;
iSize : DWord;begin

//initialise iSize at 0
iSize:=0;
//Copy the name of the string attribute into an array of Char StrPCopy(aInput,TheString);

//Set Up Input Parameter
dskInput.Header.Format:=DSKCSTRING; dskInput.Header.Usage:=USAGE_CONSTANT;
dskInput.Header.More:=0;
dskInput.Body.pText:=@aInput; //@ means address of in Pascal

//Create Jade String
paramCreateJadeString(@dskReturn,pData,0);

//Set Header output
dskReturn.Header.Usage:=USAGE_OUTPUT;

//Make API Call to get property iError:=jomGetProperty(nil,@TheObject,@DskInput,@DskReturn,iLine);

if iError<>0 then
begin
raise EJadeException.Create('Jade error '+IntToStr(iError)+' has occurred during GetAtKeyGeq. Line No '+IntToStr(iLine));
end else
begin
if dskReturn.Header.Format=DSKJADESTRING then
begin
//invoke callBack PPointer is a pointer to an untyped pointer
//which should be equivelant to (void**)
dskReturn.Body.DataHandler.callBack(JADE_DEREF_STRING_OP,@dskReturn,PPointer(@pData),iSize);
Result:=String(pData);
end else
begin
Result:=String(dskReturn.Body.pText);
end;
end;
paramDeleteJadeString(@dskReturn);
end;

The TDskObjectID and TDskParams are the same as the DskObjectID and DskParams I Found in the JomTypes.h file. I have managed to translate the whole thing into Pascal and it seems to work (except for this).

If you can spot anything I've oviously done wrong (theres bound to be something) please let me know.

The Swami.

Krull wrote:
Yo Swami,
The question I have is regarding pDynaHandle->pParam fed into the callback method. I have treated this pParam is a pointer, in this case to a DskParam.

Is this DskParam set up for me by the param createJadeString API call I get out of jomutil.dll or do I have to set it up myself?

The pParam member of the DynamicDataHandler structure is a pointer to the DskParam containing the data handler. The first version of JADE_DEREF_STRING requires this to be setup; the second version does not because a pointer to the DskParam is passed as a parameter to the function instead. The data handler callback (pDynaHandler->callback) itself does not require the pParam member.

The paramCreateJadeString function exported by jomutil does set up pParam for you, along with creating a JadeString, assigning this to pItem and assigning a pointer to the jadeDataHandler callback to the callback member.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Callbacks

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:44 am

by The_Swami >> Mon, 8 Nov 1999 22:28:46 GMT

Nominate me for the moron of the week award.

Originaly I translated the DskDynamicDataHandler like so

DynamicDataHandler = packed record
callBack : function(Operation:Byte;pParam:Pointer;pDate:PPointer;pLength:DWord):Integer; pItem : Pointer;
pParam : PDskParam;
end;

However the call back is assigned by the createJadeString call and the function pointer is assigned by this call to point at a function in another DLL. This means it needs to be called using the standard calling convention.

I should have translated the structure as:

DynamicDataHandler = packed record
callBack : function(Operation:Byte;pParam:Pointer;pDate:PPointer;pLength:DWord):Integer; stdcall;
pItem : Pointer;
pParam : PDskParam;
end;

Once I put the calling convention in the code in my previous posting worked fine.

The Swami.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Callbacks

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:44 am

by Krull >> Mon, 8 Nov 1999 22:54:41 GMT
Nominate me for the moron of the week award.

On the contrary, you have done very well to get this stuff working from Delphi; the missing stdcall qualifier was a minor oversight. Well done!!


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 23 guests

cron