public static object Box (void *ptr, Type type) { if (type == null) throw new ArgumentNullException ("type"); if (!type.IsPointer) throw new ArgumentException ("type"); Pointer res = new Pointer (); res.data = ptr; res.type = type; return res; }
// This method will box an pointer. We save both the // value and the type so we can access it from the native code // during an Invoke. public static unsafe Object Box(void *ptr,Type type) { if (type == null) throw new ArgumentNullException("type"); if (!type.IsPointer) throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),"ptr"); Pointer x = new Pointer(); x._ptr = ptr; x._ptrType = type; return x; }
// This method will box an pointer. We save both the // value and the type so we can access it from the native code // during an Invoke. public static unsafe Object Box(void *ptr,Type type) { if (type == null) throw new ArgumentNullException(nameof(type)); if (!type.IsPointer) throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),nameof(ptr)); Contract.EndContractBlock(); RuntimeType rt = type as RuntimeType; if (rt == null) throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"), nameof(ptr)); Pointer x = new Pointer(); x._ptr = ptr; x._ptrType = rt; return x; }
public static bool TestDynamicInvoke() { Console.Write("Testing dynamic invoke..."); { TestValueType t = new TestValueType { X = 123 }; Func <string, string> d = t.GiveX; string result = (string)d.DynamicInvoke(new object[] { "MyPrefix" }); if (result != "MyPrefix123") { return(false); } } { Func <int, TestValueType> d = TestValueType.MakeValueType; TestValueType result = (TestValueType)d.DynamicInvoke(new object[] { 789 }); if (result.X != 789) { return(false); } } { IFoo t = new ClassWithIFoo("Class"); Func <int, string> d = t.DoFoo; if ((string)d.DynamicInvoke(new object[] { 987 }) != "Class987") { return(false); } } { IFoo t = new StructWithIFoo("Struct"); Func <int, string> d = t.DoFoo; if ((string)d.DynamicInvoke(new object[] { 654 }) != "Struct654") { return(false); } } { Func <string, string, string> d = ExtensionClass.Combine; if ((string)d.DynamicInvoke(new object[] { "Hello", "World" }) != "HelloWorld") { return(false); } } { Func <string, string> d = "Hi".Combine; if ((string)d.DynamicInvoke(new object[] { "There" }) != "HiThere") { return(false); } } { Mutate <int> d = ClassWithByRefs.Mutate; object[] args = new object[] { 8 }; d.DynamicInvoke(args); if ((int)args[0] != 50) { return(false); } } { Mutate <string> d = ClassWithByRefs.Mutate; object[] args = new object[] { "Hello" }; d.DynamicInvoke(args); if ((string)args[0] != "HelloMutated") { return(false); } } unsafe { GetAndReturnPointerDelegate d = ClassWithPointers.GetAndReturnPointer; if (Pointer.Unbox(d.DynamicInvoke(new object[] { (IntPtr)8 })) != (void *)50) { return(false); } if (Pointer.Unbox(d.DynamicInvoke(new object[] { Pointer.Box((void *)9, typeof(void *)) })) != (void *)51) { return(false); } } #if false // This is hitting an EH bug around throw/rethrow from a catch block (pass is not set properly) unsafe { PassPointerByRefDelegate d = ClassWithPointers.PassPointerByRef; var args = new object[] { (IntPtr)8 }; bool caught = false; try { d.DynamicInvoke(args); } catch (ArgumentException) { caught = true; } if (!caught) { return(false); } } #endif Console.WriteLine("OK"); return(true); }
public static extern bool FindNextUrlCacheEntryEx( IntPtr hEnumHandle, IntPtr lpFirstCacheEntryInfo, ref uint lpdwFirstCacheEntryInfoBufferSize, Pointer lpGroupAttributes, Pointer pcbGroupAttributes, Pointer lpReserved);
/// <summary> /// 構造体CvAttrListの初期化 /// </summary> /// <param name="attr">(attribute_name,attribute_value)のペアからなる配列</param> /// <param name="next">属性リストの次の塊へのポインタ</param> /// <returns></returns> #else /// <summary> /// initializes CvAttrList structure /// </summary> /// <param name="attr">array of (attribute_name,attribute_value) pairs</param> /// <param name="next">pointer to next chunk of the attributes list</param> /// <returns></returns> #endif public static CvAttrList AttrList(string[] attr, Pointer<CvAttrList> next) { return new CvAttrList(attr, next); }
internal extern static void Outlet(ExternalPtr obj, int n, Pointer p);
internal extern static void AddInlet(ExternalPtr obj,ref Pointer f);
protected static void Send(Symbol sym,Pointer p) { Send(sym,new Atom(p)); }
protected void Outlet(int n,Pointer p) { Internal.Outlet(ptr,n,p); }
protected void AddInlet(ref Symbol s) { Internal.AddInlet(ptr, ref s); } // map to data member protected void AddInlet(ref Pointer p) { Internal.AddInlet(ptr,ref p); } // map to data member
private static void CallPointer(Pointer p) { External e = Internal.pass.ext; try { e.klass.m_pointer(e, p); } catch (Exception exc) { PostError(exc.ToString()); } }