1

私は次のVBコードをC#で何時間も実行しようとしています。Value does not fall within the expected range.CreateStroke()呼び出しで例外が発生し続けます。また、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());
4

1 に答える 1

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ビット整数型です。)

于 2010-01-10T21:34:48.460 に答える