2 messages in net.java.dev.jna.usersRe: [jna-users] Calling c++ methods w...
FromSent OnAttachments
vsworkFeb 28, 2008 5:21 am 
Timothy WallFeb 28, 2008 5:56 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Calling c++ methods with mangled names exported by DLL.Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Feb 28, 2008 5:56:12 am
List:net.java.dev.jna.users

On Feb 28, 2008, at 8:21 AM, vswork wrote:

How do I call c++ methods with names mangled by linker?

JNA doesn't have a name mangler/demangler for various C++ compilers. The GNU mangling logic is documented and readily available; I don't know about MSVC++.

For example, in .h file method is called

_declspec(dllexport) int WINAPI function(char *szAccount, char *szPassword, char *szIpAddress, int nPort, int nMaxBufSize);

and method name as exported from DLL is

?function@@YGHPAD00HH@Z

There's FunctionMapper interface, but filling it with names map manually is very hard. Is there a more automated solution?

Writing a mangling/demangling FunctionMapper is only part of the solution. In order to properly call non-static C++ methods, you'd also need to provide the implicit "this" pointer as a first argument.

However, a C++ FunctionMapper would be a nice contribution to a JNA extension mapping to C++.

I believe JNIEasy does C++ mapping, but its usage is a little convoluted.