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
如何用C#而不是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;");
}
结果
我写了这个C#代码,但输出不一样,怎么解决这个?A = 579780113483169791
B = 4294967292
当我将long改为int时,结果是a = -1 b = 4 ....
dll在Dephi中,应该提供相同的输出
答案 0 :(得分:2)
将string
参数更改为ref string
s(以匹配VB.Net的ByRef
)
调用函数时,您需要传递ref
字符串变量。
答案 1 :(得分:0)
如果使用4.0,那么你可以试试这个。不确定,但可能有所帮助。使用动态关键字。
dynamic comInterop= Activator.CreateInstance(Type.GetTypeFromProgID("MyCOM.Object.Name"));
var result = comInterop.MethodCall(parameter);