Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

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:

 

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?

Chaos is merely logic beyond human comprehension
  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]
Posted
Thanks marble, I'll look into it. I never knew about the integer expansion - after all these years on dot net, I'm embarrased!
Chaos is merely logic beyond human comprehension

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...