Unable to get meaningful error info from VB dll

Brian Hirsch <[email protected]> Thu, 1 Jun 2006 05:24:40 -0700
Newsgroups gmane.comp.windows.devel.jawin
Message-ID <[email protected]>
We've been unable to get meaningful error information back from a method call to a VB dll.  My configuration is Windows XP, Java 1.4, Jawin 2.0, Visual Studio SP 6.  We've created a simple VB class with one method: DivisionByZeroError.  As you'd guess, this method tries to divide by zero.  I've included all the source code at the bottom.  Wrapper classes have been created for the VB class and are used to access the VB class.
  When we call the method, it is executing the code and is coming back with an COMException, but all the detailed message says is: Exception occurred.  Here's the output from the calling java class:
  The return was error Info :-2147024809
org.jawin.COMException: 80020009: Exception occurred.
   at org.jawin.marshal.GenericStub.dispatchInvoke0(Native Method)
 at org.jawin.marshal.GenericStub.dispatchInvoke(GenericStub.java:84)
 at org.jawin.DispatchPtr.invokeN(DispatchPtr.java:473)
 at org.jawin.DispatchPtr.invokeN(DispatchPtr.java:433)
 at com.cognos.baia.dtptest.DTP.DivisionByZeroError(DTP.java:18)
 at com.cognos.baia.ado.Test.main(Test.java:88)

We get an hresult (-2147352567), but no good exception information.
  As another test, we set up wrappers to access an ADODB dll.  When we try to open a connection with an incorrect connection string, we get this in the detailed message:
  [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified[src=Microsoft OLE DB Provider for ODBC Drivers,guid={0C733A8B-2A1C-11CE-ADE5-00AA0044773D}]

  Good stuff!

  the stack trace looks like this:
  org.jawin.COMException: 80020009: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified[src=Microsoft OLE DB Provider for ODBC Drivers,guid={0C733A8B-2A1C-11CE-ADE5-00AA0044773D}]
The return was error Info from Connection:-2147024809
 at org.jawin.marshal.GenericStub.dispatchInvoke0(Native Method)
 at org.jawin.marshal.GenericStub.dispatchInvoke(GenericStub.java:84)
 at org.jawin.DispatchPtr.invokeN(DispatchPtr.java:473)
 at org.jawin.DispatchPtr.invokeN(DispatchPtr.java:433)
 at org.jawin.DispatchPtr.invoke(DispatchPtr.java:377)
 at com.cognos.baia.ado.Connection.Open(Connection.java:85)
 at com.cognos.baia.ado.Test.getCommand(Test.java:48)
 at com.cognos.baia.ado.Test.main(Test.java:104)

  So, we get good error information from the ADODB call, but minimal from the VB call.  What are we doing wrong?  Why can't we get better error information back from this VB dll?

  Thanks
Brian

  Here's the code from the VB class:
  Public Function DivisionByZeroError() As Long
        '<EhHeader>
        On Error GoTo ErrorHandler
        Const sThisProject As String = "Project1": Const sThisComponent As String = "DTP": Const sThisFunction As String = "DivisionByZeroError": Const sThisProcedure As String = sThisProject & "." & sThisComponent & "." & sThisFunction
        '</EhHeader>

100         DivisionByZeroError = 1 / 0


        '<EhFooter>
        Exit Function
ErrorHandler:
        CreateObject("DebugTools_80.Helper").LogAndReRaiseVBError Err, App, Erl, sThisProject, sThisComponent, sThisFunction
        '</EhFooter>
End Function

Here's how we call it in Java:
    try {
            Ole32.CoInitialize();
   DTP dtp = new DTP();
            dtp.DivisionByZeroError();
            Ole32.CoUninitialize();
  } catch (COMException e) {
   // TODO Auto-generated catch block
   int errorInfo = getErrorInfo();
   System.out.println("The return was error Info :" + errorInfo);
   e.printStackTrace();
        }
  Here's how we're calling the ADODB dll:
    try {
   String connectStr = args[0];
   String queryStr = "select * from authors";
   getCommand(connectStr, queryStr);
   // getRS(connectStr, queryStr);
  } catch (Throwable t) {
   int errorInfo = getErrorInfo();
   System.out.println("The return was error Info from Connection:" + errorInfo);
   t.printStackTrace();
  }
   public static void getCommand(String con, String query) throws COMException // throws
 // Exception
 {
  System.out.println("Command+Connection -> Recordset");
  Connection c = new Connection("ADODB.Connection");
    c.setConnectionString(con);
  c.Open();
  Command comm = new Command("ADODB.Command");
  comm.setActiveConnection(c);
  comm.setCommandType(CommandTypeEnum.adCmdText);
  comm.setCommandText(query);
  Recordset rs = comm.Execute();
  printRS(rs);
  comm.close();
  c.Close();
 }
  Here's how we're going after the error information:
  private static int getErrorInfo() {
  int ret = 0;
  try {
   FuncPtr getErrInfo = new FuncPtr("OLEAUT32.DLL", "GetErrorInfo");
   ret = getErrInfo.invoke(0, 0, ReturnFlags.FAIL_ON_FALSE);
  } catch (COMException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
    return ret;
 }



---------------------------------
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1¢/min.