Hi,
I am attempting to write JNI (Java Native Interface) layer ontop of the supplied DLL to enable K8062 control from my Java application. I have written a number of these JNI layers previosuly all without significant issues. Note, I am using the K8062D.DLL file that came on the installation CD with the kit, from the folder “:\K8062 & VM116 DMX light controller\SDK tools\Borland C++Builder\K8062D.DLL” this file is dated “17/11/2008 10:00” (there are several copies of this DLL in the various example directories, but they all appear to be the same size and date so I’m assuming they are identical). I am using “Microsoft Visual C++ 2010 Express v10.0.30319.1”. I am running on Windows 7 64bit.
In case you are not familar with the JNI process I’ll briefly outline it.
- create C header file from Java class which contains native method stubs
- create new Win32 DLL project in VC++
- copy header file from step 1 into project directory and add to project
- copy native library (K8062D.DLL) into project directory
- add native library (K8062D.DLL) to linker ‘additional libraries’ path in VC++ properties
- add native library (K8062D.DLL) to VC++ project libraries path in VC++ properties
8 ) copy native library header file to project directory and add to VC++ project includes path (I am using K8052D_DLL.h from same path as I got the DLL, see above)
9 ) implement interface methods defined in header from step one by calling methods identified in native header file from setp 7 - build project and obtain the new JNI interface DLL
I am having problems at steps 8 and 10.
At step 8 VC++ complains that the function definitions in the native header file are invalid, specifically in the header file 4 lines like the the following are found:
FUNCTION __stdcall StartDevice();
VC++ doesn’t like this as no explict return value is declared, I get around this by creating a new copy of this header file and change all the affected lines to read like this:
FUNCTION void __stdcall StartDevice();
- note the addition of void return value
VC++ is now happy with the header file.
I now try to build the project and VC++ fails with the following linker error:
I have tried recopying the DLL from the CD, I get the same error. I have tried downloading a new DLL from the downloads section of the main Velleman site (this new DLL is dated 11/12/2003) and I get the same error. I have tried downloading a new DLL from a link posted on these forums (this DLL is dated 02/06/2004) and get the same error. I have found a fourth DLL link on this thread but the link is now out of date and doesn’t work.
Can anyone advise as to whats going on here? I can open all of these DLLs using a third party DLL viewer and they look fine, but VC++ allways reports them as corrupt with the same error message.
Any help would be very greatfully recieved
FYI this is my code for the various files - I don’t think any of these are really pertenant to the problem as I think it’s some sort of versioning, or compatability issue with VC++ and the supplied K8062D.DLL file, but for the sake of completeness here they are:
My NEW K8062D.h file:
[code]#ifdef __cplusplus
extern “C” { /* Assume C declarations for C++ */
#endif
#define FUNCTION __declspec(dllimport)
FUNCTION void __stdcall StartDevice();
FUNCTION void __stdcall SetData(long Channel, long Data);
FUNCTION void __stdcall SetChannelCount(long Count);
FUNCTION void __stdcall StopDevice();
#ifdef __cplusplus
}
#endif[/code]
My JNI interface headre file (generated by java)
[code]/* DO NOT EDIT THIS FILE - it is machine generated /
#include <jni.h>
/ Header for class com_dyteqta_control_jni_DMXControl */
#ifndef _Included_com_dyteqta_control_jni_DMXControl
#define _Included_com_dyteqta_control_jni_DMXControl
#ifdef __cplusplus
extern “C” {
#endif
/*
- Class: com_dyteqta_control_jni_DMXControl
- Method: startDevice_native
- Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_dyteqta_control_jni_DMXControl_startDevice_1native
(JNIEnv *, jobject);
/*
- Class: com_dyteqta_control_jni_DMXControl
- Method: stopDevice_native
- Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_dyteqta_control_jni_DMXControl_stopDevice_1native
(JNIEnv *, jobject);
/*
- Class: com_dyteqta_control_jni_DMXControl
- Method: setChannel_native
- Signature: (I)V
*/
JNIEXPORT void JNICALL Java_com_dyteqta_control_jni_DMXControl_setChannel_1native
(JNIEnv *, jobject, jint);
/*
- Class: com_dyteqta_control_jni_DMXControl
- Method: setData_native
- Signature: (II)V
*/
JNIEXPORT void JNICALL Java_com_dyteqta_control_jni_DMXControl_setData_1native
(JNIEnv *, jobject, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
[/code]
My JNI interface cpp file:
[code]// DMXControl.cpp : Defines the exported functions for the DLL application.
//
#include <jni.h>
#include “stdafx.h”
#include “DMXControl.h”
#include “K8062D.h”
/*
- Class: com_dyteqta_control_jni_DMXControl
- Method: startDevice_native
- Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_dyteqta_control_jni_DMXControl_startDevice_1native (JNIEnv * env, jobject obj){
StartDevice();
}
/*
- Class: com_dyteqta_control_jni_DMXControl
- Method: stopDevice_native
- Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_dyteqta_control_jni_DMXControl_stopDevice_1native (JNIEnv * env, jobject jobj){
StopDevice();
}
/*
- Class: com_dyteqta_control_jni_DMXControl
- Method: setChannel_native
- Signature: (I)V
*/
JNIEXPORT void JNICALL Java_com_dyteqta_control_jni_DMXControl_setChannel_1native (JNIEnv * env, jobject jobj, jint count){
SetChannelCount(count);
}
/*
- Class: com_dyteqta_control_jni_DMXControl
- Method: setData_native
- Signature: (II)V
*/
JNIEXPORT void JNICALL Java_com_dyteqta_control_jni_DMXControl_setData_1native (JNIEnv * env, jobject jobj, jint channel, jint data){
SetData(channel, data);
}[/code]