Guest_imported
New member
- Jan 1, 1970
- 0
david j. (Visitor) Aug 29, 2001
Hello everyone,
So far I've been unsuccessful to call a VB dll from java although I've followed the Sun's online tutorial ("writing a java program with native method" on java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.htm) and another tutorial provided by Sahir Shah Shibley ( Compilations are OK but when running identification.class i get this error message :
Exception in thread "main" java.lang.UnsatisfiedLinkError: verifLogin
at identification.verifLogin(Native Method)
at identification.main(identification.java:12)
Now here are the codes :
*****************identification.java************************
import java.io.*;
class identification {
public native String checkLogin(String sp1,String sp2,String strCode,String strMdp,String strConn);
static {
System.loadLibrary("dWrapper"
}
public static void main (String[] args){
String resultat = "";
identification id = new identification();
resultat = id.checkLogin("VerLogSelCode","VerLogSelStatNb","test","test","Provider=SQLOLEDB.1;.......etc;"
System.out.println("result : " + result);
}
}
*****************end of identification.java*****************
*****************identification.h***************************/* DO NOT EDIT THIS FILE - it is machine generated by Microsoft Visual C++*/
#include <jni.h>
/* Header for class identification */
#ifndef _Included_identification
#define _Included_identification
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: identification
* Method: checkLogin
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/StringLjava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_identification_checkLogin
(JNIEnv *, jobject, jstring, jstring, jstring, jstring, jstring);
#ifdef __cplusplus
}
#endif
#endif
********************end of identification.h*****************
*********************dWrapper.cpp***************************
// dallozWrapper.cpp : Implementation of DLL Exports.
#include "jni.h"
#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "dWrapper.h"
#include "dlldatax.h"
#include "dWrapper_i.c"
#ifdef _MERGE_PROXYSTUB
extern "C" HINSTANCE hProxyDll;
#endif
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()
class CDWrapperApp : public CWinApp
{
public:
JNIEXPORT jstring JNICALL Java_identification_checkLogin(JNIEnv *env, jobject obj, jstring sp1, jstring sp2, jstring strCode, jstring strMdp, jstring strConn);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDWrapperApp)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL
//{{AFX_MSG(CDWrapperApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CDWrapperApp, CWinApp)
//{{AFX_MSG_MAP(CDWrapperApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CDWrapperApp theApp;
BOOL CDWrapperApp::InitInstance()
{
#ifdef _MERGE_PROXYSTUB
hProxyDll = m_hInstance;
#endif
_Module.Init(ObjectMap, m_hInstance, &LIBID_DWRAPPERLib);
return CWinApp::InitInstance();
}
int CDWrapperApp::ExitInstance()
{
_Module.Term();
return CWinApp::ExitInstance();
}
/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
#ifdef _MERGE_PROXYSTUB
if (PrxDllCanUnloadNow() != S_OK)
return S_FALSE;
#endif
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
#ifdef _MERGE_PROXYSTUB
if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
return S_OK;
#endif
return _Module.GetClassObject(rclsid, riid, ppv);
}
/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
#ifdef _MERGE_PROXYSTUB
HRESULT hRes = PrxDllRegisterServer();
if (FAILED(hRes))
return hRes;
#endif
// registers object, typelib and all interfaces in typelib
return _Module.RegisterServer(TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
#ifdef _MERGE_PROXYSTUB
PrxDllUnregisterServer();
#endif
return _Module.UnregisterServer(TRUE);
}
jstring CDWrapperApp::Java_identification_checkLogin(JNIEnv *env, jobject obj, jstring sp1, jstring sp2, jstring strCode, jstring strMdp, jstring strConn)
{
return env->NewStringUTF("return"
}
**************************end of dWrapper.cpp***************
to end with I would add that identification.h, identification.class and dWrapper.dll are in the same folder.
Many Thanks for your help
Hello everyone,
So far I've been unsuccessful to call a VB dll from java although I've followed the Sun's online tutorial ("writing a java program with native method" on java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.htm) and another tutorial provided by Sahir Shah Shibley ( Compilations are OK but when running identification.class i get this error message :
Exception in thread "main" java.lang.UnsatisfiedLinkError: verifLogin
at identification.verifLogin(Native Method)
at identification.main(identification.java:12)
Now here are the codes :
*****************identification.java************************
import java.io.*;
class identification {
public native String checkLogin(String sp1,String sp2,String strCode,String strMdp,String strConn);
static {
System.loadLibrary("dWrapper"
}
public static void main (String[] args){
String resultat = "";
identification id = new identification();
resultat = id.checkLogin("VerLogSelCode","VerLogSelStatNb","test","test","Provider=SQLOLEDB.1;.......etc;"
System.out.println("result : " + result);
}
}
*****************end of identification.java*****************
*****************identification.h***************************/* DO NOT EDIT THIS FILE - it is machine generated by Microsoft Visual C++*/
#include <jni.h>
/* Header for class identification */
#ifndef _Included_identification
#define _Included_identification
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: identification
* Method: checkLogin
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/StringLjava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_identification_checkLogin
(JNIEnv *, jobject, jstring, jstring, jstring, jstring, jstring);
#ifdef __cplusplus
}
#endif
#endif
********************end of identification.h*****************
*********************dWrapper.cpp***************************
// dallozWrapper.cpp : Implementation of DLL Exports.
#include "jni.h"
#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "dWrapper.h"
#include "dlldatax.h"
#include "dWrapper_i.c"
#ifdef _MERGE_PROXYSTUB
extern "C" HINSTANCE hProxyDll;
#endif
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()
class CDWrapperApp : public CWinApp
{
public:
JNIEXPORT jstring JNICALL Java_identification_checkLogin(JNIEnv *env, jobject obj, jstring sp1, jstring sp2, jstring strCode, jstring strMdp, jstring strConn);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDWrapperApp)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL
//{{AFX_MSG(CDWrapperApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CDWrapperApp, CWinApp)
//{{AFX_MSG_MAP(CDWrapperApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CDWrapperApp theApp;
BOOL CDWrapperApp::InitInstance()
{
#ifdef _MERGE_PROXYSTUB
hProxyDll = m_hInstance;
#endif
_Module.Init(ObjectMap, m_hInstance, &LIBID_DWRAPPERLib);
return CWinApp::InitInstance();
}
int CDWrapperApp::ExitInstance()
{
_Module.Term();
return CWinApp::ExitInstance();
}
/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
#ifdef _MERGE_PROXYSTUB
if (PrxDllCanUnloadNow() != S_OK)
return S_FALSE;
#endif
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
#ifdef _MERGE_PROXYSTUB
if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
return S_OK;
#endif
return _Module.GetClassObject(rclsid, riid, ppv);
}
/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
#ifdef _MERGE_PROXYSTUB
HRESULT hRes = PrxDllRegisterServer();
if (FAILED(hRes))
return hRes;
#endif
// registers object, typelib and all interfaces in typelib
return _Module.RegisterServer(TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
#ifdef _MERGE_PROXYSTUB
PrxDllUnregisterServer();
#endif
return _Module.UnregisterServer(TRUE);
}
jstring CDWrapperApp::Java_identification_checkLogin(JNIEnv *env, jobject obj, jstring sp1, jstring sp2, jstring strCode, jstring strMdp, jstring strConn)
{
return env->NewStringUTF("return"
}
**************************end of dWrapper.cpp***************
to end with I would add that identification.h, identification.class and dWrapper.dll are in the same folder.
Many Thanks for your help