Creating a DLL

  • (2 Pages)
  • +
  • 1
  • 2

28 Replies - 1396 Views - Last Post: 01 December 2018 - 08:55 AM Rate Topic: -----

#16 andrewsw   User is offline

  • dependency injected
  • member icon

Reputation: 6668
  • View blog
  • Posts: 27,308
  • Joined: 12-December 12

Re: Creating a DLL

Posted 28 November 2018 - 09:51 AM

PiratePete It is not always necessary to quote a previous post (especially in full). If you want to add something use the large Reply button further down the page.
Was This Post Helpful? 0
  • +
  • -

#17 PiratePete   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 03-February 16

Re: Creating a DLL

Posted 28 November 2018 - 09:59 AM

View PostIronRazer, on 27 November 2018 - 04:10 PM, said:

I am not absolutely positive but, I believe that if you have windows 7 or above, a newer version of the speech sdk will already be included and does not need to be installed. For example, I have windows 7 and I have the 5.4 version on mine.

You can open your project in Visual Studio and on the main menu go to (Project -> Add Reference...). That will open the Reference Manager window. You can select the COM tab in the reference manager window and find (Microsoft Speech Object Library) as shown in the image below. Check the checkbox next to it and then click the OK button to add the reference.

Attachment Frame_1.png

Now you can add the import at the top of your code to import the SpeechLib namespace...
Imports SpeechLib

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim ad As New SpVoice
        ad.Speak("Hello, this is your computer talking to you.")
    End Sub

End Class


Was This Post Helpful? 0
  • +
  • -

#18 PiratePete   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 03-February 16

Re: Creating a DLL

Posted 28 November 2018 - 10:08 AM

Hi and thanks!
Your method (which worked)gave me a means to inform the user (of my program) of an error.
What I'd like is a DLL that any new programs I might write can use it.
Like this :
Public Class MyLib
 Function 1

 Function 2

 etc.
End Class



As my idiocy is increasing would you give me step by step instructions ?
I think after this I'll stick to "ordinary" programming!
Was This Post Helpful? 0
  • +
  • -

#19 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,026
  • Joined: 05-December 13

Re: Creating a DLL

Posted 28 November 2018 - 11:00 AM

Instructions on how to create a dll? Step by step instructions for what exactly?

If I know what you are asking, Maybe I can help you
Was This Post Helpful? 0
  • +
  • -

#20 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1530
  • View blog
  • Posts: 3,856
  • Joined: 01-February 13

Re: Creating a DLL

Posted 28 November 2018 - 11:39 AM

@ PiratePete,

I am guessing that you where talking to me since you quoted my post right before asking your last question. If so, then do you know how to create a Class Library project?

When you open Visual Studio, click (New Project) and from the list of project types select the (Class Library) type. Now name the Project and press the (OK) button. For my example I named mine "SpeekString".

When your empty class library code opens you should go right to the Solution Explorer tab, right click on the "Class1.vb" and choose to rename it. Be aware that you should not use spaces in the Class name. For this example I renamed mine as "Speaker.vb".

Then you will follow the same steps to add a reference to the SpeechLib dll that I explained in my other post. Then you could just add the import at the top of the code and a small public sub that you can pass a string of the error message to. For example...

Imports SpeechLib

Public Class Speaker

    Public Sub Say(msg As String)
        Dim ad As New SpVoice
        ad.Speak(msg)
    End Sub

End Class



Now you can save your project and build it. Build it by going to the VS menu and selecting (Build -> Build YourProjectName). Now you will have a (YourProjectName.dll) file in your project's bin\Debug folder. You can now close this class library project.

All you need to do now is create a new Form project and add a reference to (YourProjectName.dll). Open the reference manager (Project -> Add Reference), and click the (Browse) button at the bottom. Browse to your dll file and double click it. Last, press the (OK) button on the reference manager.

You can see here that I did this with my dll and have imported it's namespace at the top of the code. Notice it is the name of the class library project I created, "SpeekString".
Imports SpeekString

Public Class Form1
    Private spkr As New Speaker 'create a new Speaker class

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'tell the Speaker class to say something
        spkr.Say("Here is something that you want your computer to say.")
    End Sub

End Class



Hopefully this helps you get to your goal. 8)
Was This Post Helpful? 0
  • +
  • -

#21 PiratePete   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 03-February 16

Re: Creating a DLL

Posted 29 November 2018 - 01:35 PM

Hi all.
I think my last post got lost in the post!
What I need is a DLL file MyLib :
[code]
Class MyLib (?)
function/sub 1
function/sub 2
etc.
end
[code/]

and then in various of my projects I can select and transfer code
to be shared in the DLL.

Thanks for your continued patience :rockon:/>

This post has been edited by PiratePete: 29 November 2018 - 01:36 PM

Was This Post Helpful? 0
  • +
  • -

#22 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14691
  • View blog
  • Posts: 58,718
  • Joined: 12-June 08

Re: Creating a DLL

Posted 29 November 2018 - 01:46 PM

Is that supposed to be on your other topic?
Was This Post Helpful? 0
  • +
  • -

#23 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,026
  • Joined: 05-December 13

Re: Creating a DLL

Posted 29 November 2018 - 02:26 PM

Yes, this topic @Modi
Was This Post Helpful? 0
  • +
  • -

#24 PiratePete   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 03-February 16

Re: Creating a DLL

Posted 29 November 2018 - 03:38 PM

Hi all.
I posted a few hours ago but cant see it here, but have eMail responses from previous posts!
This is basically what I posted :

I've several programs where it would be useful to re-use code.
so :
I'd like a DLL like this :
.. Class MyLib
Function/sub 1

Function/sub 2

etc
... end ...

Sorry I'm being such a pain in your neck but I'm
sure we'll get there ... :stupid:
Was This Post Helpful? 0
  • +
  • -

#25 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1530
  • View blog
  • Posts: 3,856
  • Joined: 01-February 13

Re: Creating a DLL

Posted 29 November 2018 - 04:23 PM

@ PiratePete

Have your read back through the answers that have been posted in this 2nd page of your question? In post #18 you asked this same question. Then in post #20 I gave you a step by step example of creating a dll for this.
Was This Post Helpful? 0
  • +
  • -

#26 PiratePete   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 03-February 16

Re: Creating a DLL

Posted 30 November 2018 - 12:15 PM

Hi,
To mod123_1 :
-- ----------
Didn't understand this ...

To IronRazer :
-- -----------
Your reply was dated 28th. After I logged in it wasn't there!
Where do you get these post reference numbers ?

To all respondents :
-- --- -------------
Am receiving eMails saying "XYZ.. has replied" but these are dated 2 days ago
and are the same info. as previously provided.

All I want to do is create a "common" DLL (called MyLib) for all my projects
extract code functions from the projects into MyLib and in the various projects
add (at the top!) Imports MyLib,
In MyLib I presumably have Imports to whatever.. (yes ? )

Project A
  Imports MyLib
  ..



Project B
  Imports MyLib
  ..



This is want I need :
.. Class MyLib
Imports Math
Imports xxxx
Function X
Function Y
etc.
..end

As I'm taking up a lot of your time (and patience!) then
if my dim brain still wont get it it, I'll give up. :oops:
but Thanks all.

This post has been edited by PiratePete: 30 November 2018 - 12:18 PM

Was This Post Helpful? 0
  • +
  • -

#27 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,026
  • Joined: 05-December 13

Re: Creating a DLL

Posted 30 November 2018 - 01:33 PM

PiratePete When you create duplicate topics (separate) but related to other topics or bump topics related to topics like yours, moderators can split topics from the one you bumped, and merge them with one you posted, so when the email comes, it will likely have an old link referring to a topic which was later merged with an other topic. Hope this makes sense to you.

As for your DLL project, I will come back and post some tips later on for you.

This post has been edited by Sheepings: 30 November 2018 - 01:35 PM

Was This Post Helpful? 0
  • +
  • -

#28 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,026
  • Joined: 05-December 13

Re: Creating a DLL

Posted 30 November 2018 - 03:55 PM

Open up visual studio, and go to File / New / Project. You will get a dialog looking like this ::

Attached Image

Click Visual Basic / Look for Class Library from the center box, and then on the right, you can see where it says for creating DLL files.

Set the name of your project, I called mine "MyLibrary".

When your project creates, right click your class file and rename it as I've done in my screenshot, the name of your DLL, will be the name of your project.

Attached Image

Next add your reference to your DLL, and then you can move on to posting your code into your class. Right click on your References in the solution explorer.

Attached Image

You will be faced with another window "Reference Manager", in here select COM, then Type Libraries. And on the right side select the second object in the list. If you hover your mouse over it, it will show you the file name ends as "sapi.dll". Tick the checkbox left side and then click OK.

Attached Image

Next open up your class file. Mine is called "MyLib", and so my class is called MyLib, if you name your file something else, you will be best to edit the class names to reflect that.

Imports SpeechLib
Public Class MyLib
    Public Sub Say(myTxt As String)
        Dim nVoice As New SpVoice
        nVoice.Speak(myTxt)
    End Sub
End Class


Then go to Build Menu and click Build Solution. Your DLL file is created and you are now ready to import that DLL file into any other projects you wish you use it.

Attached Image

You can find that file in your debug folder. To navigate there, just right click your project, and then go to "Open Folder In File Explorer". Double click "Bin", and then Debug. There's your file.

Attached Image

Hope this and the screenshots helps put the process in perspective that IronRazer previously explained to you.

This post has been edited by Sheepings: 30 November 2018 - 03:57 PM

Was This Post Helpful? 0
  • +
  • -

#29 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1530
  • View blog
  • Posts: 3,856
  • Joined: 01-February 13

Re: Creating a DLL

Posted 01 December 2018 - 08:55 AM

Quote

To IronRazer :
-- -----------
Your reply was dated 28th. After I logged in it wasn't there!
Where do you get these post reference numbers ?


@ PiratePete,

I did make the post on the 28th, perhaps you where only looking on the 1st page of your thread instead of the 2nd page where my post has been? If you look at the top or bottom of the pages you can see (2 Pages [1][2]) where you can switch pages. My post #20 is towered the top of page 2. If you look at the top right hand side of each post in the pages, there should be post numbers there.

I gave you step by step instructions on creating a small dll Class Library and then how you could add a reference to that dll in a new separate Form project and use it.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2