Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#121 32 bit pointers in 1.17

1.18
open
nobody
None
5
2014-08-27
2014-04-24
tbeu
No

After updating my code from 1.14.3 to 1.17 I noticed that my checks if m_pDispatch is zero or not no longer take effect if a 32-bit COM server application is started.

long NOT_ATTACHED = 0;
prog = new ActiveXComponent("progID"); // start 32-bit COM server appl
Variant v = Dispatch.invoke(prog, "Method",
    Dispatch.Method, new Object[] {"test"},
    new int[0]).toDispatch(); // get some variant data
if (v.getvt() == Variant.VariantDispatch)
    if (v.getDispatch().m_pDispatch == NOT_ATTACHED) {
        // We never get here if our prog is a 32-bit application and
        // "Method" returns a 32-bit null pointer in variant v
        // since only the lower 32-bit of m_pDispatch are zeros whereas
        // the upper 32 bit of m_pDispatch are garbage.
    }
}

Thus I guess when changing Jacob in 1.17 from int to long data type it was overseen that casting null pointers should result in 64-bit zeros.

Instead of int or long a proper pointer type should be used (if possible).

By the way, why is NOT_ATTACHED private and int in Dispatch.java?

Discussion

  • tbeu
    tbeu
    2014-04-24

    Code fix:

    long NOT_ATTACHED = 0;
    prog = new ActiveXComponent("progID"); // start 32-bit COM server appl
    Variant v = Dispatch.invoke(prog, "Method",
        Dispatch.Method, new Object[] {"test"},
        new int[0]); // get some variant data
    if (v.getvt() == Variant.VariantDispatch) {
        if (v.getDispatch().m_pDispatch == NOT_ATTACHED) {
            // We never get here if our prog is a 32-bit application
            // and "Method" returns a 32-bit null pointer in
            // variant v since only the lower 32-bit of m_pDispatch
            // are zeros whereas the upper 32 bit of m_pDispatch
            // are garbage.
        }
    }
    
     
    Last edit: tbeu 2014-04-24
  • clay_shooter
    clay_shooter
    2014-05-28

    So what do we think the fix is, masking the upper bits when returning form a 32 bit dll?

     
  • tbeu
    tbeu
    2014-05-28

    Yes, that is what I used as a workaround. However it only worked out since there was a special method of my COM server to find out if it is a 32-bit or 64-bit application. There should be a general way to figure it out.

    /**
     * Check if a dispatch object is attached.
     *
     * @param dispatch Dispatch
     * @return true if attached
     */
    private boolean isAttached(Dispatch dispatch) {
        long NOT_ATTACHED = 0;
        boolean retVal = false;
    
        // We need to somehow find out if our
        // COM server is a 32-bit or 64-bit appl
        if (platform(prog) == X64) {
            retVal = dispatch.m_pDispatch != NOT_ATTACHED;
        }
        else {
            retVal = (dispatch.m_pDispatch & 0xFFFFFFFFl) != NOT_ATTACHED;
        }
        return retVal;
    }
    
     
    Last edit: tbeu 2014-05-28
  • tbeu
    tbeu
    2014-05-28

    If you are really interested in a generic solution (and not just a woraround) you should use something like uintptr_t in JNI code.

     
  • tbeu
    tbeu
    2014-07-29

    Two months passed without feedback. :-( I consider this as a serious problem that impedes generality of Jacob usage.