Calling a C++ DLL from Visual Basic

The VB Code

This is the easiest part of the demonstration so I wont go into detail as it is pretty much self explanatory.

Private Declare Function Resolve_Name_To_Ip _
      Lib "[Add the path to the dll you just compiled]" _
                     (ByVal pcDomainToResolve As String, _
                     ByVal szReturnIP As String, _
                     ByRef iSize As Integer) As Long
                     
Private Sub Form_Load()

  Dim sIP As String
  Dim iSize As Integer
  Dim lRetVal As Long
  Dim sDomain As String
    
    sDomain = "www.yahoo.com"
    sIP = String(20, "*")
    lRetVal = Resolve_Name_To_Ip(sDomain, sIP, iSize)
    MsgBox (Mid(sIP, 1, iSize))

End Sub

Well that just about wraps it up, but again, and I cannot stress it enough that if you run into trouble compiling the DLL make sure you have included the ws2_32.lib library in the project as explained above or you will get a ton of errors.

If you ever receive errors like, "error LNK2001: unresolved external symbol", you are most likely missing a required library. Just go ahead and add the missing library to the project and you will be good to go.

I hope this has helped you out!

You might also like...

Comments

About the author

Kevin Saitta United States

Kevin Saitta is an independent Database/Programming consultant specializing in full life cycle development and database design. You can contact Kevin through the Internet at [email protected].

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perl - The only language that looks the same before and after RSA encryption.” - Keith Bostic