Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Accessing DLL written in Perl from Java

 
Greenhorn
Posts: 7
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I'm doing this project for school: I was tasked to translate a VBS to Java. The first hurdle is to utilize a DLL file in order to connect to the DB. In order to do that I have to know how to access that DLL. The DLL's name is DBIAccess.dll. Here's the code snippet in VBS:

That particular block assigns value to the variable needed to call the function ConnectDBI. If the function connect to the DBI successfully, it returns true. Else, false. I have registered the DLL file to the OS and place it in the system path. I'm also using Eclipse so all configuration are done. I have done my reaserch. JNI, JNA, J-interop. There is this thing about wrapper but I can't quite wrap (pun intended) it around my head. I've followed alot of tutorials but it all seems ineffective for my project, at the least. I've come this far (or near considering my milestone):

And in the main:

I would appreciate it if anyone would help.
 
Saloon Keeper
Posts: 12254
259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the DLL is just for accessing the database, wouldn't it be possible to connect to the database directly using a Java API?
 
Marshal
Posts: 70260
282
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Agree with Stephan. But this is much too difficult a question for “beginning”, so I shall move it.
 
Abbygail Mendoza
Greenhorn
Posts: 7
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know but the project I am on is originally written in VB, and I am to translate it to Java. Anyway, I thought since the program is already written in VB, I thought maybe I could make an .exe file of it then access that file in Java? Or I'm making my complicated problem more complicated? Ps. I really have to use that dll file.
 
author
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Abbygail Mendoza wrote:I have done my reaserch. JNI, JNA, J-interop. There is this thing about wrapper but I can't quite wrap (pun intended) it around my head. I've followed alot of tutorials but it all seems ineffective for my project, at the least.



Basically, VB (likely .NET) is creating a DLL that is completely not compatible with the DLL that is required by Java (JNI, JNA, etc.). What you need to do is create a new DLL, that will wrap and translate requests from the Java layer. This new DLL follows the format of JNI, and is loaded by the code that you shown. This new DLL is also using a .NET language running as unmanaged, so that it can be called by the Java layer, and then forwards those requests to the VB DLL.

If this sounds complicated, well, it kinda is... you will need to understand the two interfaces, as you will be translating between them.

Henry
 
Saloon Keeper
Posts: 22490
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A DLL written in Perl?

Sounds like all kinds of nasty. Perl itself is practically a thin wrapper around C, which is why I've taken to using Python instead of Perl for most of my quick-and-dirty stuff these days (unless there's some serious regex work involved).

I concur. Unless the perl module is doing something more than simple database access, I'd chuck it and code straight to JDBC, which is Java's equivalent to Perl DBI. You don't have to muck around with JNI, language transitions, how to have one VM basically spawn and run another (Perl) VM, and other things that have no business being dumped on someone who doesn't have years of Java experience.
 
Abbygail Mendoza
Greenhorn
Posts: 7
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Henry Wong wrote:What you need to do is create a new DLL, that will wrap and translate requests from the Java layer. This new DLL follows the format of JNI, and is loaded by the code that you shown. This new DLL is also using a .NET language running as unmanaged, so that it can be called by the Java layer, and then forwards those requests to the VB DLL.

Henry



It's quite confusing but I think I understand your point. But, I don't want to sound rude or anything, why is it that in VB it was done in a quite straight-forward way (note the first code block from my question)? But in java I have to make another DLL. Isn't java "more OOP" than VB? Sorry if I sound stupid for I'm only using Java for a year.

Thank you for your answers.
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Abbygail Mendoza wrote:Isn't java "more OOP" than VB?


What does "OOP-ness" (whatever that means) have to do with it. VB and DLLs are Windows concepts; Java is cross-platform.
 
Abbygail Mendoza
Greenhorn
Posts: 7
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Abbygail Mendoza wrote:Isn't java "more OOP" than VB?


What does "OOP-ness" (whatever that means) have to do with it. VB and DLLs are Windows concepts; Java is cross-platform.


You could ignore that line if it doesn't make sense. But what I want to know, because it seems that it is beyond my Java knowledge, is that how is it possible or why is it that in VB you could do it straight-forwardly but not in Java. Perhaps anyone could enlighten me, thank you.
 
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're supposed to use the existing DLL? Look into adding it as a native library to the project with Eclipse.

Also this:
http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#loadLibrary%28java.lang.String%29
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Abbygail Mendoza wrote:Perhaps anyone could enlighten me, thank you.



Already did. DLLs are a Windows-proprietary concept. Why would a cross-platform language and environment such as Java have core features specific to one OS?
 
Abbygail Mendoza
Greenhorn
Posts: 7
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Why would a cross-platform language and environment such as Java have core features specific to one OS?

Oh. I get it. Thank you.
 
Marshal
Posts: 25814
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Abbygail Mendoza wrote:But, I don't want to sound rude or anything, why is it that in VB it was done in a quite straight-forward way (note the first code block from my question)? But in java I have to make another DLL.



Not rude at all. But here's a way to think about that: you're asking about why some guys twenty years ago decided to do something in one way instead of another way. There's really no way to know the answer to that question unless it was documented by those guys, which it wasn't. It's always possible for people to speculate why they did it, and it's possible to come up with plausible-sounding speculations. But at the end of the day... those answers don't provide you with anything useful. You still have to deal with the situation as it is, right?
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Abbygail Mendoza wrote:[...] why is it that in VB it was done in a quite straight-forward way (note the first code block from my question)? But in java I have to make another DLL. Isn't java "more OOP" than VB?



Java is cross-platform, thus doesn't directly support COM. (Interestingly, a structure used in JNI is described as being similar to a COM structure, but I'm not aware of any implementation that actually reuses it that way.) It would be nice if someone had written a generic library that simplifies instantiating and using COM objects, but I'm not aware of such a thing.

Getting back to your original question, you actually have multiple options...

1. Use JNI. Write a "wrapper" DLL in C that internally calls CoGetClassObject etc.

2. Use a child process. Write a "wrapper" program in VB6, C, C#, whatever, that accepts commands on standard input or via the command-line and returns results on standard output. Start it up using ProcessBuilder.start() or java.lang.Runtime.exec().

3. Figure out what database the "DBIAccess" object is talking to, find a JDBC or ODBC driver for it, use JDBC to access it.
 
Yeah. What he said. Totally. Wait. What? Sorry, I was looking at this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic