I have a strange problem with my camera JNI windows DLL program. I can load and run immaculately on Windows 10 machine on which the DLL program was developed.
When I copy to Windows 11 another machine, I get the unsatisfied Java module load error. It says "cannot find dependent libraries". It works on Windows 10. Not in another machine! The following is a stack trace;
java.lang.UnsatisfiedLinkError: C:\Users\XXXX\AppData\Local\Temp\AnamonCamera-win64.dll10819000438203799267: Can't find dependent libraries
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryI mpl.open(Unknown Source)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(Un known Source)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(Un known Source)
at java.base/java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.base/java.lang.Runtime.load0(Unknown Source)
at java.base/java.lang.System.load(Unknown Source)
at anamon.camera.Webcam.<clinit>(Webcam.java:43)
at anamon.cms.ImageStereoVision.run(ImageStereoVision .java:372)
at java.base/java.lang.Thread.run(Unknown Source)
The following is JNI Visual Studio C++ program snippets which shows included libraries and APIs used. It's basic camera interface program that get a list of camera names and fetch images from a camera. It uses Media Foundation APIs which is win32 which doesn't require extra installations.
#include "jni.h"
#include <mfapi.h>
#include <mfidl.h>
#include <mfreadwrite.h>
#pragma comment(lib, "mf.lib")
#pragma comment(lib, "mfuuid.lib")
#pragma comment(lib, "mfplat.lib")
#pragma comment(lib, "mfreadwrite.lib")
// JNI interface functions call this;
int setupCameraDeviceList() {
HRESULT hr;
if (!mfinitialized) {
hr = MFStartup(MF_VERSION);
if (FAILED(hr)) {
return -3;
}
}
hr = MFCreateAttributes(&videoConfig, 1);
if (FAILED(hr)) {
return -4;
}
......
}
The following is Java DLL loading part. It extracts DLL file stored in a Jar file and store on a temp file. Then the temp file is loaded;
String dllname = "AnamonCamera-win64";
File temp = WebcamTools.extractInJarDllFileAndCreateTempFile(d llname);
System.load(temp.getAbsolutePath());
temp.delete();
The following is Visual Studion CMakeLists.txt file.
cmake_minimum_required (VERSION 3.8)
# Enable Hot Reload for MSVC compilers if supported.
if (POLICY CMP0141)
cmake_policy(SET CMP0141 NEW)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_I D:MSVC>>,$<$<CONFIGebug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIGebug,RelWithDebInforogramDatabase>>")
endif()
project ("AnamonCameraMF-win6")
add_library( # Sets the name of the library.
AnamonCamera-win64
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
AnamonCameraMF.cpp
)
I suspect this CMakeLists.txt file may need something. Otherwise it could be visual studio license or java or windows security issue. Currently I subscribed monthly. Probably not charged yet.
It could be I am making a simple mistake as I am not expert on Visual Studio matter. I use Visual Studio 2022 professional and community editions.