I should make use of com methods present in a 32-bit dll, on a 64-bit Java application.
My idea was to use JNI in order to use the dll methods.
I then tried to create a java class with native methods from which I then created the .h file to be used in C++. Java class with native method cpp file.
#include <jni.h>
#include "pfr_KCryptDll.h"
#include <windows.h>
#include <tchar.h>
#import "KCrypt.dll" raw_interfaces_only no_namespace
//typedef int (__GPESTDCALL *pFc_Transaction) (int, int);
typedef jstring(CALLBACK* pFc_Transaction) (jstring, jstring);
JNIEXPORT jstring JNICALL Java_pfr_KCryptDll_Encrypt (JNIEnv* env, jclass, jstring text, jstring key) {
pFc_Transaction lpfnDllFunc;
HRESULT hrReturnVal = NULL;
HINSTANCE dllHandle = NULL;
jstring result = NULL;
dllHandle = LoadLibrary(L"KCrypt.dll");
if (NULL != dllHandle)
{
lpfnDllFunc = (pFc_Transaction)GetProcAddress(dllHandle, "Encrypt");
if (NULL != lpfnDllFunc)
{
result = lpfnDllFunc(text, key);
}
else
{
HRESULT hrReturnValErr = ERROR_DELAY_LOAD_FAILED;
return text;
}
}
else
{
HRESULT hrReturnValErr = ERROR_DELAY_LOAD_FAILED;
return key;
}
FreeLibrary(dllHandle);
return result;
}
}
typedef jstring(CALLBACK* pfr_test) (jstring);
JNIEXPORT jstring JNICALL Java_pfr_KCryptDll_test(JNIEnv*, jclass, jstring input) {
return input;
}
int main(int argc, TCHAR* argv[]) {
}
I'm definitely doing something wrong, partly because I'm not that knowledgeable about these things. Could you by any chance help me and especially tell me if it is possible to use dll com methods from java.
Thank you very much.