Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load a library that calls functions from a dependency from java #26

Closed
K-Full opened this issue Feb 7, 2017 · 1 comment
Closed

Load a library that calls functions from a dependency from java #26

K-Full opened this issue Feb 7, 2017 · 1 comment

Comments

@K-Full
Copy link

K-Full commented Feb 7, 2017

I want to call the dll output by unmanagedexportts from JNA.
However, all dlls that are dependent on dll must be placed in the same folder as JRE.
I think it would be nice if there was a way to go to load dll in the same folder as dll in a folder different from JRE. I would like you to tell me if there is something else in a different way.

java-native-access/jna#590

@3F
Copy link
Owner

3F commented Feb 7, 2017

It shouldn't be related for DllExport at all, because it only adds records into EXPORT_DIRECTORY (read more about PE32/PE32+).
That is, the final dynamic-link libraries(DLL) should contains the addresses of exported functions/variables as for your example from #25

If you have problem with paths:

For example, the windows platform (WinAPI) provides LoadLibrary functions for work with dynamic libraries (DLL).

https://msdn.microsoft.com/en-us/library/windows/desktop/ms684179.aspx

HMODULE WINAPI LoadLibraryEx(
  _In_       LPCTSTR lpFileName,
  _Reserved_ HANDLE  hFile,
  _In_       DWORD   dwFlags
);

You can try to use flag 0x00000200 (LOAD_LIBRARY_SEARCH_APPLICATION_DIR) - If this value is used, the application's installation directory is searched for the DLL and its dependencies.
or 0x00000400 via AddDllDirectory etc.

e.g. my implementation for .NET uses 0x00000008 (LOAD_WITH_ALTERED_SEARCH_PATH)

The JNA uses this logic: https://github.com/java-native-access/jna/blob/master/src/com/sun/jna/NativeLibrary.java

so you can also try to use:

public static final void addSearchPath(String libraryName, String path)

+ other specific way for JNA, and any own implementation of course.

By the way:

java.lang.Error: Invalid memory access

the problem can be for different architectures (x64/x86 ...). I don't remember specific error for java but it looks like incorrect access in memory by reading of incorrect addresses etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants