Help for SAFEARRAY(unsigned char)*

Help
2014-04-04
2014-04-07
  • Kyle Renfro

    Kyle Renfro - 2014-04-04

    Hello,

    I need help with the following IDL.

    VARIANT_BOOL AZSetAddressBlock_ForMultiThread(
                    [in] BSTR addressLine1, 
                    [in] BSTR addressLine2, 
                    [in] BSTR addressLine3, 
                    [in] BSTR City, 
                    [in] BSTR State, 
                    [in] BSTR zipcode, 
                    [in] BSTR urbanization, 
                    [in, out] SAFEARRAY(unsigned char)* outputRec);
    

    Here is what I have tried so far:

        //instantiate the Character[] and populate it with ' '
        //bufferSize was previously retrieved from the COM object.  (its 5000)
        Character[] data = createPopulatedCharacterArray(bufferSize);
    
        JIVariant v = new JIVariant(new JIArray(data, true), true);
    
        //some other blind attempts that did not work            
        //JIArray v = new JIArray(data, true);           
        //JIVariant v = new JIVariant(new JIArray(data, true));
    
        Object[] params = new Object[8];
        params[0] = new JIString("1234 Main St");
        params[1] = new JIString("");
        params[2] = new JIString("");
        params[3] = new JIString("Austin");
        params[4] = new JIString("TX");
        params[5] = new JIString("78701);
        params[6] = new JIString("");
        params[7] = v;
    
        Object[] result = accuzipDispatch.callMethodA("AZSetAddressBlock_ForMultiThread", params);
    

    The error I receive is 0x800200005

    I have also attempted to use Byte[] instead of Character[].

    I have worked though compiling trunk and solving my Windows 7 issues from the forum. Several other methods against this COM object are working correctly. I'm so close to getting this project finished, any help you can give would be much appreciated.

    thanks!

     
  • Kyle Renfro

    Kyle Renfro - 2014-04-07

    I have made some progress. I am now able to call the method on the com object and the value returned is 'true', meaning the com object liked my arguments and did some work. However, the JIArray I am passing by reference is not being updated.

    If I pass in a JIArray of JIUnsignedBytes I no longer get the error message!

    //build array of JIUnsignedBytes
    int bufferSize = 5000;
    JIUnsignedByte[] bytes = new JIUnsignedByte[bufferSize];
    
    //initialize each element or J-Interop will throw NPE when trying to calculate the size of the parameters 
    for (int i = 0; i < bufferSize; i++){
        bytes[i] = (JIUnsignedByte) JIUnsignedFactory.getUnsigned((short) 0, JIFlags.FLAG_REPRESENTATION_UNSIGNED_BYTE);
    }
    
    //wrap the JIUnsignedByte[] in a JIArray then a JIVariant and 
    //specify by-reference.
    
    JIVariant v = new JIVariant(new JIArray(bytes, true),  true);
    
    Object[] params = new Object[8];
    params[0] = new JIString("1234 Main St");
    params[1] = new JIString("");
    params[2] = new JIString("");
    params[3] = new JIString("Austin");
    params[4] = new JIString("TX");
    params[5] = new JIString("78701);
    params[6] = new JIString("");
    params[7] = v;
    
    JIVariant[] result = accuzipDispatch.callMethodA("AZSetAddressBlock_ForMultiThread", params);
    
    //check the result
    if (result[0].getObjectAsBoolean()){
        System.out.println("All Good");
    }
    
    //print out the array values that were passed by reference...
    //this prints out '0' for each element, which is what there were initialized to.
    JIArray test = ((JIVariant) params[7]).getObjectAsArray();
    for (JIUnsignedByte b: (JIUnsignedByte[]) test.getArrayInstance()){
        System.out.println(b.getValue());
    }
    

    I am expecting the JIUnsignedByte[] to contain an updated value, but it is always '0' (or whatever I initialize the array with)

    So, I feel I'm on the right track, but hopefully doing something silly that y'all can spot.

    thanks!

     
  • Kyle Renfro

    Kyle Renfro - 2014-04-07

    It was indeed silly. The result I wanted was returned in the JIVariant[] result array.

    result[1].getObjectAsArray();
    

    whew.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks