Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

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

4186fa9f-c458-447c-9689-168605dd980cNov 7 2014 — edited Nov 25 2014

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.

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 23 2014
Added on Nov 7 2014
1 comment
1,613 views