static void MarshalOneArg(ParamDescriptor param, object arg, IntPtr buffer) { string msg; if (param.flags != TypeInfo.ParamFlags.In) { msg = String.Format("{0} is {1} (only In " + "supported)", param.Name(), param.flags.ToString()); throw new Exception(msg); } TypeInfo.TypeDescriptor type = param.type; if ((type.flags & TypeFlags.Reference) != 0) { if ((type.flags & TypeFlags.Pointer) == 0) { throw new Exception("TD is Reference but " + "not Pointer?! (" + param.ToString() + ")"); } if (arg == null) { throw new Exception(param.Name() + ": null passed as arg for " + "Reference param"); } } if (type.IsScalar()) { XPTCVariant variant = new XPTCVariant(); variant.type = type; variant.flags = 0; variant.ptr = IntPtr.Zero; Marshal.StructureToPtr(variant, buffer, false); IntPtr p; switch (type.tag) { case TypeTag.Int8: case TypeTag.Int16: case TypeTag.Int32: case TypeTag.UInt8: case TypeTag.UInt16: case TypeTag.UInt32: case TypeTag.Char: case TypeTag.WChar: Marshal.WriteInt32(buffer, (Int32)arg); break; case TypeTag.UInt64: case TypeTag.Int64: Marshal.WriteInt64(buffer, (Int64)arg); break; case TypeTag.Bool: bool b = (bool)arg; Marshal.WriteInt32(buffer, b ? 1 : 0); break; case TypeTag.Float: float[] f = new float[] { (float)arg }; Marshal.Copy(f, 0, buffer, 1); break; case TypeTag.Double: double[] d = new double[] { (double)arg }; Marshal.Copy(d, 0, buffer, 1); break; case TypeTag.String: Marshal.WriteIntPtr(buffer, Marshal.StringToCoTaskMemAnsi((string)arg)); break; case TypeTag.WString: Marshal.WriteIntPtr(buffer, Marshal.StringToCoTaskMemUni((string)arg)); break; default: msg = String.Format("{0}: type {1} not supported", param.Name(), type.tag.ToString()); throw new Exception(msg); } Console.WriteLine("{0} @ {1:X2}", param.Name(), buffer.ToInt32()); return; } if (type.tag == TypeTag.Interface) { Guid iid = param.GetIID(); Console.WriteLine("{0} is interface {1}", param.Name(), iid); Marshal.WriteIntPtr(buffer, CLRWrapper.Wrap(arg, ref iid)); Console.WriteLine("{0} @ {1:X2}", param.Name(), buffer.ToInt32()); return; } msg = String.Format("{0} type {1} not yet supported ", param.Name(), type.tag.ToString()); throw new Exception(msg); }