C#中的vb dll奇怪的输出 [英] vb dll strange output in C#

查看:40
本文介绍了C#中的vb dll奇怪的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Module Module1
    Public Declare Function GET_CALCULATION_FAN_ALONE Lib "EbmPapstFan.dll" (ByRef path As String) As Long
    Private Declare Function GET_PRODUCTS Lib "ebmpapstfan.dll" (ByRef path As String) As Long
    Public Declare Function SET_XML_PATH Lib "EbmPapstFan.dll" (ByRef path As String) As Long

    Sub Main()
        Dim Int_A As Long, Int_B As Long Str_Antwort As String, Str_Input As String
        Str_Input = "C:\Users\Sebastiaan\AppData\Local\ebmpapst\Product_selector_2011\Data\Fans\"
        Int_A = SET_XML_PATH(Str_Input)
        Int_B = GET_PRODUCTS("114709;A3G800AV0101;")

    End Sub

End Module

结果

Int_A = 12884901888
Int_B = 25

Int_A = 12884901888
Int_B = 25

如何用 C# 而不是 VB 重写这段代码?

How to rewrite this code in C# instead of VB?

[DllImport("EbmPapstFan.dll")]
public static extern long SET_XML_PATH(String path);

[DllImport("EbmPapstFan.dll")]
static extern long GET_CALCULATION_FAN_ALONE(String fanDescription);

[DllImport("EbmPapstFan.dll")]
public static extern long GET_PRODUCTS(String fanDescription);

static void Main(string[] args)
{
    long a = SET_XML_PATH(@"C:\Users\Sebastiaan\AppData\Local\ebmpapst\Product_selector_2011\Data\Fans\");
    long b = GET_PRODUCTS("114709;A3G800AV0101;");
}

结果

A = 579780113483169791
B = 4294967292

A = 579780113483169791
B = 4294967292

我写了这个 C# 代码,但输出不一样,如何解决这个问题?

i wrote this C# code but the output is not the same, how to solve this?

当我将 long 更改为 int 时,结果为 a = -1 b = 4....

when i change long to int the resuls are a = -1 b = 4....

dll 在 Dephi 中,应该给出相同的输出

The dll is in Dep and should give the same output

推荐答案

string 参数更改为 ref strings(以匹配 VB.Net 的 ByRef)

Change the string parameters to ref strings (to match VB.Net's ByRef)

调用函数时需要传递一个ref字符串变量.

You will need to pass a ref string variable when calling the functions.

这篇关于C#中的vb dll奇怪的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆