www.teamdev.com
0 Replies Last post: Aug 4, 2008 11:10 PM by Dan  
Click to view Dan's profile   6 posts since
Jul 28, 2008

Aug 4, 2008 11:10 PM

Need help resizing a SafeArray argument


Hello,

I am implementing an interface that is written in Visual Basic and having trouble getting the array to resize. Here is the Java code I wrote that implements the "GetErrors" function of the interface:

    public Int32 GetErrors(SafeArray array) {
        String errors[] = { "error1", "error2" };
        try {
            // Redimension the array
            array.create(new SafeArrayBound(errors.length, 0));
            // Set the values 
            for (int idx = 0; idx < errors.length; idx++) {
                BStr bstr = new BStr(errors[idx]);
                bstr.setAutoDelete(false);
                array.set(idx, bstr);  // This line fails
            }
            array.unlock();
        } catch (Throwable th) {
            th.printStackTrace();
        }
        return new Int32(errors.length);
    }


And Here is the VB code that calls into the Java code:

    Private Sub TestResizeArray()
        Dim nErrorCount As Integer
        Dim sErrors() As String
 
        nErrorCount = objJavaServer.GetErrors(sErrors)
    End Sub


What is supposed to happen is that the VB code passes an empty string array and the GetErrors function will fill that string array with the error strings.

Any help is appreciated.

Thanks,
Dan