Originally Posted by
GregBrannon
Can you post a simple, short example that demonstrates what you're trying to do? Through imports or by proximity (on the CLASSPATH or in the same project/folder), what you propose should be very simple, so it's difficult to say why you're having problems without an example.
//HelloNative.c
#include "HelloNative.h"
#include <stdio.h>
#include <iostream>
using std::cout;
using std::endl;
int c = 0;
JNIEXPORT void JNICALL Java_HelloNative_greeting(JNIEnv * env, jclass cl)
{
printf("Hello Java and C function calling!\n");
cout << c << ": This is about calling a C++ native function..." << endl;
cout << c << ": Just another line..." << endl;
cout << c++ << ": This is C++." << endl;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
//HelloNative.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloNative */
#ifndef _Included_HelloNative
#define _Included_HelloNative
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloNative
* Method: greeting
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloNative_greeting
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
////////////////////////////////////////////////////////////////
//HelloNative.java
public class HelloNative {
/**
* @param args
*/
public static native void greeting();
static
{
System.loadLibrary("HelloNative");
}
}
////////////////////////////////////////////////////////////
//HelloNativeTest.java
import javax.swing.JOptionPane;
public class HelloNativeTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
for(int i = 0;i<10; ++i){
HelloNative.greeting();
}
//JOptionPane.showMessageDialog(null,"Are you OK?");
}
}
//DONE