Trivial question?

S

simplicity

Why do the examples always have to be completely disconnected from the
reality?

I am trying to create a simple prototype which interfaces with the
native DLL using JNA. So, following the JNA tutorial, I specify the
native function as
int func(int)
just as it is in the C++ header. When I run the java program it fails
with "module not found" exception.

After a bit of digging inside the DLL I see that it rightly so: my
function is actually _func@0 rather than func. OK, so back to Java
code and change the the native to what it really is.

Syntax error!!! Java will not take _func@0 as a function name. Because
of "@", I guess.

So, here is my "trivial question": How can I put this name with "@" to
allow Java to digest it without complaints?
 
M

markspace

So, here is my "trivial question": How can I put this name with "@" to
allow Java to digest it without complaints?


To me this is really a question of knowing your compiler, not Java.
Java doesn't allow @ signs in identifiers, period. You'll have to make
an identifier that Java can accept. One without an @ sign. Hence,
you'll need to ask on your compiler help list how to get rid of the @.

Some compilers support an option to remove the name mangling (the @),
some you have an assembler that you can use to bridge the gap between C
output and another language. It all depends on your long term goals,
and what your language is capable of.
 
A

Andreas Leitgeb

markspace said:
To me this is really a question of knowing your compiler, not Java.
Java doesn't allow @ signs in identifiers, period. You'll have to make
an identifier that Java can accept. One without an @ sign. Hence,
you'll need to ask on your compiler help list how to get rid of the @.
Some compilers support an option to remove the name mangling (the @),
some you have an assembler that you can use to bridge the gap between C
output and another language. It all depends on your long term goals,
and what your language is capable of.

extern "C" {
...
int func(...) { ... }
...
}

might help a lot, too. (just guessing)
 
R

Roedy Green

I am trying to create a simple prototype which interfaces with the
native DLL using JNA

You might think that was a typo for JNI. They have similar purposes.

See http://mindprod.com/jgloss/jna.html
http://mindprod.com/jgloss/jni.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
Capitalism has spurred the competition that makes CPUs faster and
faster each year, but the focus on money makes software manufacturers
do some peculiar things like deliberately leaving bugs and deficiencies
in the software so they can soak the customers for upgrades later.
Whether software is easy to use, or never loses data, when the company
has a near monopoly, is almost irrelevant to profits, and therefore
ignored. The manufacturer focuses on cheap gimicks like dancing paper
clips to dazzle naive first-time buyers. The needs of existing
experienced users are almost irrelevant. I see software rental as the
best remedy.
 
R

Roedy Green

So, here is my "trivial question": How can I put this name with "@" to
allow Java to digest it without complaints?

You would put a C wrapper around it with a Java-friendly name.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Capitalism has spurred the competition that makes CPUs faster and
faster each year, but the focus on money makes software manufacturers
do some peculiar things like deliberately leaving bugs and deficiencies
in the software so they can soak the customers for upgrades later.
Whether software is easy to use, or never loses data, when the company
has a near monopoly, is almost irrelevant to profits, and therefore
ignored. The manufacturer focuses on cheap gimicks like dancing paper
clips to dazzle naive first-time buyers. The needs of existing
experienced users are almost irrelevant. I see software rental as the
best remedy.
 
S

simplicity

extern "C" {
    ...
    int func(...) { ... }
    ...

}

might help a lot, too.   (just guessing)

This will work but I hoped there would be a way to do it without
creating an extra layer between Java and the DLL. I actually found a
package called xFunction that is similar to JNA and actually allows me
to define native modules with "@", something like

xFunction func = new xFunction("my_dll_library", "int _func@0(int)");

and execute it

int rc = ((Integer) func.invoke(1)).intValue();

so, apparently, there is a way. I hoped that there might be something
as simple as the syntax I am not aware of.
 
A

Andreas Leitgeb

simplicity said:
This will work but I hoped there would be a way to do it without
creating an extra layer between Java and the DLL.

Seems like I misunderstood your problem. I thought, the DLL was yours,
so you'd extern-"C"-wrap the relevant functions within the DLL and then
use it trivially from Java.

If it's not your own DLL, then I understand, that my solution doesn't
satisfy you. :-/

Either xFunction does have its own code between the DLL and Java, or
(if it is pure java itself) you could examine how it does the magic.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top