简体   繁体   中英

Calling a function in a header file

I want to know how to call a function in a header file.

For example..

example.h

#ifndef NPT_IMM32_H
#define NPT_IMM32_H

#ifndef NPT_API
    #ifdef  _THIS_IS_IMPLE_
        #define NPT_API     __declspec(dllexport)
    #else
        #define NPT_API     __declspec(dllimport)
    #endif 
#endif 

NPT_API char * __stdcall npt_GetVer();

I want to call npt_GerVer() function in calling.c JNI file

calling.c
#include <jni.h>
#include <stdio.h>
#include <stdbool.h>
#include <windows.h>

#include "example.h"

JNIEXPORT void JNICALL Java_FingerPrintJNI_GetVer(JNIEnv *env, jobject thisObj){
    // Here How to call the npt_GerVer() function ? 
    return;
}

As you can see, I want to call "npt_GerVer() function" in Java_FingerPrintJNI_GetVer function. How can I do that?

A function gets called in exactly the same way and manner, whether it is declared in a header file, or in the actual translation unit itself.

In this case:

npt_GetVer();

That's it. It doesn't matter where the function is declared, as long as its declared before it's use or reference.

The only requirement is that the header file gets included. During the preprocessing phase, all header files are logically inserted at their #include reference, as if the contents of the header file logically replace the #include statement. The end result is a single C++ translation unit.

If you were to manually replace all #include statements with the contents of the corresponding header files (mindful of conditional compilation, include guards, etc...) the end result will be exactly the same.

Your original question was tagged C++ , but you are referring to C ; however this applies equally well to C or C++ .

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