/// <summary> /// Marshal our data to the UIAutomationMethodInfo struct. /// </summary> private void Build() { // Copy basic data _data = new UIAutomationMethodInfo { pProgrammaticName = _programmaticName, doSetFocus = _doSetFocus ? 1 : 0, cInParameters = (uint)_inParamNames.Count, cOutParameters = (uint)_outParamNames.Count }; var cTotalParameters = _data.cInParameters + _data.cOutParameters; // Allocate parameter lists and populate them if (cTotalParameters > 0) { _data.pParameterNames = Marshal.AllocCoTaskMem((int)(cTotalParameters * Marshal.SizeOf(typeof(IntPtr)))); _data.pParameterTypes = Marshal.AllocCoTaskMem((int)(cTotalParameters * Marshal.SizeOf(typeof(Int32)))); var namePointer = _data.pParameterNames; var typePointer = _data.pParameterTypes; for (var i = 0; i < _data.cInParameters; ++i) { Marshal.WriteIntPtr(namePointer, _inParamNames[i]); namePointer = (IntPtr)(namePointer.ToInt64() + Marshal.SizeOf(typeof(IntPtr))); Marshal.WriteInt32(typePointer, (int)_inParamTypes[i]); typePointer = (IntPtr)(typePointer.ToInt64() + Marshal.SizeOf(typeof(Int32))); } for (var i = 0; i < _data.cOutParameters; ++i) { Marshal.WriteIntPtr(namePointer, _outParamNames[i]); namePointer = (IntPtr)(namePointer.ToInt64() + Marshal.SizeOf(typeof(IntPtr))); Marshal.WriteInt32(typePointer, (int)_outParamTypes[i]); typePointer = (IntPtr)(typePointer.ToInt64() + Marshal.SizeOf(typeof(Int32))); } } else { _data.pParameterNames = IntPtr.Zero; _data.pParameterTypes = IntPtr.Zero; } _built = true; }
/// <summary> /// Marshal our data to the UIAutomationMethodInfo struct. /// </summary> private void Build() { // Copy basic data _data = new UIAutomationMethodInfo { pProgrammaticName = _programmaticName, doSetFocus = _doSetFocus ? 1 : 0, cInParameters = (uint)_inParamNames.Count, cOutParameters = (uint)_outParamNames.Count }; var cTotalParameters = _data.cInParameters + _data.cOutParameters; // Allocate parameter lists and populate them if (cTotalParameters > 0) { _data.pParameterNames = Marshal.AllocCoTaskMem((int)(cTotalParameters*Marshal.SizeOf(typeof(IntPtr)))); _data.pParameterTypes = Marshal.AllocCoTaskMem((int)(cTotalParameters*Marshal.SizeOf(typeof(Int32)))); var namePointer = _data.pParameterNames; var typePointer = _data.pParameterTypes; for (var i = 0; i < _data.cInParameters; ++i) { Marshal.WriteIntPtr(namePointer, _inParamNames[i]); namePointer = (IntPtr)(namePointer.ToInt64() + Marshal.SizeOf(typeof(IntPtr))); Marshal.WriteInt32(typePointer, (int)_inParamTypes[i]); typePointer = (IntPtr)(typePointer.ToInt64() + Marshal.SizeOf(typeof(Int32))); } for (var i = 0; i < _data.cOutParameters; ++i) { Marshal.WriteIntPtr(namePointer, _outParamNames[i]); namePointer = (IntPtr)(namePointer.ToInt64() + Marshal.SizeOf(typeof(IntPtr))); Marshal.WriteInt32(typePointer, (int)_outParamTypes[i]); typePointer = (IntPtr)(typePointer.ToInt64() + Marshal.SizeOf(typeof(Int32))); } } else { _data.pParameterNames = IntPtr.Zero; _data.pParameterTypes = IntPtr.Zero; } _built = true; }