2 Replies Latest reply: Oct 6, 2010 4:11 PM by 803583 RSS

    problem calling java from vb via activex bridge

      I am trying to call java from vb via ActiveX Bridge and I am running into problems. I would appreciate any help.

      I am using Visual Basic 2010 express, and Java JDK 1.6.0_16. I have used the http://download.oracle.com/javase/1.4.2/docs/guide/beans/axbridge/developerguide/index.html page as a guideline. To try to make it work I took the following steps:

      1. Wrote a very simple java class (below):

      package xxx;

      import java.io.Serializable;

      public class axb implements Serializable {
      public int get_axb_Handle() {
      int Address = 12345678;
      return Address;

      2. After I compiled, and created the jar file. I built the dll using the following command:

      "C:\Program Files\Java\jdk1.6.0_16\bin\packager" -out "C:\Program Files\Java\jdk1.6.0_16\jre\axbridge\bin" E:\axb\dist\axb.jar xxx.axb

      3. I then registered using: regsvr32 axb.dll

      4. In Visual Basic Express IDE I use Project -> Add Reference to add Iterop.axb (dump below), and axb namespace

      5. In my basic code I use the following lines

      Dim axb1 As axb.axb
      axb1 = New axb.axb <== Crash here with AccessViolationException ( full exception below)

      What am I missing? Any help would be greatly appreciated

      Iterop.axb partial dump
      ___[MOD] C:\Documents and Settings\Elie A. Cohen.USINC022\My Documents\Visual Studio 2010\Projects\Repo API Example\Repo API Example\obj\x86\Release\Interop.axb.dll
      | M A N I F E S T
      |___[NSP] axb
      | |___[INT] axb.axb
      | | | .class interface public abstract auto ansi import /*02000006*/
      | | | implements axb.axbDispatch/*02000003*/
      | | | implements axb.axbSource_Event/*02000005*/
      | | | .custom /*0C000018:0A000001*/ instance void [mscorlib/*23000001*/]System.Runtime.InteropServices.GuidAttribute/*01000002*/::.ctor(string) /* 0A000001 */ = ( 01 00 24 34 45 36 44 30 44 41 38 2D 36 41 45 44 // ..$4E6D0DA8-6AED ...
      | | | .custom /*0C000019:0A000007*/ instance void [mscorlib/*23000001*/]System.Runtime.InteropServices.CoClassAttribute/*01000009*/::.ctor(class [mscorlib/*23000001*/]System.Type/*01000007*/) /* 0A000007 */ = ( 01 00 0C 61 78 62 2E 61 78 62 43 6C 61 73 73 00 // ...axb.axbClass. ...
      | |
      | |___[CLS] axb.axbClass
      | | | .class public auto ansi import /*02000004*/
      | | | implements axb.axbDispatch/*02000003*/
      | | | implements axb.axb/*02000006*/
      | | | implements axb.axbSource_Event/*02000005*/
      | | | .custom /*0C00000F:0A000008*/ instance void [mscorlib/*23000001*/]System.Runtime.InteropServices.ClassInterfaceAttribute/*0100000A*/::.ctor(int16) /* 0A000008 */ = ( 01 00 00 00 00 00 ) ...
      | | | .custom /*0C000010:0A000009*/ instance void [mscorlib/*23000001*/]System.Runtime.InteropServices.ComSourceInterfacesAttribute/*0100000B*/::.ctor(string) /* 0A000009 */ = ( 01 00 0F 61 78 62 2E 61 78 62 53 6F 75 72 63 65 // ...axb.axbSource ...
      | | | .custom /*0C000011:0A000001*/ instance void [mscorlib/*23000001*/]System.Runtime.InteropServices.GuidAttribute/*01000002*/::.ctor(string) /* 0A000001 */ = ( 01 00 24 43 44 42 46 36 42 33 33 2D 45 32 33 46 // ..$CDBF6B33-E23F ...
      | | | .custom /*0C000012:0A000002*/ instance void [mscorlib/*23000001*/]System.Runtime.InteropServices.TypeLibTypeAttribute/*01000003*/::.ctor(int16) /* 0A000002 */ = ( 01 00 02 00 00 00 ) ...
      | | |___[MET] method .ctor : void()
      | | |___[MET] method equals : bool(object)
      | | |___[MET] method getClass : object()
      | | |___[MET] method get_axb_Handle : int32()
      | | |___[MET] method hashCode : int32()
      | | |___[MET] method notify : void()
      | | |___[MET] method notifyAll : void()
      | | |___[MET] method toString : string()
      | | |___[MET] method wait : object(object,object)

      AccessViolationException exception

      System.AccessViolationException was unhandled
      Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
      at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
      at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
      at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
      at System.Activator.CreateInstance(Type type, Boolean nonPublic)
      at System.Activator.CreateInstance(Type type)
      at WindowsApplication1.Form1.getPatientHandle_Click(Object sender, EventArgs e) in C:\Documents and Settings\Elie A. Cohen.USINC022\my documents\visual studio 2010\Projects\Repo API Example\Repo API Example\Repo API Example.vb:line 13
      at System.Windows.Forms.Control.OnClick(EventArgs e)
      at System.Windows.Forms.Button.OnClick(EventArgs e)
      at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
      at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
      at System.Windows.Forms.Control.WndProc(Message& m)
      at System.Windows.Forms.ButtonBase.WndProc(Message& m)
      at System.Windows.Forms.Button.WndProc(Message& m)
      at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
      at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
      at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
      at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
      at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
      at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
      at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
      at System.Windows.Forms.Application.Run(ApplicationContext context)
      at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
      at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
      at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
      at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
      at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
      at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
      at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      at System.Threading.ThreadHelper.ThreadStart()
        • 1. Re: problem calling java from vb via activex bridge
          At first I thought that being new to ActiveX bridge and VB I was missing something, and that is why I was getting the AccessViolation Exception, but I just tried the two examples posted at http://download-llnw.oracle.com/javase/7/docs/technotes/guides/beans/axbridge/developerguide/examples.html; cal.exe and boundpop.exe and both of them crashed with the following error signature:

          AppName: cal.exe     AppVer:     ModName: axbridge.dll
          ModVer:     Offset: 00002464

          To try them I followed the instructions posted on the web page (i.e. 1. put the dll in the C:\Program Files\Java\jdk1.6.0_16\jre\axbridge\bin directory, 2. register the dll, and 3. run the exe)
          So there is something very basic that is wrong with my environment. I am running on XP Professional SP3 English

          I have several questions
          1. Is Activex Bridge still supported
          2. Is anybody using activex bridge?
          3. Can I find somewhere an example if a working ActiveX bridge?
          4. Most important is there a simple working way to call Java from VB? For my project I really need to find a working solution, and fast

          Thanks for any help
          • 2. Re: problem calling java from vb via activex bridge
            In case you haven't figured it out already... Or if anyone else is curious... Or for myself when I get old and forgetful...

            h2. Object Creation
            For starters, when you create an ActiveX object from within VB, use:
            Set myObject = CreateObject("JavaObject.Bean")
            When I refer to JavaObject.Bean, I'm meaning the full object name + ".Bean". So, in your case, you should use:
            Set myObject = CreateObject("xxx.axb.Bean")
            h2. Location
            The .dll file must be located in the JRE that is used at the time of calling. Meaning, the .dll file must be placed under <jre_home>\axbridge\bin and registered there.
            In your case:
            C:\Program Files\Java\jre6\axbridge\bin

            C:\Program Files\Java\jre6\axbridge\lib
            h4. A Note:
            The only supported JRE is a 32bit version as far as I know with regards to the ActiveX bridge. Just like the packager.exe can only be found in the 32bit JDK.

            h2. Methods
            h3. Object Types
            ActiveX Bridge does not support passing literals or arrays. However, it does support passing java's primitive data types as Objects.
            Simply meaning:
            h4. Invalid:
            public int get_axb_Handle() {
                 int Address = 12345678;
                 return Address;
            h4. Valid:
            public Integer get_axb_Handle() {
                 int Address = 12345678;
                 return Address;
            On a normal circumstance, there's little difference between the two methods. However, in the second example, the JVM does a typecast from a literal data type to a object data type, resulting in a valid object to pass through to Visual Basic. Now, obviously there are multiple ways to do a proper change, new Integer(int) for example. It doesn't matter to me. At the end of the day, you have to pass an object.
            As a side note, the same idea applies when receiving data from Visual Basic.
            h4. Invalid:
            public void set_axb_Handle(int newHandle) {
                 int Address = newHandle;
            h4. Valid:
            public void set_axb_Handle(Integer newHandle) {
                 int Address =newHandle;