简体   繁体   中英

How to pass values to a function with pointer

I am new To C programming language. I have created a header file in java so that I can call C function from java. My problem is I don't know how to pass values to the method here is my C code.

_declspec(dllimport) HANDLE FAR PASCAL CPSC1900Connect(BYTE port, void *param);

JNIEXPORT jstring JNICALL Java_CPSE_CPSC1900Connect(JNIEnv * env, jclass hPrinter, jstring port, jstring param)
{
     HANDLE hMapFile = NULL;
     const char *str = (*env)->GetStringUTFChars(env, port, 0);
     const char *str2 = (*env)->GetStringUTFChars(env, param, 0);
     hMapFile = CPSC1900Connect((BYTE )str,&str2);
     (*env)->ReleaseStringUTFChars(env, port, str);
     (*env)->ReleaseStringUTFChars(env, param, str2);

     return param;
}

I need to call CPSC1900Connect(BYTE port, void *param) function and pass port and param respectively . How do I pass these values. Any correction from the above code is highly appreciated.

One possibility is calling another C function that will return the pointer value that you want and then you can pass that return value into other functions as needed. At the end of the day pointers (memory addresses) are just numbers so Java will be able to store it and use it in future JNI calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM