Solved

Calling functions in VB6 ActiveX DLL Using JNI in Java

Posted on 2014-04-18
7
1,370 Views
Last Modified: 2014-04-19
I have an old VB6 program that is 10 years old, and it is communicating with the COM interface of a commercial program of the time, PADS Layout 2005. I would like to reuse my fully functional code contained in the VB6 program I wrote at the time in a Java program, and also since all the examples for communicating with PADS layout are done in VB6 or a proprietary VB scripting API, it would be very hard to do anything else, practically.

So I want to put all essential code from the VB6 program into a VB6 ActiveX DLL, wrap it into a VC++ DLL and access functions in it it with JNI using Java.

I found a simple example, that looked very reasonable, that worked to a certain point:

https://www.classle.net/book/creation-dll-vb-and-deployment-java-using-jni

It is just adding up 2 int numbers converted to String and displayed, the activeX dll VB6 function used:

Public Function add(ByVal a As Integer, ByVal b As Integer)

MsgBox "Result: " + CStr(a + b) 'Convert to String function

End Function

Open in new window



I did the exact same thing as suggested in example, same folder structure and file names, and I got all the way to creating the header files, as described at the link above:

 4) Now create the JNI header files for the class file using the following command

                   javah  –jni  NativeImpl

All I get is various error messages, I tried several things:

Running javah on command line
I am using an XP virtual machine, Visual Studio 6 installed, which includes Visual Basic 6 and Visual C++ 6.0 to make the wrapper DLL. I am using older Java 1.6, and still I slightly had to change code to avoid using a depricated method. I also did a decompile on the Java class file I created, just to check, but it looks fine to me:

// Decompiled by DJ v3.11.11.95 Copyright 2009 Atanas Neshkov  Date: 4/18/2014 7:18:57 AM
// Home Page: http://members.fortunecity.com/neshkov/dj.html  http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   NativeImpl.java

import java.io.*;

public class NativeImpl
{

    public NativeImpl()
    {
    }

    public native void add(int i, int j);

    public static void main(String args[])
        throws IOException
    {
        DataInputStream datainputstream = new DataInputStream(System.in);
        NativeImpl nativeimpl = new NativeImpl();
        System.out.println("Enter number 1 & 2:");
        int i = Integer.parseInt(datainputstream.toString());
        int j = Integer.parseInt(datainputstream.toString());
        nativeimpl.add(i, j);
    }

    static 
    {
        System.loadLibrary("dllproj");
    }
}

Open in new window


The only change I had to make in the OS is adding a CLASSPATH, so that the javac compiler could be found on command line. that should be enough, right?:
CLASSPATH
I have all the files, in the zip file on my Google drive:

https://drive.google.com/file/d/0BzAVH2D-BU9IQ21tcDZwb1RhUXc/edit?usp=sharing

(Expert Exchange did not let me upload a zip containing a dll)

Thank you for your help.
0
Comment
Question by:AttilaB
  • 4
  • 3
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 40009346
You'll find it much easier using JNA
0
 

Author Comment

by:AttilaB
ID: 40009460
Ok. I can do that. However, let's suppose I create an ActiveX DLL from the VB6 code I want to reuse. Do I still need to wrap it into a C++ DLL before I have access to it through JNA?

If yes, since I don't really have much experience with C++, can you point me to some step-by-step example on how to do that?
(I mostly did Java and VB6)

Or is there perhaps a good working example of how to go from an ActiveX DLL connecting all the way to Java, using JNA?

Thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40009721
Do I still need to wrap it into a C++ DLL before I have access to it through JNA?
No, JNA can access the library directly
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:AttilaB
ID: 40009784
Even if it is ActiveX DLL, not a C++ DLL?

Do you know of any good examples or tutorials on that?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40009790
ActiveX is little more than a brand name. Also, the language in which is written is irrelevant.The only thing that's relevant is the binary format and its exports

I could only google, like you, for the links to tutorials
0
 

Author Closing Comment

by:AttilaB
ID: 40009809
OK. Thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40010115
:)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb6, excel Run-time error 1004 method 'close' of object 'workbooks' failed 7 44
Modifying Conditional Format from VBA code 3 49
Apps blocked by Java 9 64
javap bin 2 30
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now