Re: Argument string structure size mismatch

Alex Kotchnev <[email protected]>
Newsgroups gmane.comp.windows.devel.jawin
Message-ID <OF61259126.B4207979-ON85256EF0.0015C7EF-85256EF0.001638BC@divintech.com>
Here is something that I missed in the initial post ( setting some of the
properties of the structure ):

>>> from org.jawin import *
>>> from org.jawin.io import *
>>> from org.jawin.marshal import *
>>> from com.divintech.testing import *
>>> import java

>>> printDlg = FuncPtr("comdlg32.dll","PrintDlgW")
>>> nbs = NakedByteStream()
>>> leos = LittleEndianOutputStream(nbs)
>>> pd = PRINTDLG()

--- This is the part that I forgot in the original post...  ---------

>>> pd.lStructSize = pd.
>>> pd.nCopies = 1
>>> pd.nFromPage = 0xFFF
>>> pd.nToPage = 0xFFFF
>>> pd.nMinPage = 1
>>> pd.nMaxPage = 0xFFFF
 ---------------------------------
>>> pd.lStructSize = pd.size
>>> pd.size
66
>>> instructions = "P66:B1:n66"
>>> pd.marshal(leos)

and so on...



Regards,

Alex Kotchnev
Developer / Systems Analyst
Diversified Information Technologies

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CONFIDENTIALITY NOTICE: If you have received this e-mail in error, please
immediately notify the sender by e-mail at the address shown.  This e-mail
transmission may contain confidential information.  This information is
intended only for the use of the individual(s) or entity to whom it is
intended even if addressed incorrectly.  Please delete it from your files
if you are not the intended recipient.  Thank you for your compliance.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



Alex Kotchnev/divintech
08/13/2004 11:42 PM

To
[email protected]
cc

Subject
Argument string structure size mismatch





I am trying to go over some basic win32 functions to get a better handle
on working with Jawin. Below is the code, it mostly speaks for itself.
Basically, the problem is that when I invoke the function with the
"P66:B1:n66" instruction string as I would expect it to be, it doesn't
work and the error is " passed end of stream in the marshalling layer". I
figured that something was not right with the P66 part of the instruction
string, and I started lowering it. Finally, the function works at
"P60:B1:n60".  I must be wrong somewhere, probably when calculating the
size of the struct. However, I even compared the sizes of the Java members
by looking at the Visual J++ class corresponding to the PRINTDLG structure
(and they are all the same as in my class). What am I calculating wrong ?

Thanks in advance for the help.

This is my test code in Jython, but it is pretty readable, so I wouldn't
convert it to Java:

>>> from org.jawin import *
>>> from org.jawin.io import *
>>> from org.jawin.marshal import *
>>> from com.divintech.testing import *
>>> import java

>>> printDlg = FuncPtr("comdlg32.dll","PrintDlgW")
>>> nbs = NakedByteStream()
>>> leos = LittleEndianOutputStream(nbs)
>>> pd = PRINTDLG()
>>> pd.lStructSize = pd.size
>>> pd.size
66
>>> instructions = "P66:B1:n66"
>>> pd.marshal(leos)

Now, the error, when I run when I run it:
>>> printDlg.invoke(instructions,4,nbs,None,ReturnFlags.CHECK_FALSE)
Traceback (innermost last):
  File "<console>", line 1, in ?
org.jawin.COMException: 8000ffff: passed end of stream in the marshalling
layer
        at org.jawin.marshal.GenericStub.win32Invoke0(Native Method)
        at org.jawin.marshal.GenericStub.win32Invoke(GenericStub.java:152)
        at org.jawin.FuncPtr.invoke(FuncPtr.java:186)
        at org.jawin.FuncPtr.invoke(FuncPtr.java:205)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)....
------------ jython errors snipped -------------------
org.jawin.COMException: org.jawin.COMException: 8000ffff: passed end of
stream in the marshalling layer


And now the good news, when I run : I get the Print dialog and when it
retuns I get a byte array.

>>> printDlg.invoke("P60:B1:n60",4,nbs,None,ReturnFlags.CHECK_FALSE)
array([1, 66, 0, 0, 0, 0, 0, 0, 0, 100, 0, 115, 0, 108, 0, 115, 0, 0, 0,
0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 1, 0, -1, -1
 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0], byte)


The equivalent of the PRINTDLG struct is:
/*
 * PRINTDLG.java
 *
 * Created on August 13, 2004, 7:47 PM
 *
 *
 *
 *
 *
 *
 *
typedef struct tagPD {
    DWORD lStructSize;
    HWND hwndOwner;
    HGLOBAL hDevMode;
    HGLOBAL hDevNames;
    HDC hDC;
    DWORD Flags;
    WORD nFromPage;
    WORD nToPage;
    WORD nMinPage;
    WORD nMaxPage;
    WORD nCopies;
    HINSTANCE hInstance;
    LPARAM lCustData;
    LPPRINTHOOKPROC lpfnPrintHook;
    LPSETUPHOOKPROC lpfnSetupHook;
    LPCTSTR lpPrintTemplateName;
    LPCTSTR lpSetupTemplateName;
    HGLOBAL hPrintTemplate;
    HGLOBAL hSetupTemplate;
} PRINTDLG, *LPPRINTDLG;
 */

package com.divintech.testing;


import org.jawin.io.LittleEndianInputStream;
import org.jawin.io.LittleEndianOutputStream;
import org.jawin.marshal.GenericStub;
import java.util.ArrayList;
import java.io.IOException;

/**
 *
 * @author  alexandrek
 */
public class PRINTDLG {
   // This comes to 66: 6 ints followed by 5 shorts, then 4 ints, 2
Strings, and 2 ints. total of 19 members.
    public static final int size = 6*4 + 5*2 + 4*4 + 2*4 + 2*4;

    public int lStructSize;
    public int  hwndOwner;
    public int  hDevMode;
    public int  hDevNames;
    public int  hDC;
    public int  Flags;
    public short  nFromPage;
    public short  nToPage;
    public short  nMinPage;
    public short  nMaxPage;
    public short  nCopies;
    public int  hInstance;
    public int  lCustData;
    public int  lpfnPrintHook;
    public int  lpfnSetupHook;
    public String  lpPrintTemplateName;
    public String lpSetupTemplateName;
    public int  hPrintTemplate;
    public int  hSetupTemplate;

    public void marshal(LittleEndianOutputStream leos, ArrayList objs)
             throws IOException {
        leos.writeInt(lStructSize);
        leos.writeInt(hwndOwner);
        leos.writeInt(hDevMode);
        leos.writeInt(hDevNames);
        leos.writeInt(hDC);
        leos.writeInt(Flags);
        leos.writeShort(nFromPage);
        leos.writeShort(nToPage);
        leos.writeShort(nMinPage);
        leos.writeShort(nMaxPage);
        leos.writeShort(nCopies);
        leos.writeInt(hInstance);
        leos.writeInt(lCustData);
        leos.writeInt(lpfnPrintHook);
        leos.writeInt(lpfnSetupHook);
        leos.writeStringUnicode(lpPrintTemplateName);
        leos.writeStringUnicode(lpSetupTemplateName);
        leos.writeInt(hPrintTemplate);
        leos.writeInt(hSetupTemplate);
    }

}




Regards,

Alex Kotchnev
Developer / Systems Analyst
Diversified Information Technologies

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CONFIDENTIALITY NOTICE: If you have received this e-mail in error, please
immediately notify the sender by e-mail at the address shown.  This e-mail
transmission may contain confidential information.  This information is
intended only for the use of the individual(s) or entity to whom it is
intended even if addressed incorrectly.  Please delete it from your files
if you are not the intended recipient.  Thank you for your compliance.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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.