Reputation: 1025
i am working on some java application in which i am using jni. Well here now i want to call pure c++ function from JNI method. well i am doing this as shown as below code. here dll is created but when i am trying run i get the error java.lang.UnsatisfiedLinkError: Can't find dependent libraries. i am creating my dll in visual studio. so tell me what i am doing wrong in calling c++ function.
here is code of my .cpp file
#include "SensorDetect.h"
#include <stdio.h>
#include <windows.h>
// Include specific Tools header
#include "Tools.h"
// Include IO_XRayUSB_MD_VC80 header
#include "IO_XRayUSB.h"
// Include IO_XRayUSB_MD_VC80 library
#pragma message ("Using : IO_XRayUSB_MD_VC80.lib")
#pragma comment(lib, "IO_XRayUSB_MD_VC80.lib")
//// Custom user Callback function which is called by IO_XrayUsb when a device is plugged or unplugged
void _stdcall DevicePlugUnplugCallback(XRay_CALLBACK * pCallBackInfo, int nCallBackCount)
{
if (pCallBackInfo && (nCallBackCount > 0))
{
for (int nDeviceIndex = 0; nDeviceIndex < nCallBackCount; nDeviceIndex ++)
{
switch(pCallBackInfo[nDeviceIndex].nState)
{
case XRAY_USB_PLUGGED_DEVICE :
printf("\n=>Callback Device: %s has been Plugged...\n\n", pCallBackInfo[nDeviceIndex].pcDeviceName);
break;
case XRAY_USB_UNPLUGGED_DEVICE :
printf("\n=>Callback Device: %s has been Unplugged...\n\n", pCallBackInfo[nDeviceIndex].pcDeviceName);
break;
default:
break;
}
}
}
}
extern "C"
JNIEXPORT void JNICALL Java_sensordetect_SensorDetect_getDevice(JNIEnv * env, jclass cl)
{
const int nNbMaxDevices = 10;
char pDeviceList[nNbMaxDevices][260];
int nDeviceCount = 10;
XRay_HANDLE hDevice;
XRay_SENSOR_INFO SensorInfo;
//int nTriggerMode = GetChoice(1, "Choose Trigger Mode:\t0:XVIS_detection 1:TWI_request_detection");
char pcBuffer[100];
int nKey;
nKey=0;
int nTriggerMode=nKey;
try
{
// XRay_RegisterCallBackPlugDevice to be notified of device plug/unplug
**//This function call creates problem in loading dll. error:Can't find dependent libraries**
BOOL bSuccess = XRay_RegisterCallBackPlugDevice(DevicePlugUnplugCallback);
//for (int nIndex = 0; nIndex < 1; nIndex ++)
printf("\tFound device : %s\n", pDeviceList[0]);
}
catch (...) // catch own CMyException
{
//e.ShowReason();
}
}
Upvotes: 0
Views: 1807
Reputation: 6247
Make sure you specify the -Djava.library.path=C:\path\to\DLLs
option when launching your program, and/or include the DLLs' directories in the Windows PATH
.
Upvotes: 1
Reputation: 121961
Either IO_XRayUSB_MD_VC80.dll
or one of is dependents is not in one of the directories listed in the PATH
environment variable, or does not exist in the same directory where your application is running.
To get a list of DLLs on which a DLL depends you can use dumpbin.exe
:
dumpbin.exe /DEPENDENTS C:\path\to\IO_XRayUSB_MD_VC80.dll
Upvotes: 1