Forum Stats

  • 3,827,633 Users
  • 2,260,801 Discussions
  • 7,897,323 Comments

Discussions

How Can I load third party dll in another dll and used in java native interface

I have one dll, I want to load that dll into java native interface but it was not working properly. so now i try to create new dll file and load existing dll into that new dll file and access method from existing dll . How Can i do this ??. Please help me.

Following code which i write in .c file

  #include "stdafx.h"

  #include <basetyps.h>

  #include <jni.h>

  #include "HelloPopup.h"

  #include <windows.h>

typedef int * (_stdcall * OPENCOM) (int ComPort);

HINSTANCE dllHandle;

int result;

/*

* Class: HelloPopup

* Method: OpenSerialPort

* Signature: (I)I

*/`enter code here`

JNIEXPORT jint JNICALL Java_HelloPopup_OpenSerialPortDll

  (JNIEnv * env, jobject obj, jint ComPort)

{

  OPENCOM pOpenCom ;

  dllHandle=LoadLibrary ("AlzData.dll");

  POpenCom = (OPENCOM) GetProcAddress (dllHandle, "OpenSerialPort");

  int * ret = (* pOpenCom) (ComPort);

  result=pOpenCom(ComPort);

  FreeLibrary (dllHandle);

  return result;

}

.. but when i call the method in java native interface i was got an error..So this code i am little bit confused about this code it is correct or not please help me.

Tagged:

Answers

  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge

    That isn't a java or jni question.

    There is nothing magic in java/jni that allows/prevents that.

    You should create a test app that has no java/jni in it and figure out how to dynamically load a dll (presumably what you are doing.)  A windows programming site can help with specifics.

    As a suggestion I would suggest that you do the following since it will help debugging problems.

    1. Determine the fully qualified path to the dll

    2. Use that

    3. If the dll fails to load then report that fully qualified path.

This discussion has been closed.