Re: Reference variables in jawin?
Roger I Martin PhD <[email protected]>
| Newsgroups | gmane.comp.windows.devel.jawin |
|---|---|
| Message-ID | <[email protected]> |
Hi Morten, Do you think that generating for dll's from header files would be a good next implementation that I could do next? I was looking at it this weekend because I had started on it before. I was trying to see what was the best way to go about it. Tried Chaperon and couldn't get it to work. Looked at JFlex but don't see how to generate xml with it. Tempted to simply write code that parses a header file and outputs xml description similar to what was done for type libs. What do you or anybody think? --Roger ----- Original Message ----- From: "Morten Andersen" <[email protected]> To: <[email protected]> Sent: Monday, June 21, 2004 9:27 AM Subject: Re: [JAWIN] Reference variables in jawin? > 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