c# - Converting some VB.NET code to C# - Need Advice
问题描述
I am working with the original MMO that ever opened called VZones and they have a dll file that allows you to call the functions from this dll to do certain things within the program.
I have found some VB.NET code and the problem I am having is converting it to a way that will work with C# (using VS 2017)
You setup the DLL calls with this, which works fine:
[DllImport("vzdapi.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern string DapiGetText(string BufferIn, int LengthIn, int Timeout);
The problem is I need to convert this VB.NET code that is from someone else to what will work in C#. I have tried a few different options but the program just closes and never gives me an error.
object obj1 = (object)new string(char.MinValue, 32678);
vzText.Text = this.DapiGetText(Conversions.ToString(obj1), Strings.Len(RuntimeHelpers.GetObjectValue(obj1)), 1500);
The problem arises in the Conversions.ToString part, which I have of course tried to just make obj1.ToString() and that may work fine but the place I think is getting caught up is when it tries to run the middle code "Strings.Len(RuntimeHelpers.GetObjectValue(obj1))".
Does anyone have any help into getting this into something that will work in C#? Thanks!
解决方案
我想知道是否有必要进行转换,因为您定义的初始对象已经是一个字符串,请尝试以下解决方案:
string obj = new string(char.MinValue, Int16.MaxValue);
vzText.Text = this.DapiGetText(obj, obj.Length, 1500);
推荐阅读
- python - 火车测试验证拆分python中的非重叠数据
- reactjs - React 没有渲染 UI 中的所有元素
- php - 我们如何检查数据库中是否不存在密码?
- spring-boot - 尝试使用 GCP 模拟器发布到主题时出错
- ios - 使用 UIScrollView 仅向左滑动
- javascript - 在这个依赖注入的例子中,控制反转出现在哪里?
- python - 如何让我的机器人更快地弹奏钢琴拼贴?
- reactjs - 无法读取 AOS 动画中未定义的属性“类型”
- python - Python中的共现矩阵仅给出两列
- html - Flask: BadRequestKeyError: 400 Bad Request: 浏览器(或代理)发送了一个服务器无法理解的请求