Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create a C++ wrapper dll called by a java class

Status
Not open for further replies.

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 &quot;C&quot; {
#endif
/*
* Class: identification
* Method: checkLogin
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/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 &quot;jni.h&quot;
#include &quot;stdafx.h&quot;
#include &quot;resource.h&quot;
#include <initguid.h>
#include &quot;dWrapper.h&quot;
#include &quot;dlldatax.h&quot;
#include &quot;dWrapper_i.c&quot;

#ifdef _MERGE_PROXYSTUB
extern &quot;C&quot; 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(&quot;return&quot;);

}

**************************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
 
compille java classes with resulted .lib of your dll. Ion Filipski
1c.bmp


filipski@excite.com
 

be careful : your function Java_identification_essai is declared as a member of the CDWrapper class. So JNI can't find it. You should not use the C++ add function Wizzard but implement the fonction directly in the cpp code :

jstring Java_identification_checkLogin(JNIEnv *env, jobject obj, jstring sp1, jstring sp2, jstring strCode, jstring strMdp, jstring strConn)
{

return env->NewStringUTF(&quot;return&quot;);

}
and not :

jstring CDWrapperApp::Java_identification_checkLogin(JNIEnv *env, jobject obj, jstring sp1, jstring sp2, jstring strCode, jstring strMdp, jstring strConn)
{

return env->NewStringUTF(&quot;return&quot;);

}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top