Callbacks from API

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

Callbacks from API

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

by Torrie Moore >> Thu, 28 Oct 1999 4:28:19 GMT

Hello All

I have a method on one if the classes called displayString as follows:

displayString(): String;
vars
begin

return surname&', '&givenName;
end;

The problem is that when I call this method through the jomSendMsg API call it doesn't seem to work. I have figured out that it is because of the length of the string not being defined in advance.

I have also worked out that the return parameter needs to be a Dynamic Data Handler.

My Question is regarding the CallBack Procedure. I have found the line in the jomtypes.h file which defines it i.e.

typedef int ( JOMAPI* DaterHandlerCB )
(BYTE operation,DskParam* pParam,void** pData, Size* pLength);

In Pascal this is equivelent to:
function dataHandlerCB(Operation:Byte;pVoid:^DskParam;pData:^Pointer;
Size:^Integer):Integer; stdcall; forward;

My questions is as what can each of these parameters contain and under what circumstances would they contain these values? In other words what does the function have to do with these parameters in order to get the string returned by my Jade method?

I have searched through all the code examples I could find and come up with nothing that demonstrates the use of this. Does anyone have an example of this or know where there is one?

Thanks a lot,

Torrie

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

Re: Callbacks from API

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

by Krull >> Thu, 28 Oct 1999 5:33:42 GMT

Hi Torrie,

You are correct in assuming that you either need to know the length of the return string in advance or that you need to use some form of dynamic data structure. The simplest way to do this is to use a JadeString. You have obviously come across some of the type definitions in jomtypes.h relating to the callbacks used by the JadeString implementation, but it would be easier for you if you didn't try to implement the data handler since we don't publish this interface.

It sounds like you are trying to do this from Pascal (Delphi perhaps?); if you can call the paramCreateJadeString function defined in jomParam.hpp, then you can use the supplied JadeString implementation provided in the jomutil.dll library.

Below is sample C++ code fragment that shows how to use paramCreateJadeString to create a JadeString which will receive the string return value from a JADE method.


Character *pBuff;
DskParam returnParam;

// We don't really know the exact size of the string returned by the
// hello method so we will create a JADE string to receive the return result.
// JADE strings provide their own storage management and dynamically
// resize themselves as required
paramCreateJadeString(&returnParam, TEXT(""), 0);
returnParam.header.usage = USAGE_OUTPUT;

paramGetString(returnParam, pBuff);

// call displayString signature: displayString() : String;
// the obj proxy is assumed to be initialised with a valid object reference
obj.sendMsg(TEXT("displayString"), 0, &returnParam, __LINE__);
// dereference return parameter
paramGetString(returnParam, pBuff);

// do something with pBuff

// we must ensure that we delete the JADE string when finished with it to return space to the string pool
paramDeleteJadeString(&returnParam);




Hope this helps

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

Re: Callbacks from API

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

by Krull >> Thu, 28 Oct 1999 5:38:49 GMT

I should mention that some of the types and macros used in my sample code fragment such as the Character type and the TEXT macro are defined in the c header files that we ship with JADE.

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

Re: Callbacks from API

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

by Krull >> Sun, 31 Oct 1999 22:07:11 GMT

Torrie,

Further to my previous posting.

If you opt to call the paramCreateJadeString and paramDeleteJadeString functions exported by jomutil.dll from Pascal you will no doubt encounter an issue with C++ name mangling. You need to actually call the mangled names, which you can find by using quick view on jomutil.dll.

You have no doubt discovered that the function paramGetString used in my C++ sample to dereference the internal string is an inline function so you cannot use this directly from Pascal. Two options you could try are:
a) Provide your own C++ wrapper equivalent to paramGetString with a stdcall calling convention extern "C" function in a DLL that you can call directly from Pascal. If you take this approach you could also provide similar wrappers for the paramCreateJadeString and paramDeleteJadeString functions thus mitigating the name mangling issue.

b) You can emulate the paramGetString function in Pascal by referring to the inline implementaion in jomparam.hpp and the implementation of JADE_DEREF_STRING in jomstr.h; this requires calling the data handler callback you mentioned in your initial posting. The jomstr.h header file shows the required defines for the operation parameter and the usage of the other parameters to this callback.

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

Re: Callbacks from API

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

by Carl Ranson >> Tue, 2 Nov 1999 0:05:54 GMT

Does anyone have an example of a Delphi/Pascal dll that implements a simple Jade Method?

It would be quite a lot better implementing a dll in Delphi rather than endure C++, in my humble opinion.

Thanks,

CR

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

Re: Callbacks from API

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

by Wilfred Verkley >> Tue, 2 Nov 1999 1:49:14 GMT

I converted all the headers a while back, but I didnt get much further then this:

library DemoDll2;

uses
windows, classes,
jomTypNo, jomTypes, jomCalls, jomDefs;

function demoShowMsg (buffer : PDskBuffer; DskParam : PDskParam; pReturn : PDskParam) : Integer; stdCall;
begin
Windows.MessageBox (0, 'Hello, world!', 'Information', IDOK);
result := 0;
end;

exports
demoShowMsg;
end.

Did anyone get the VCL working properly from an external method call?


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 12 guests