我一直试图在C#中运行以下几个小时的VB代码。我一直在CreateStroke()调用上得到Value does not fall within the expected range.
异常。 此外,here也是带有C ++版本的Microsoft文档。
Option Explicit
Dim theInkCollector As InkCollector
Private Sub Form_Load()
Set theInkCollector = New InkCollector
theInkCollector.hWnd = Me.hWnd
theInkCollector.Enabled = True
//Create a set of three points, stored as x1, y1, x2, y2, x3, y3
//in an array of six Long elements, starting at index 0.
Dim ptStrokePoints(5) As Long
ptStrokePoints(0) = 200
ptStrokePoints(1) = 200
ptStrokePoints(2) = 400
ptStrokePoints(3) = 600
ptStrokePoints(4) = 900
ptStrokePoints(5) = 300
//The description value is an unused placeholder.
Dim theDescription As Variant
Dim theStroke As IInkStrokeDisp
Set theStroke = theInkCollector.Ink.CreateStroke(ptStrokePoints, theDescription)
End Sub
这就是我所拥有的:
MSINKAUTLib.InkCollector collector = new MSINKAUTLib.InkCollector();
collector.hWnd = (int)(this.Handle);
collector.Enabled = true;
long[] pts = new long[6];
pts[0] = 200;
pts[1] = 200;
pts[2] = 400;
pts[3] = 600;
pts[4] = 900;
pts[5] = 300;
collector.Ink.CreateStroke(pts, new object());
答案 0 :(得分:2)
这看起来像文档中的以下错误:
E_INVALIDARG - 无效的VARIANT类型(仅支持VT_ARRAY | VT_I4)。
C#long
类型是64位整数,因此您传递的是VT_ARRAY | VT_I8(不是VT_I4)。
将您的pts声明更改为:
int[] pts = new int[6];
你应该好好去。 (int是C#32位整数类型。)