E
Eric B
Hello,
I'm looking for an example of code which shows how to use an existing
VB dll with C#.
So far, many posts that I have looked through simply talk about
problems dealing with issues like "cannot convert from 'ref string' to
'ref object'". But what I'm looking for is an actual working example.

Lets just say I have a fake dll named A.dll with a function named
Test().
Function Test(ByVal arg1 As Variant, ByRef arg2 As Variant) As Variant
Dim strParam2 as String
On Error GoTo Error
If arg1 = "1" Then
strParam2 = "One"
Else
strParam2 = "Whatever Value"
End If
arg2 = strParam2
Test = 0
Exit Function
Error:
Test = -1
End Function
I know arg1 and arg2 have to be passed in as an object because they
are declared as Variant, but what about the return value of Test.
Note: Both arguments will be eventually converted to string.
What would be the code to get the value of arg2, as well as int for
function Test()?
Just so you know, I have tried to create what seems to be a pretty
simple example of this but was unable to get it working. It compiles
fine, but when the code is executed I keep getting an: "Unable to find
an entry point named Test in DLL A.dll" message.
I'm using the line: [DllImport("A.dll",EntryPoint="Test")].
What does this mean?
I should mention that I do not want to change existing dlls to work
with C# unless absolutely necessary.
Thanks in advance,
Eric B
I'm looking for an example of code which shows how to use an existing
VB dll with C#.
So far, many posts that I have looked through simply talk about
problems dealing with issues like "cannot convert from 'ref string' to
'ref object'". But what I'm looking for is an actual working example.

Lets just say I have a fake dll named A.dll with a function named
Test().
Function Test(ByVal arg1 As Variant, ByRef arg2 As Variant) As Variant
Dim strParam2 as String
On Error GoTo Error
If arg1 = "1" Then
strParam2 = "One"
Else
strParam2 = "Whatever Value"
End If
arg2 = strParam2
Test = 0
Exit Function
Error:
Test = -1
End Function
I know arg1 and arg2 have to be passed in as an object because they
are declared as Variant, but what about the return value of Test.
Note: Both arguments will be eventually converted to string.
What would be the code to get the value of arg2, as well as int for
function Test()?
Just so you know, I have tried to create what seems to be a pretty
simple example of this but was unable to get it working. It compiles
fine, but when the code is executed I keep getting an: "Unable to find
an entry point named Test in DLL A.dll" message.
I'm using the line: [DllImport("A.dll",EntryPoint="Test")].
What does this mean?
I should mention that I do not want to change existing dlls to work
with C# unless absolutely necessary.
Thanks in advance,
Eric B