Sebastiaan
Sebastiaan

Reputation: 432

vb dll strange output in C#

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

RESULTS

Int_A = 12884901888
Int_B = 25

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;");
}

RESULTS

A = 579780113483169791
B = 4294967292

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

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

The dll is in Dephi, and should give the same output

Upvotes: 0

Views: 285

Answers (2)

user240141
user240141

Reputation:

If using 4.0, then u can try this. Not sure but might help. Use dynamic keyword.

dynamic comInterop= Activator.CreateInstance(Type.GetTypeFromProgID("MyCOM.Object.Name"));
var result = comInterop.MethodCall(parameter);

Upvotes: 0

SLaks
SLaks

Reputation: 887415

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

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

Upvotes: 2

Related Questions