Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Two Ways To Create A Dll(.dll) In Vb.net Part 1


6 replies to this topic

#1 Shadow_x21

    Newbie

  • Kontributors
  • Pip
  • 8 posts
  • Gender:Male
  • Location:Salinas, California

Posted 03 November 2008 - 12:18 AM

Note - I Used VB.net but I Think It Works The Same In Other Languages. Please Let Me Know If It Doesn't. Thanks


Hi Everybody, This Tutuorial Was Created By Shadow_x21 (_x21)

Part 1 - This Tutorial Will Show You How To:
    Create A Class Library [ Also Called A DLL(.dll) File ]

    Reference A Class Library In The Same Or Other Project
Advantages To Creating A DLL Is That You Can Reference It (Use It) In A .Net Framework Language(Visual Basic, C#, C++, ect.). This Means That You Can

Create A Procedure ( A Simple One That ) and Save It As A DLL, Create A New Project In Whatever Langage You Use and Use That Same Procedure.

Note: I Have Not Tried Referencing A DLL In Any Language Other Than VB.net. I Just Create A DLL And Use It In Other Projects With Visual Basic. I Have Heard
That You Can Reference A DLL In Other Language Like C# Though, So Hopefully That Is Correct.

* To Create A New Class Library(.dll) In VB.net Follow These Steps.

- 1( Start Visual Basic.
- 2(Goto Create Project(Create...)
- 3(Choose "Class Library" Instead Of Windows Application and Name It Whatever You Want (Something Related To Procedures That Your DLL Will Hold)


* Inside Of Your Class Create A Sample Procedure : You Can Use The Procedure Below If You Can't Think Of One Or If Your New To VB.NeT.

Public Class Class1

	Public Function Message(ByVal Msg As String) As Boolean 
		MsgBox(Msg.ToString)
	End Function

End Class


* Alright, I Created A Class Library Called "Sample" With A Class Called "Class1"
    - I Created A Function (Like A Sub) Called Message
    - I Added "ByVal Msg As String" Which Means I Declared A Variable Called Msg That Will Have A Value Of String/Text
    (English = ByValue Msg As Text : The Value Of Msg Equals Text/String)
    - The "As Boolean" After The Function Is Required So That The Function Will Work On All Levels
    - The "Msgbox(Msg.ToString)" Creates A MessageBox At Runtime (When The Program Runs) With The Value Of Msg
    I Use "ToString" Just In Case The String Contains Numbers(Integers) Or Other Characters
* Now To Save Your DLL Goto File > Save All and Then Choose Your Directory
After You Save Your Project You May Want To Build It To Ensure A Final Version(You Can Build It Again Later) Goto Build > Build "Name Of Your Project"

* It Is Important To Keep The Project That Was Used To Create Your DLL So You Can Edit It Later To Make Changes
* Also : Don't Move Your DLL Directly From It's Saved Folder. Instead Just Copy & Paste It Where You Want It

- Referencing A DLL(.dll) or Class Library

- Create A New Project And Choose "Windows Application" Instead Of A "Class Library"

( Now To Reference Your DLL, You Can Use The Same Project, An Exististing Project, or a New Project )


- In Visual Basic You Can Reference A DLL Two Ways
    First - Goto Project > Add Reference... ( A Window Shold Pop-Up. Goto Browse and Look In The "Debug" Or "Release" Folder )
    - Example URL/Path Of DLL
    "Documents\Visual Studio 2005\Projects\Sample\bin\Debug\Sample.dll"
    "Documents\Visual Studio 2005\Projects\Sample\bin\Release\Sample.dll"

    Second - You Can Also Double-Click On "My Project" In The"Solution Explorer" At The Right
    Go To "References" and Click "Add" Below The WhiteBox. Then Follow The Same Steps As The First
* Add One Button To Your Form
* Add One Textbox To Your Form

Now Double-Click Your Button and Use This Code To Reference The DLL You Made Earlier

* Your Code Should Look Somewhat Like The Code Below

Imports Sample

Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim Hi As New Sample.Class1
		Hi.Message(TextBox1.Text)
	End Sub
End Class



* What I Did Was Add A Button and Textbox To My Form. When The Button Is Pressed It Uses The Message Function,
Grabs The Text From The Textbox And Puts It In The MessageBox That Will Be Displayed.

* How It Works, Code Wise -
    - I Imported, as you can see, my project called "Sample". If Your Project Doesn't Show Up When You Type "Imports"
    - Then You Did Not Reference Your DLL Correctly or Your DLL Is Not Compatible (or you just screwed up your dll somehow)

    - Next I Accessed My Button's Click Event. Here I Wrote The Code That Will Be Run Using My "Message" Function As Created Earlier
    - Here I Created A Variable That Will Have The Value Of "Hi" As New Sample.Class1
    - For DLL's and Alot Of Other Functions (As You Will Find Out Later On In Your Coding Life) You Cannot Access There Events/Controls Directly
    You Have To Create A New Instance Of Them And Apply/Bind It To A Variable. Then You Can Access It's Events and Controls
    - Now, With The New Variable That I Have Defined, I Can Access Sample.Class1 Events Thus Allowing Me To Use The "Message" Function That I Created Earlier.
    - Remember When I Created The Variable "Msg" In My DLL Earlier. That Variable Was A Part Of The "Message" Function. "Msg's" Value Will Be Set To That
    Of The Textbox's Text. That Means When The "Message" Function Executes, Msg's Value Will Be The Textbox's Text. Then A MessageBox Will Appear Containing
    The Text In Textbox1.
Thank You For Reading This. Hopefully You Enjoyed and Understood It.

For ?'s and Comments Post It or E-Mail Me At Shadow21son@yahoo.com

EDIT - 11/10/07: I Took Out The Link To My Site Cause' It Sucks. I Might Put Back Up In A Week Or Two.

Part 2 Will Be Out Soon... :lol: It Will Show You Another Way To Create A DLL (I Use This Way More. It's Better For What I Do)

Edited by Shadow_x21, 11 November 2008 - 03:49 AM.


#2 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 08 July 2009 - 01:28 PM

Two Ways To Create A Dll(.dll) In Vb.net Part 1 - Shows You How Reference and Create A DLL Part 1Two Ways To Create A Dll(.dll) In Vb.net Part 1

Great post. It allowed me to find the problem with my first dll project very fast. Thanks for the post.

-reply by Tony StancilKeywords: creat dll in vb.net

#3 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 10 August 2009 - 12:20 PM

how to add two class in a dllTwo Ways To Create A Dll(.dll) In Vb.net Part 1

how can I include two classes in a third class file. After this I will use the dll of third class which also includes the first and second class.Is it possible if yes than do tell me please

-question by supriya

#4 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 22 October 2009 - 01:00 PM

@ SupriyaTwo Ways To Create A Dll(.dll) In Vb.net Part 1

I beleive this is possible but the OOP method of encapsulation would be required.

 you shoul be able to hard code a second class right into the one code file perhaps like this:

Public Class fatherPublic name as string

  Public Class progeny   public name, gender as string   End Class

private child1 as new progeny

public sub dysplay

msgbox(name & " has a child. The first child is " & child1.Name & " who is a "& child1.Gender)

end sub

End Class

This could be simply used by the following:

Public Class Form1

Imports father

dim dad as new father

public sub main

dad.Name = "richard"Dad.Child1.Name = "hanna"Dad.Child1.Gender = "girl"

dad.Dysplay

end sub

End Class

 Well I may not be right but I think atleast the basic idea is correct, anyways.

Thanks a heap shadow the information on making and using dll's is scarce and scattered but this is very simple and oh-so needed, ive learned alot.

 Thanks   Nekroze

-reply by Nekroze

#5 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 12 January 2010 - 02:21 AM

This is good. But what does VB use when it calls the dll? Is it a compile time implicit link or a runtime explicit link using getprocaddress? VB always shields the user from these types of things, which is a Good Thing!

 Here is a C++ article with explicit and implicit linking. I'm just trying to reconcile my VB knowledge with C++

Simple Windows C++ DLL Example with Implicit and Explicit Calls

 

 

-reply by iresha

#6 Guest_Shav_*

  • Guests

Posted 31 January 2011 - 09:10 PM

Thank you so much!!
I am new to VB.net and you xplained it just so simple.

I created my first .dll !! Woooohoooo!!


View PostShadow_x21, on 03 November 2008 - 12:18 AM, said:

Note - I Used VB.net but I Think It Works The Same In Other Languages. Please Let Me Know If It Doesn't. Thanks


Hi Everybody, This Tutuorial Was Created By Shadow_x21 (_x21)

Part 1 - This Tutorial Will Show You How To:
    Create A Class Library [ Also Called A DLL(.dll) File ]

    Reference A Class Library In The Same Or Other Project
Advantages To Creating A DLL Is That You Can Reference It (Use It) In A .Net Framework Language(Visual Basic, C#, C++, ect.). This Means That You Can

Create A Procedure ( A Simple One That ) and Save It As A DLL, Create A New Project In Whatever Langage You Use and Use That Same Procedure.

Note: I Have Not Tried Referencing A DLL In Any Language Other Than VB.net. I Just Create A DLL And Use It In Other Projects With Visual Basic. I Have Heard
That You Can Reference A DLL In Other Language Like C# Though, So Hopefully That Is Correct.

* To Create A New Class Library(.dll) In VB.net Follow These Steps.

- 1( Start Visual Basic.
- 2(Goto Create Project(Create...)
- 3(Choose "Class Library" Instead Of Windows Application and Name It Whatever You Want (Something Related To Procedures That Your DLL Will Hold)


* Inside Of Your Class Create A Sample Procedure : You Can Use The Procedure Below If You Can't Think Of One Or If Your New To VB.NeT.

Public Class Class1

	Public Function Message(ByVal Msg As String) As Boolean 
		MsgBox(Msg.ToString)
	End Function

End Class


* Alright, I Created A Class Library Called "Sample" With A Class Called "Class1"
    - I Created A Function (Like A Sub) Called Message
    - I Added "ByVal Msg As String" Which Means I Declared A Variable Called Msg That Will Have A Value Of String/Text
    (English = ByValue Msg As Text : The Value Of Msg Equals Text/String)
    - The "As Boolean" After The Function Is Required So That The Function Will Work On All Levels
    - The "Msgbox(Msg.ToString)" Creates A MessageBox At Runtime (When The Program Runs) With The Value Of Msg
    I Use "ToString" Just In Case The String Contains Numbers(Integers) Or Other Characters
* Now To Save Your DLL Goto File > Save All and Then Choose Your Directory
After You Save Your Project You May Want To Build It To Ensure A Final Version(You Can Build It Again Later) Goto Build > Build "Name Of Your Project"

* It Is Important To Keep The Project That Was Used To Create Your DLL So You Can Edit It Later To Make Changes
* Also : Don't Move Your DLL Directly From It's Saved Folder. Instead Just Copy & Paste It Where You Want It

- Referencing A DLL(.dll) or Class Library

- Create A New Project And Choose "Windows Application" Instead Of A "Class Library"

( Now To Reference Your DLL, You Can Use The Same Project, An Exististing Project, or a New Project )


- In Visual Basic You Can Reference A DLL Two Ways
    First - Goto Project > Add Reference... ( A Window Shold Pop-Up. Goto Browse and Look In The "Debug" Or "Release" Folder )
    - Example URL/Path Of DLL
    "Documents\Visual Studio 2005\Projects\Sample\bin\Debug\Sample.dll"
    "Documents\Visual Studio 2005\Projects\Sample\bin\Release\Sample.dll"

    Second - You Can Also Double-Click On "My Project" In The"Solution Explorer" At The Right
    Go To "References" and Click "Add" Below The WhiteBox. Then Follow The Same Steps As The First
* Add One Button To Your Form
* Add One Textbox To Your Form

Now Double-Click Your Button and Use This Code To Reference The DLL You Made Earlier

* Your Code Should Look Somewhat Like The Code Below

Imports Sample

Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim Hi As New Sample.Class1
		Hi.Message(TextBox1.Text)
	End Sub
End Class



* What I Did Was Add A Button and Textbox To My Form. When The Button Is Pressed It Uses The Message Function,
Grabs The Text From The Textbox And Puts It In The MessageBox That Will Be Displayed.

* How It Works, Code Wise -
    - I Imported, as you can see, my project called "Sample". If Your Project Doesn't Show Up When You Type "Imports"
    - Then You Did Not Reference Your DLL Correctly or Your DLL Is Not Compatible (or you just screwed up your dll somehow)

    - Next I Accessed My Button's Click Event. Here I Wrote The Code That Will Be Run Using My "Message" Function As Created Earlier
    - Here I Created A Variable That Will Have The Value Of "Hi" As New Sample.Class1
    - For DLL's and Alot Of Other Functions (As You Will Find Out Later On In Your Coding Life) You Cannot Access There Events/Controls Directly
    You Have To Create A New Instance Of Them And Apply/Bind It To A Variable. Then You Can Access It's Events and Controls
    - Now, With The New Variable That I Have Defined, I Can Access Sample.Class1 Events Thus Allowing Me To Use The "Message" Function That I Created Earlier.
    - Remember When I Created The Variable "Msg" In My DLL Earlier. That Variable Was A Part Of The "Message" Function. "Msg's" Value Will Be Set To That
    Of The Textbox's Text. That Means When The "Message" Function Executes, Msg's Value Will Be The Textbox's Text. Then A MessageBox Will Appear Containing
    The Text In Textbox1.
Thank You For Reading This. Hopefully You Enjoyed and Understood It.

For ?'s and Comments Post It or E-Mail Me At Shadow21son@yahoo.com

EDIT - 11/10/07: I Took Out The Link To My Site Cause' It Sucks. I Might Put Back Up In A Week Or Two.

Part 2 Will Be Out Soon... :lol: It Will Show You Another Way To Create A DLL (I Use This Way More. It's Better For What I Do)


#7 Guest_ninja_*

  • Guests

Posted 23 November 2011 - 10:58 AM

excellent for beginner like me :) :) simply and easy to understand.
Thanks very much




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users