紫衣仙女
先写一个java类,Java代码:1234567891011121314package com.ypoj.jni; public class TestJNI { public native int add(int a, int b); static { System.loadLibrary("CallCS"); } public static void main(String[] args) { TestJNI t = new TestJNI(); System.out.println(t.add(10, 20)); } }用javah生成的com_ypoj_jni_TestJNI.h,Cpp代码: 123456789101112#include #ifndef _Included_com_ypoj_jni_TestJNI #define _Included_com_ypoj_jni_TestJNI #ifdef __cplusplus extern "C" { #endif JNIEXPORT jint JNICALL Java_com_ypoj_jni_TestJNI_add (JNIEnv *, jobject, jint, jint); #ifdef __cplusplus } #endif #endif接下来先完成C#的 Dll,C#代码:1234567891011121314151617using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace OJMain { public class OJEntrance { private int result; public int Result { get { return result + 10; } set { this.result = value; } } } }