How to call c++ com dll ?

U

Uli Kunkel

I have an SDK for some hardware that is written i c++. It has library's
and header files.I would like to make a java applet using it.
I'm wondering if I encapsulate some sdk functions in a COM dll can I
then call these functions from an applet??

Thanks in advance for any suggestions.
 
A

Arne Vajhøj

Uli said:
I have an SDK for some hardware that is written i c++. It has library's
and header files.I would like to make a java applet using it.
I'm wondering if I encapsulate some sdk functions in a COM dll can I
then call these functions from an applet??

It would need to be:

Java---(JNI)--->C Win32 DLL---(COM)--->C++ COM DLL

And applets can now download DLL's so it need to be on the
system.

I would look for alternatives.

Arne
 
U

Uli Kunkel

Arne said:
It would need to be:

Java---(JNI)--->C Win32 DLL---(COM)--->C++ COM DLL

And applets can now download DLL's so it need to be on the
system.

I would look for alternatives.

Arne

Thanks for the replay. I also found out a project for java COM
interoperability (JACOB).I haven't tried it yet.
I suppose I can write a Win32 DLL and encapsulate header files +
library's sdk.
As I understand there is no need to create a COM dll for this task?
 
R

Roedy Green

I have an SDK for some hardware that is written i c++. It has library's
and header files.I would like to make a java applet using it.
I'm wondering if I encapsulate some sdk functions in a COM dll can I
then call these functions from an applet??

Thanks in advance for any suggestions.

see http://mindprod.com/jgloss/jni.html

You write some glue, same native functions callable from Java, that
then invoke the API of your com library.
 
A

Arne Vajhøj

Uli said:
Thanks for the replay. I also found out a project for java COM
interoperability (JACOB).I haven't tried it yet.
I suppose I can write a Win32 DLL and encapsulate header files +
library's sdk.
As I understand there is no need to create a COM dll for this task?

I assume JACOB just provides a generic Win32 DLL in my
ASCII diagram above.

You can use that or write your own.

Writing a COM DLL will not help you, because it can not be
called directly from Java (except in the MS Java back from the
mid 90's).

Arne
 
A

Arne Vajhøj

Uli said:
So I can create an MFC DLL project to expose some functions and than
write the "glue"?
Will all the library's from the original sdk be embedded in that one dll?

You can not embed a DLL in another DLL. But if you have the LIB then
you can link the code into the new DLL.

Arne
 
U

Uli Kunkel

Arne said:
You can not embed a DLL in another DLL. But if you have the LIB then
you can link the code into the new DLL.

Arne

Can I create a LIB from a DLL if I don't have the project for that dll?
I think that can't be done so for that DLL library's I would have to
copy them with the library I create.
 
U

Uli Kunkel

Arne said:
You can not embed a DLL in another DLL. But if you have the LIB then
you can link the code into the new DLL.

Arne

I have another problem.
When I create a test dll, java can call it without any problems.
But when I call other dlls from the "exposed" dll I get the following
error "java.lang.UnsatisfiedLinkError" ... "Can't find dependent libraries".
All the dlls are in the same directory.I use System.load() and specify
the whole path.
 
R

Roedy Green

So I can create an MFC DLL project to expose some functions and than
write the "glue"?
Will all the library's from the original sdk be embedded in that one dll?

It depends on how you create the glue DLL. You control that with link
options in the IDE. The part that uses the COM API is just an ordinary
C++ program. It is not Java's business what you do.

As others have pointed out, you might have an easier time of it
starting with Java->COM library where someone has already done this
work for you exposing most of the COM API. The advantage of my
approach is the end result will be slimmer if you need only a few
functions.
 
R

Roedy Green

Can I create a LIB from a DLL if I don't have the project for that dll?
I think that can't be done so for that DLL library's I would have to
copy them with the library I create.

I did most of my C++ work in the 90s, with just some small JNI modules
since 2000, so I am not the person to ask. This is a question to ask
of people with expertise in the C++ compiler/linker you use.
 
U

Uli Kunkel

Roedy said:
It depends on how you create the glue DLL. You control that with link
options in the IDE. The part that uses the COM API is just an ordinary
C++ program. It is not Java's business what you do.

As others have pointed out, you might have an easier time of it
starting with Java->COM library where someone has already done this
work for you exposing most of the COM API. The advantage of my
approach is the end result will be slimmer if you need only a few
functions.

When I only comment out some function declarations that are defined in
some other dlls the loading of the jni dll works.
I haven't change any project settings..
 
U

Uli Kunkel

Uli said:
I have another problem.
When I create a test dll, java can call it without any problems.
But when I call other dlls from the "exposed" dll I get the following
error "java.lang.UnsatisfiedLinkError" ... "Can't find dependent
libraries".
All the dlls are in the same directory.I use System.load() and specify
the whole path.

I found the location for my problem.
When in an jni exposed function I call the function that initializes the
sdk, than the dll cannot load.
Notice that the error doesn't come up when I call the exposed method!It
comes up when I try to load the dll.
 
U

Uli Kunkel

Uli said:
When I only comment out some function declarations that are defined in
some other dlls the loading of the jni dll works.
I haven't change any project settings..

I found out what the problem was.
I had to put the sdk dlls in my jre/bin directory.
I don't know when I finish and build a jar containing them will that
work, or should I put them all in the system folder...
 
L

Lew

Uli said:
I found out what the problem was.
I had to put the sdk dlls in my jre/bin directory.
I don't know when I finish and build a jar containing them will that
work, or should I put them all in the system folder...

Both the JRE bin/ and system directories seem like singularly inappropriate
locations. Are the DLLs part of Java? The operating system?
 
U

Uli Kunkel

Lew said:
Both the JRE bin/ and system directories seem like singularly
inappropriate locations. Are the DLLs part of Java? The operating system?

Java calls several JNI exported functions from MyDll.dll.
MyDll.dll than uses some other dlls that are actually some hardware sdk.
Java----MyDll.dll-----Other Dlls

Usually all this dlls are in the same directory, but when used from a
java application it expects "Other Dlls" in the jre/bin directory.
 
A

Arne Vajhøj

Uli said:
Java calls several JNI exported functions from MyDll.dll.
MyDll.dll than uses some other dlls that are actually some hardware sdk.
Java----MyDll.dll-----Other Dlls

Usually all this dlls are in the same directory, but when used from a
java application it expects "Other Dlls" in the jre/bin directory.

That should be just a matter of having jre/bin in PATH.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top