Re: Reference variables in jawin?

Morten Andersen <[email protected]>
Newsgroups gmane.comp.windows.devel.jawin
Organization Arosii Information Systems A/S
Message-ID <[email protected]>
Hi Jonas

Jonas Lindén wrote:
>>>
>>>This is how the C++ code looks like:
>>>int cbAIn( int BoardNum, int Channel, int Range, unsigned short
>>>*DataValue );
>>>
>>
>>Is the "DataValue" parameter used for returning a short value? Or is it
>>used for inputting a short array? So is it used as an [in] parameter or
>>an [out] parameter.
>>
>
>
> The DataValue is used for returning a variable of type short.

Then I think something along the lines with this should do it:

   FuncPtr fp = new FuncPtr("cbw32.DLL", "cbAInScan");
   NakedByteStream nbs = new NakedByteStream();
   LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
   leos.writeInt(boardNum);
   leos.writeInt(channel);
   leos.writeInt(range);

   // call the function with three ints and 4 bytes allocated for
   // the datavalue - see explanation of the instructionstring below
   byte[] result = fp.invoke("IIIA:I:L4L4L4n4", 16, nbs, null,
     ReturnFlags.CHECK_NONE);

   LittleEndianInputStream leis = new LittleEndianInputStream(
     new ByteArrayInputStream(result));

   // return val
   int retVal = leis.readInt();

   // and datavalue - should perhaps not be casted to a short? - since
   // unsigned short in native code?
   short dataValue = (short)leis.readInt();


The instruction string "IIIA:I:L4L4L4n4" should be interpreted like this
(on the form XXX:Y:ZZZ , where XXX is directions for [in], Y is the
[retval] and ZZZ is [out]-directions) :
- I: in integer (or other 4 byte value).
- A: skip in instream and allocate 4 bytes on stack (yes, I know a short
is only 2 bytes, but on the stack the calling convention __stdcall works
in chunks of 4 bytes, so smaller parameters takes up 4 bytes).
- L4: on the output = skip 4 bytes (we do this for all the [in]-parameters).
- n4: read 4 bytes of the stack and return.

I know this code is not for the faint at heart, and over time the Jawin
Type Browser should hopefully be able to generate it for DLL's too.

I am working on documenting the instruction strings too (pt. there is
only this outdated documentation for this:
http://jawinproject.sourceforge.net/instruction_docs.html ).

Please note that I tested this code on the CVS HEAD version of Jawin,
and there have been significant cleaning of the API for calling
DLL-entry points since the last released version. So maybe this code
does not work in the released version, if that is the case I urge you to
check out the CVS version and build it yourself (please see:
http://jawinproject.sourceforge.net/jawindeveloper.html ).

In the CVS-HEAD I also started out on some detailed information about
calling DLL-entry points (see docs/jawinuserguide_dll.html in the
checked out source), although it is not complete on some of the finer
issues (as this is).

Hope this helps you, and feel welcome to email again if you still have
issues with this.

Best Regards
Morten
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.