2 Replies - 58843 Views - Last Post: 28 May 2009 - 06:32 AM Rate Topic: -----

#1 meerpool   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-February 09

How to create a DLL using Visual Basic 6.0

Posted 06 February 2009 - 03:57 AM

I am developing an application using Visual Studio 2008 ("main program") and I need to call a solver code for non linear equation systems ("code") that has been written using Visual Basic 6.0.

I had some problems in translating the code from VB60 to the language implemented in VS2008, so I decided to compile the code in a DLL using VB60, and call it from the main program.

So, how can I do it? In particular, what have I to add to the code to make it suitable for DLL compiling, and to make it accessible from other applications? Then, how can I invoke properly the subs/function included in the DLL from the main program?

I tried to simply compile the code in VB60 as a "ActiveX DLL", declaring all subs and functions as "Public", but when I add the DLL as reference in the main program, Visual Studio answer:

"...could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component"

Thank you for your support!

Is This A Good Question/Topic? 0
  • +

Replies To: How to create a DLL using Visual Basic 6.0

#2 Martyr2   User is online

  • Programming Theoretician
  • member icon

Reputation: 5225
  • View blog
  • Posts: 14,005
  • Joined: 18-April 07

Re: How to create a DLL using Visual Basic 6.0

Posted 07 February 2009 - 12:36 PM

If you create a simple VB 6 ActiveX DLL project (leave it for now as the name Project1), you will be given a default class called "Class1" In this class if you create a function like so....

Public Function AddTwoNumbers(ByVal a As Integer, ByVal b As Integer)
	AddTwoNumbers = a + b
End Function

Then go to the File >> Make and save it as something like "add.dll" in your C:\ drive then you are all set on that end.

Now over in VB.NET you have to do a few things, first you have to create a declaration statement like so...

Declare Auto Function AddTwoNumbers Lib "c:\add.dll" (ByVal a As Integer, ByVal b As Integer) As Integer

Here we are telling VB.NET about a function we have defined called AddTwoNumbers and it is pointing where we put our dll. Notice that it is followed by the two parameters and return type of our original function in VB6.

Next we need to go to the project explorer, right click the name and add a reference. Click the browse tab in the window that pops up and select our "add.dll" from the c:\ folder.

In the solution explorer window you will see an icon at the top that says "Show all files". This will allow you to view the references folder. In there you will now see a reference to "Project1" which was the name of our project in VB6.

So using that reference we can write this in VB.NET...

' Get reference to our Class called Class1 through Project1
Dim ourclass As New Project1.Class1

' Create a variable to hold our result
Dim result As Integer

' Use our class instance to then call our function and pass it two numbers
result = ourclass.AddTwoNumbers(4, 5)

' Print out the result.

So after this you should see a messagebox pop up reading "9". That is there is all to it. We have created a VB6 DLL, declared it in VB.NET and referenced the class. We then called the method and we are golden.

Use this knowledge here to then build your other classes and their methods etc and you are on your way. Enjoy!

"At DIC we be VB6 DLL building code ninjas... DLL 'Damn Lousy Lesbian'. All the DLLs we build run off with men. Lame!" :snap:
Was This Post Helpful? 1
  • +
  • -

#3 ivqt4u   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-May 09

Re: How to create a DLL using Visual Basic 6.0

Posted 28 May 2009 - 06:32 AM

Hello Sir i realy thanks for your code but i want one more help from ur side i just want to know how to pass form's text value in dll using vb6 code
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1