gpt4 book ai didi

c# - 帮助我将以下 VB/C++ 代码转换为 C#

转载 作者:行者123 更新时间:2023-11-30 04:39:43 25 4
gpt4 key购买 nike

几个小时以来,我一直在尝试让以下 VB 代码在 C# 中运行。我不断收到 CreateStroke() 调用的 Value does not fall in 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());

最佳答案

这看起来像文档中的以下错误:

E_INVALIDARG - Invalid VARIANT type (only VT_ARRAY | VT_I4 supported).

C# long 类型是一个 64 位整数,因此您要传递一个 VT_ARRAY | VT_I8(不是 VT_I4)。

将您的 pts 声明更改为:

int[] pts = new int[6];

你应该可以开始了。 (int 是 C# 32 位整数类型。)

关于c# - 帮助我将以下 VB/C++ 代码转换为 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2038704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com