We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 132,097 times

Contents

Related Categories

Calling a C++ DLL from Visual Basic - Introduction

kconcept

Introduction

There have been projects I have been on in the past where there was certain functionality I needed but could not get from VB, or I had to do a complete workaround to get the functionality I could get from C++ very easily. In this tutorial I will show you how to create a C++ dll that you can call from VB. I figure instead of doing the norm, "HELLO WORLD", or "ADD NUMBER", routine I will show you how to resolve a domain name to an IP address and return that IP address back to VB, this is a little advanced for the beginner but if you have some C++ experience it wont be that bad.

For this example I will be using VC++ 6 so if you have that IDE then you will be right at home and in the case you do not use that IDE then just try to follow along and enjoy the ride!

Ok, you will first have to create a new dynamic link library project. After you create this project you will be prompted on what kind of DLL, just click empty.

After that is complete you will have to add the library ws2_32.lib to the project under project-> settings -> link -> object/modules library or the code below will not compile! Believe me when I tell you this as I had the fun of learning this the hard way and it was a nightmare.

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 kev@kbaseonline.com.

KBaseonline.com, your #1 stop to I.T. information! Tutorials, Tips, Articles and more!

Comments

  • Re: [1973] Calling a C++ DLL from Visual Basic

    Posted by joseluiscruz on 09 Jun 2008

    How do I get a longer String back to visual basic from my visual c++ dll ?

  • the code i looked for!!!!!!!!!!!!

    Posted by guerinik_khalil on 09 Dec 2005

    thank you very much for this code. It resolves all my problems and errors. khalil from france.

  • Terrific

    Posted by tank on 25 May 2005

    [blue] This program is very useful for me, you are very terrific. Thanks [/blue]

  • Posted by ChuckSomerville on 20 Apr 2005

    Hi Caripito,

    I guess what you need is to see if there's some VBA function to return the location of the current workbook. I don't use Excel/VBA hardly at all, so I'm not familiar with any such fun...

  • Posted by caripito on 20 Apr 2005

    Hey Chuck, thank you very much for answering me... I already know haow to add a DLL in Visual Basic, in fact I guess it is hte same as stand alone VB... I do this:

    Public Declare Convert Lib "Blue...