public static void SetFuncPtrStructTestCallback(FuncPtrStructTest funcCallback, global::System.IntPtr userData) { Console.WriteLine("[SetFuncPtrStructTestCallback] Called C# Callback"); Console.WriteLine("================================================="); HandleRef strictHandle = FuncPtrStructTest.getCPtr(funcCallback); long address = strictHandle.Handle.ToInt64(); Console.WriteLine("callback structPtrFuncTest address int64 : {0}", address); IntPtr info = Marshal.StringToHGlobalAuto("csharp called"); funcCallback.Func1(info); funcCallback.Func2(989898); funcCallback.Func3("callback csharp func3!!"); byte[] testData = new byte[5]; funcCallback.GetFuncData(out testData, testData.Length); string testDataStr = System.Text.Encoding.UTF8.GetString(testData); Console.WriteLine("callback structPtrFuncTest testData : {0}", testDataStr); Console.WriteLine("================================================="); }
public static void Main() { Console.WriteLine("=========== Swig Default Test ==========="); int result = NativeCode.Fact(10); Console.WriteLine("fact : " + result); int result1 = NativeCode.MyMod(2, 5); Console.WriteLine("my_mode : " + result1); Console.WriteLine("=========== Swig Array Test ==========="); int[] source = { 1, 2, 3 }; int[] target = new int[source.Length]; NativeCode.MyArrayCopy(source, target, target.Length); Console.WriteLine("Contents of copy target array using default marshaling"); PrintArray(target); target = new int[source.Length]; NativeCode.myArrayCopyUsingFixedArrays(source, target, target.Length); Console.WriteLine("Contents of copy target array using fixed arrays"); PrintArray(target); target = new int[] { 4, 5, 6 }; NativeCode.MyArraySwap(source, target, target.Length); Console.WriteLine("Contents of arrays after swapping using default marshaling"); PrintArray(source); PrintArray(target); source = new int[] { 1, 2, 3 }; target = new int[] { 4, 5, 6 }; NativeCode.myArraySwapUsingFixedArrays(source, target, target.Length); Console.WriteLine("Contents of arrays after swapping using fixed arrays"); PrintArray(source); PrintArray(target); Console.WriteLine("=========== Swig Struct Test ==========="); TestInfo info = new TestInfo(); info.BuildingName = "shinagawa"; info.OfficeName = "jr office"; info.PersionName = "joso"; TextClient textClient = new TextClient("http://google.com", "english", info, TestType.TESTTYPEOK); string urlStr = NativeCode.GetTestString(textClient); Console.WriteLine("url string : " + urlStr); string language = NativeCode.GetTestLang(textClient); Console.WriteLine("language : " + language); Console.WriteLine("=========== Swig function pointer ==========="); FuncPtCallback callback = new FuncPtCallback(CallbackTest); NativeCode.TestExec("Called C Function pointer??", callback); FuncPtCallback callback1 = new FuncPtCallback(CallbackTest1); NativeCode.TestExec("No Problem Callback", callback1); FuncPtIntCallback intCallback = new FuncPtIntCallback(IntCallbackTest); NativeCode.SetCallback(intCallback); Console.WriteLine("=========== Swig struct with function pointer ==========="); FuncPtrStructTest structPtrFuncTest = new FuncPtrStructTest(); structPtrFuncTest.Func1 = Func1CallbackTest; structPtrFuncTest.Func2 = Func2CallbackTest; structPtrFuncTest.Func3 = Func3CallbackTest; structPtrFuncTest.GetFuncData = GetFuncDataCallbackTest; NativeCode.RegistFuncPtrStruct(structPtrFuncTest); NativeCode.CallStructFunc1(); NativeCode.CallStructFunc2(); NativeCode.CallStructFunc3(); NativeCode.CallStructGetFuncData(); FuncPtrTest funcPtrTest = new FuncPtrTest(); funcPtrTest.SetFuncPtrStructTest = SetFuncPtrStructTestCallback; NativeCode.RegistAndCallFuncPtrs(funcPtrTest); Console.WriteLine("=========== Int Array Struct Test ==========="); IntArrayStructTest intArrayStructTest = new IntArrayStructTest(); intArrayStructTest.Test1 = new int[] { 3, 5, 7, 8, 9, 10, 14, 25, 30 }; intArrayStructTest.Test2 = new int[] { 10, 35, 67, 89, 100 }; Console.WriteLine("intArrayStructTest Test1 : {0}", string.Join(",", intArrayStructTest.Test1)); Console.WriteLine("intArrayStructTest Test2 : {0}", string.Join(",", intArrayStructTest.Test2)); Console.WriteLine("intArrayStructTest Test1[3] : {0}", intArrayStructTest.Test1[3]); Console.WriteLine("intArrayStructTest Test2[4] : {0}", intArrayStructTest.Test2[4]); string[] names = new string[] { "james", "micle", "jonson" }; NativeCode.StringArrayTest(names, names.Length); Console.WriteLine("=========== Swig Test End ==========="); }