Linking a VS6 dll to a .NET application

CryoEnix

Regular
Joined
Jan 11, 2003
Messages
93
Location
Wrexham, Wales
Hey all, I'm just getting to grips with Visual C++ from VS6 at the moment as it's the fastest language I've seen so far, and I'm attempting to create a 'test dll' with it before I write my application.

The test dll contains a simple 'sum' function that returns two numbers added together, and it will link perfectly in VB6 with this code:

Code:
Private Declare Function sum Lib "example1.dll" (ByVal x As Long, ByVal y As Long) As Long


Private Sub Command1_Click()
    lblanswer.Caption = Str(sum(CInt(Text1.Text), CInt(Text2.Text)))
End Sub

However, when using VB 2005.NET:

Code:
Public Class Form1
    Private Declare Function sum Lib "example1.dll" (ByVal x As Long, ByVal y As Long) As Long


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox(sum(CInt(1), CInt(2)))
    End Sub
End Class

I get a BadImageFormatException error on the MsgBox line - is this a compatability issue, and how can it be overcome?
 
Dotnet might be more finicky than VB6. Also, remember that a Long in VB6 is an Integer in VB.Net.

You might want to look around for some tutorials for this. I'm sure you've already read at least one or two, but they might have missed a detail that VB6 tolerated, and there are plenty of them out there so you can cross reference them.
 
Back
Top