Re: Unable to get meaningful error info from VB dll

"Mcnamara, Sean D" <[email protected]> Fri, 2 Jun 2006 08:48:08 -0400
Newsgroups gmane.comp.windows.devel.jawin
Message-ID <57F935D6BB6B2543AF5D835DCE7CAF2701F7F660@MD61EX100.ad.honeywell-tsi.com>
Brian,

Perhaps the line

CreateObject("DebugTools_80.Helper").LogAndReRaiseVBError Err, App, Erl, sThisProject, sThisComponent, sThisFunction

is incorrectly using the Err object? I've never worked with a DebugTools_80.Helper object, but you need to use the Err.Raise method with the correct parameters, including the number:

Dim desiredNum As Integer
Err.Raise number:=vbObjectError + desiredNum, etc1, etc2, etc3, etc4

Also, make sure your VB DLL is not compiled with options to eliminate div/0 checks! Otherwise the VBVM60.DLL will, itself, divide by zero and cause your module to crash.

Is your LogAndReRaiseVBError function "logging" this error anywhere? Try and verify that this line of code is actually being executed. For instance, try displaying a MsgBox before you call this statement, to make sure that your error handler is executed. JAWIN should have no problem displaying message boxes without modifying your code, if I recall correctly...




-----Original Message-----
From: Discussion of Java/Win32/COM integration with Jawin [mailto:[email protected]] On Behalf Of Brian Hirsch
Sent: Thursday, June 01, 2006 8:25 AM
To: [email protected]
Subject: [JAWIN] Unable to get meaningful error info from VB dll

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.