Click here to Skip to main content
15,886,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C++
#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.
Posted
Updated 6-Nov-14 22:25pm
v2
Comments
Richard MacCutchan 7-Nov-14 4:45am    
What error? Looking at that code I would not expect it even to compile.
Xiao Ling 10-Nov-14 0:58am    
Do you know which line the code crashed at? You'd better check null pointer before going to next step.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900