[Mono-bugs] [Bug 57081][Wis] New - Problems with MarshalAs or/and InteropServices Function Table (Delegates)
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Thu, 15 Apr 2004 15:14:54 -0400 (EDT)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by ddmk@r66.ru.
http://bugzilla.ximian.com/show_bug.cgi?id=57081
--- shadow/57081 2004-04-15 15:14:54.000000000 -0400
+++ shadow/57081.tmp.29837 2004-04-15 15:14:54.000000000 -0400
@@ -0,0 +1,102 @@
+Bug#: 57081
+Product: Mono: Runtime
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity: 004 Four hours
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: ddmk@r66.ru
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Problems with MarshalAs or/and InteropServices Function Table (Delegates)
+
+Description of Problem:
+When Marhaling to native code of functions table error appears.
+
+source sample:
+
+//testdll.dll c++ source
+#include "stdio.h"
+
+#define _DLL_EXPORT extern "C" __declspec( dllexport )
+
+typedef void (__stdcall *call_back_type)();
+//typedef void (__cdecl *call_back_type)();
+struct TD
+{
+ int type;
+ call_back_type t;
+//here may be other functions
+};
+
+_DLL_EXPORT void* test(void *o,int i,TD t)
+{
+ printf("%x %d %d\n",(unsigned long)o,i,t.type);
+ t.t();
+ return o;
+}
+//end of testdll.dll source
+//test.exe C# source
+using System;
+using System.Runtime.InteropServices;
+namespace testch
+{
+ class Class1
+ {
+ [ StructLayout( LayoutKind.Sequential )]
+ public struct delegate_wrapper
+ {
+ public int type;
+ public delegate void CTest();
+ [MarshalAs(UnmanagedType.FunctionPtr)] public CTest Test;
+ static void WTest()
+ { Console.WriteLine("test"); }
+
+//here may be other functions with params...
+
+ internal delegate_wrapper(int _type)
+ {
+ type=_type;
+ Test=new CTest(WTest);
+ }
+ }
+
+ [DllImport("testdll.dll")]
+ public static extern void test(int a,int i,delegate_wrapper c);
+ [DllImport("testdll.dll",EntryPoint="test")]
+public static extern void test2(int a,int i,int
+ type,delegate_wrapper.CTest c);
+
+
+ static void Main(string[] args)
+ {
+ delegate_wrapper t=new delegate_wrapper(10);
+ test(10,5,t); //correct way but not work Under MONO and Portable.NET
+ //test2(10,5,t.type,t.Test);//Incorrect way but work anywhere
+ }
+ }
+}
+
+Actual Results:
+
+** ERROR **: cant marshal object as native type 26
+aborting...
+
+Expected Results:
+"
+a 5 10
+test
+"
+without exceptions and errors
+
+How often does this happen?
+everytime
+
+Additional Information:
+NO