MM_QUERYITEM fails - OS2

This is a discussion on MM_QUERYITEM fails - OS2 ; Witch would be the reasons for MM_QUERYITEM to fail eveytime?. I have checked the parameters over and over and everything seems to be in place, still the call keeps returning FALSE. I'm pretty sure I'm using the right menu handle. ...

+ Reply to Thread
Results 1 to 10 of 10

Thread: MM_QUERYITEM fails

  1. MM_QUERYITEM fails

    Witch would be the reasons for MM_QUERYITEM to fail eveytime?. I have
    checked the parameters over and over and everything seems to be in
    place, still the call keeps returning FALSE.

    I'm pretty sure I'm using the right menu handle. Still i could verify
    that even further. The problem is that a FALSE as a return tells me
    nothing about the reasons (wrong handle, broken pointer to MENUITEM
    stuct or something else)

    Does anyone have the experience on this and can give me pointers on
    where to look?

    Thanks

    Leonardo Pino

  2. Re: MM_QUERYITEM fails

    In <7ff0cf4b-e7a6-4af4-b3ce-6e590e8b6318@e67g2000hsa.googlegroups.com>, on
    04/18/2008
    at 08:39 AM, lpino said:

    >I'm pretty sure I'm using the right menu handle. Still i could verify
    >that even further. The problem is that a FALSE as a return tells me
    >nothing about the reasons (wrong handle, broken pointer to MENUITEM stuct
    >or something else)


    Most of the Win functions return FALSE when an error occurs. You need to
    use WinGetErrorInfo and WinLastError to get the details.

    Steven

    --
    --------------------------------------------------------------------------------------------
    Steven Levine MR2/ICE 3.00 beta 11pre6 #10183
    eCS/Warp/DIY/14.103a_W4 www.scoug.com irc.ca.webbnet.info #scoug (Wed 7pm PST)
    --------------------------------------------------------------------------------------------


  3. Re: MM_QUERYITEM fails

    On Apr 18, 1:27 pm, Steven Levine wrote:
    > In <7ff0cf4b-e7a6-4af4-b3ce-6e590e8b6...@e67g2000hsa.googlegroups.com>, on
    > 04/18/2008
    > at 08:39 AM, lpino said:
    >
    > >I'm pretty sure I'm using the right menu handle. Still i could verify
    > >that even further. The problem is that a FALSE as a return tells me
    > >nothing about the reasons (wrong handle, broken pointer to MENUITEM stuct
    > >or something else)

    >
    > Most of the Win functions return FALSE when an error occurs. You need to
    > use WinGetErrorInfo and WinLastError to get the details.
    >
    > Steven
    >
    > --
    > --------------------------------------------------------------------------------------------
    > Steven Levine MR2/ICE 3.00 beta 11pre6 #10183
    > eCS/Warp/DIY/14.103a_W4www.scoug.comirc.ca.webbnet.info #scoug (Wed 7pm PST)
    > --------------------------------------------------------------------------------------------


    After working on the problem a bit further I found out that the
    problem seems to be something related with JNI mapping of the MENUITEM
    struct.

    I did the following:

    JNIEXPORT jboolean JNICALL
    Java_org_eclipse_swt_internal_pm_OS_WinSendMsg__II ILorg_eclipse_swt_internal_pm_MENUITEM_2
    (JNIEnv *env, jclass that, jint hwnd, jint ulMsgid, jint
    mpParam1, jobject mpParam2)
    {

    MENUITEM c_mpParam2, *c_pmpParam2 = NULL;
    MENUITEM mi;
    jboolean rc, rc2;
    printf("param 1 = %u\n", hwnd);
    printf("param 2 = %d\n", ulMsgid);
    printf("param 3 = %d\n", mpParam1);

    if (mpParam2)
    c_pmpParam2 = getMENUITEMFields(env, mpParam2, &c_mpParam2,
    &PGLOB(MENUITEMFc));
    rc = (jboolean)WinSendMsg((HWND)hwnd, ulMsgid, (MPARAM)mpParam1,
    MPFROMP(c_pmpParam2));
    rc2 = (jboolean)WinSendMsg((HWND)hwnd, ulMsgid, (MPARAM)mpParam1,
    MPFROMP(&mi));
    if (mpParam2)
    setMENUITEMFields(env, mpParam2, c_pmpParam2,
    &PGLOB(MENUITEMFc));
    printf("ID = %d\n", c_pmpParam2->id);
    printf("ID = %d\n", mi.id);
    return rc;
    }
    and I got results on the mi var, but not on the c_pmpParam2. I tried
    to find a pattern looking at other API calls that use pointers to
    structs but I didn't find anything specially wrong with the
    implementation I'm using.

    Here is the output I get on the console:

    [java] ================================================== ==========
    [java] SWT009_08: Testcase FAILED!!!
    [java] ================================================== ==========

    [java] param 1 = 2147484332
    [java] param 2 = 386
    [java] param 3 = 6553601
    [java] ID = 0
    [java] ID = 0
    [java] ID = 0
    [java] param 1 = 2147484332
    [java] param 2 = 386
    [java] param 3 = 1
    [java] ID = 0
    [java] ID = 0 ----> Wrong result
    [java] ID = 8063 ---->Expected result
    [java] param 1 = 2147484332
    [java] param 2 = 386
    [java] param 3 = 6553601
    [java] ID = 0
    [java] ID = 0
    [java] ID = 34192

    Any ideas?

    Thanks

  4. Re: MM_QUERYITEM fails

    In <882eb73a-fcb0-44d8-9e77-cad13d82a9cb@w5g2000prd.googlegroups.com>, on
    04/18/2008
    at 06:31 PM, lpino said:


    Hi,

    >After working on the problem a bit further I found out that the problem
    >seems to be something related with JNI mapping of the MENUITEM struct.


    Are you sure you are using the correct packing and alignment? The
    MENUITEM struct requires pack(2) alignment.

    >I did the following:


    > MENUITEM c_mpParam2, *c_pmpParam2 = NULL;
    >MENUITEM mi;
    > jboolean rc, rc2;
    >printf("param 1 = %u\n", hwnd);
    >printf("param 2 = %d\n", ulMsgid);
    >printf("param 3 = %d\n", mpParam1);


    Personally, I find this easier to analyze if formatted in hex because most
    of the defintions are in hex.

    >[java] param 1 = 2147484332


    This is 0x800002AC, which is a reasonable hwnd value

    >[java] param 2 = 386


    This is 0x182, which is MM_QUERYITEM

    >[java] param 3 = 6553601


    This is 640001, which is not word aligned and might be part of your
    problem.

    Steven

    --
    --------------------------------------------------------------------------------------------
    Steven Levine MR2/ICE 3.00 beta 11pre6 #10183
    eCS/Warp/DIY/14.103a_W4 www.scoug.com irc.ca.webbnet.info #scoug (Wed 7pm PST)
    --------------------------------------------------------------------------------------------


  5. Re: MM_QUERYITEM fails

    On 19 abr, 02:01, Steven Levine wrote:
    > In <882eb73a-fcb0-44d8-9e77-cad13d82a...@w5g2000prd.googlegroups.com>, on
    > 04/18/2008
    > * *at 06:31 PM, lpino said:
    >
    > Hi,
    >
    > >After working on the problem a bit further I found out that the problem
    > >seems to be something related with JNI mapping of the MENUITEM struct.

    >
    > Are you sure you are using the correct packing and alignment? *The
    > MENUITEM struct requires pack(2) alignment.
    >
    > >I did the following:
    > > * *MENUITEM c_mpParam2, *c_pmpParam2 = NULL;
    > >MENUITEM mi;
    > > * *jboolean rc, rc2;
    > >printf("param 1 = %u\n", hwnd);
    > >printf("param 2 = %d\n", ulMsgid);
    > >printf("param 3 = %d\n", mpParam1);

    >
    > Personally, I find this easier to analyze if formatted in hex because most
    > of the defintions are in hex.
    >
    > >[java] param 1 = 2147484332

    >
    > This is 0x800002AC, which is a reasonable hwnd value
    >
    > >[java] param 2 = 386

    >
    > This is 0x182, which is MM_QUERYITEM
    >
    > >[java] param 3 = 6553601

    >
    > This is 640001, which is not word aligned and might be part of your
    > problem.
    >
    > Steven
    >
    > --
    > --------------------------------------------------------------------------------------------
    > Steven Levine *MR2/ICE 3.00 beta 11pre6 #10183
    > eCS/Warp/DIY/14.103a_W4www.scoug.comirc.ca.webbnet.info #scoug (Wed 7pm PST)
    > --------------------------------------------------------------------------------------------


    I'm sorry, but you lost me there.
    What would be the word aligned value for MPFROM2SHORT(100, TRUE)?

    Thanks

  6. Re: MM_QUERYITEM fails

    In <6a91693c-21b4-487b-8bf1-03b01f10ec3b@m3g2000hsc.googlegroups.com>, on
    04/21/2008
    at 10:26 AM, lpino said:

    Hi,

    >> This is 0x182, which is MM_QUERYITEM
    >>
    >> >[java] param 3 = 6553601

    >>
    >> This is 640001, which is not word aligned and might be part of your
    >> problem.


    >I'm sorry, but you lost me there.
    >What would be the word aligned value for MPFROM2SHORT(100, TRUE)?


    Sorry. MP2 points to a MENUITEM structure. According to the toolkit
    headers, the buffer for this structure must be word aligned in memory.
    Your data dump indicates that your buffer is byte aligned. This can cause
    problems, especially if the message processing needs to go though a call
    gate and the pointers need to be thunked on the other side of the gate.

    Steven

    --
    --------------------------------------------------------------------------------------------
    Steven Levine MR2/ICE 3.00 beta 11pre7 #10183
    eCS/Warp/DIY/14.103a_W4 www.scoug.com irc.ca.webbnet.info #scoug (Wed 7pm PST)
    --------------------------------------------------------------------------------------------


  7. Re: MM_QUERYITEM fails

    On Apr 21, 2:00 pm, Steven Levine wrote:
    > In <6a91693c-21b4-487b-8bf1-03b01f10e...@m3g2000hsc.googlegroups.com>, on
    > 04/21/2008
    > at 10:26 AM, lpino said:
    >
    > Hi,
    >
    > >> This is 0x182, which is MM_QUERYITEM

    >
    > >> >[java] param 3 = 6553601

    >
    > >> This is 640001, which is not word aligned and might be part of your
    > >> problem.

    > >I'm sorry, but you lost me there.
    > >What would be the word aligned value for MPFROM2SHORT(100, TRUE)?

    >
    > Sorry. MP2 points to a MENUITEM structure. According to the toolkit
    > headers, the buffer for this structure must be word aligned in memory.
    > Your data dump indicates that your buffer is byte aligned. This can cause
    > problems, especially if the message processing needs to go though a call
    > gate and the pointers need to be thunked on the other side of the gate.
    >
    > Steven
    >
    > --
    > --------------------------------------------------------------------------------------------
    > Steven Levine MR2/ICE 3.00 beta 11pre7 #10183
    > eCS/Warp/DIY/14.103a_W4www.scoug.comirc.ca.webbnet.info #scoug (Wed 7pm PST)
    > --------------------------------------------------------------------------------------------


    I worked on the problem further and I modified the call to the
    following code:

    JNIEXPORT jboolean JNICALL
    Java_org_eclipse_swt_internal_pm_OS_WinSendMsg__II ILorg_eclipse_swt_internal_pm_MENUITEM_2
    (JNIEnv *env, jclass that, jint hwnd, jint ulMsgid, jint
    mpParam1, jobject mpParam2)
    {

    MENUITEM c_mpParam2, *c_pmpParam2 = NULL;
    MENUITEM mi;
    jboolean rc, rc2;

    printf("param 1 = %X\n", hwnd);
    printf("param 2 = %X\n", ulMsgid);
    printf("param 3 = %X\n", mpParam1);
    printf("param 3 right = %X\n", MPFROM2SHORT(100, TRUE));


    if (mpParam2)
    c_pmpParam2 = getMENUITEMFields(env, mpParam2, &c_mpParam2,
    &PGLOB(MENUITEMFc));

    rc = (jboolean)WinSendMsg((HWND)hwnd, ulMsgid, (MPARAM)mpParam1,
    MPFROMP(c_pmpParam2));
    rc2 = (jboolean)WinSendMsg((HWND)hwnd, ulMsgid, MPFROM2SHORT(100,
    TRUE), MPFROMP(&mi));
    if (mpParam2)
    setMENUITEMFields(env, mpParam2, c_pmpParam2,
    &PGLOB(MENUITEMFc));

    printf("ID c_pmpParam2 = %X\n", c_pmpParam2->id);
    printf("ID mi= %X\n", mi.id);

    return rc;
    }

    The idea was to inject a known to be right value, this time also for
    the third parameter. The surprise was to find out that it worked and
    for the mi variable, the whole stucture was return. So then I added
    the line to print the result of the macro MPFROM2SHORT(100, TRUE) and
    there it was the values were inverted instead of getting 640001 I got
    10064,, but why?

    The macro was programmed into the Java code:

    public static final int MPFROM2SHORT(short s1, short s2){ return ((s1
    << 16) + s2);}

    and I have been using it extensively across the code. The natural
    question is... is that Java code wrong? and why?.

    Anyway here is the output:

    [java] ================================================== ==========
    [java] SWT009_08: Testcase FAILED!!!
    [java] ================================================== ==========

    [java] param 1 = 80000389
    [java] param 2 = 182
    [java] param 3 = 640001 --> this comes from the java code
    [java] param 3 right = 10064
    [java] ID c_pmpParam2 = 0
    [java] ID mi= 64 --> right answer
    [java] param 1 = 80000389
    [java] param 2 = 182
    [java] param 3 = 1
    [java] param 3 right = 10064
    [java] ID c_pmpParam2 = 0
    [java] ID mi= 64
    [java] param 1 = 80000389
    [java] param 2 = 182
    [java] param 3 = 640001
    [java] param 3 right = 10064
    [java] ID c_pmpParam2 = 0
    [java] ID mi= 64

    Thanks

  8. Re: MM_QUERYITEM fails

    lpino wrote:
    > The macro was programmed into the Java code:
    >
    > public static final int MPFROM2SHORT(short s1, short s2){ return ((s1
    > << 16) + s2);}
    >
    > and I have been using it extensively across the code. The natural
    > question is... is that Java code wrong? and why?.


    Looks wrong when I compare to the appropriate macro definition from the
    C world (which I use extensively):

    ((ULONG)(((USHORT)(firstShort)) | ((ULONG)((USHORT)(secondShort))) << 16

    The first short should be the low order 16 bits of the 32-bit word. You
    have it shifted into the high order 16 bits.

    --
    [Reverse the parts of the e-mail address to reply.]

  9. Re: MM_QUERYITEM fails

    On Apr 24, 2:19*am, Marty wrote:
    > lpino wrote:
    > > The macro was programmed into the Java code:

    >
    > > public static final int MPFROM2SHORT(short s1, short s2){ return ((s1
    > > << 16) + s2);}

    >
    > > and I have been using it extensively across the code. The natural
    > > question is... is that Java code wrong? and why?.

    >
    > Looks wrong when I compare to the appropriate macro definition from the
    > C world (which I use extensively):
    >
    > ((ULONG)(((USHORT)(firstShort)) | ((ULONG)((USHORT)(secondShort))) << 16
    >
    > The first short should be the low order 16 bits of the 32-bit word. *You
    > have it shifted into the high order 16 bits.
    >
    > --
    > [Reverse the parts of the e-mail address to reply.]


    My God!!! that means A LOT of code will have to be reviewed, but maybe
    this will solve some of the unresolved issues I just couldn't fix like
    the insertions of tabs

    At least now I can keep on going.

    Thanks everyone

  10. Re: MM_QUERYITEM fails

    On Apr 24, 9:11 am, lpino wrote:
    > On Apr 24, 2:19 am, Marty wrote:
    >
    >
    >
    > > lpino wrote:
    > > > The macro was programmed into the Java code:

    >
    > > > public static final int MPFROM2SHORT(short s1, short s2){ return ((s1
    > > > << 16) + s2);}

    >
    > > > and I have been using it extensively across the code. The natural
    > > > question is... is that Java code wrong? and why?.

    >
    > > Looks wrong when I compare to the appropriate macro definition from the
    > > C world (which I use extensively):

    >
    > > ((ULONG)(((USHORT)(firstShort)) | ((ULONG)((USHORT)(secondShort))) << 16

    >
    > > The first short should be the low order 16 bits of the 32-bit word. You
    > > have it shifted into the high order 16 bits.

    >
    > > --
    > > [Reverse the parts of the e-mail address to reply.]

    >
    > My God!!! that means A LOT of code will have to be reviewed, but maybe
    > this will solve some of the unresolved issues I just couldn't fix like
    > the insertions of tabs
    >
    > At least now I can keep on going.
    >
    > Thanks everyone


    Guess what,,?, I have basic operational menus and tabs issues were
    resolved too!

    Great, now I need to finish and test the implementation

    Thanks

+ Reply to Thread