none
Calling unmanaged DLL VB.NET 2015 RRS feed

  • Question

  • Hi Guys,

    I'm writing a programme that users log into, and I have a function for resetting forgotten passwords, by emailing a temporary password to their registered email address.

    However, as I'm not that seasoned in VB.NET (or any programming language really) I hard coded the sending email address and password; obviously this isn't a good thing to do!

    So, I went about learning how to handle it with a DLL file, and got it working really well. The only problem is, that the way I've done it is by adding a reference at design time; which means I don't need to ship the DLL file with my programme, but if I want to make any changes to the DLL file (such as sending email address or password) I still have to recompile my whole application and push an update.

    What I would really like to do is have my programme access the DLL externally, only as and when needed, and if I need to make any changes to that one DLL file, I can and then just replace the old one.

    I've tried follwoing examples online, but they all seem to be so specific, I just can't get my head around them.

    My DLL has one function, SendMail, that accepts 3 parameters; User, Email, tempPass. It then fires off the email to the user's email address.

    How do I utilise that function at runtime, rather than add it as a reference?

    Sunday, February 17, 2019 12:25 AM

All replies

  • Hi

    I think you can use System.Net.Mail:

    https://social.msdn.microsoft.com/Forums/en-US/357245ee-fbaf-4ba2-8ba3-fa005655c687/how-do-i-send-mail-in-vbnet?forum=Vsexpressvb

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 18, 2019 3:12 AM
  • ... The only problem is, that the way I've done it is by adding a reference at design time; which means I don't need to ship the DLL file with my programme, ....

      Hmmm,  That is strange,  if you build a separate ClassLibrary (dll) project and then create a new test form application which you add a reference to the dll,  it is required to be with the application when it is moved to another computer, or published and installed on another computer.  Otherwise,  your application would throw an exception when your app tries to create a new instance of the dll or access its shared methods.

     If you are publishing your app and installing it on another computer and it works,  then the dll file is there somewhere,  or it is not a separate dll ClassLibrary.  If you are copying just the application's exe file to another computer without a dll file and your app works,  then I could only guess that you have added a Class to your application project instead of building a separate ClassLibrary dll and adding a reference to it.


    If you say it can`t be done then i`ll try it

    Monday, February 18, 2019 11:46 PM
  • Hello,

    The following may be a huge (or not) jump in your learning curve. This Visual Studio code sample will store sender email address and sender password encrypted in a binary file residing in the executable folder.

    Take your time, run through the bullet list below to setup for adding email address and password along with updating.

    Solution projects

    Basic instructions

    About

    This solution has the capabilities to

    • Save user email address and email password encrypted in a binary file, in this example in the executable folder named data.bin

    Requires

    NuGet package BaseConnectionLibrary.

    Before compiling the solution, right click on solution explorer, select restore packages. Next build the solution.

    Setting a user email address and user password.

    • In MyGreatApplication select project properties, change the startup form to ConfigureSenderForm.
    • Build the projects.
    • Run MyGreatApplication.
    • First time, enter a email address and email password.
    • Press Add.
    • Close form.
    • Change startup form back to Form1
    • Run the project.
    • Press the button.
    • Note in the IDE output window the email address and password are shown, from here they can be used to sen email messages,

    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, February 19, 2019 1:15 AM
    Moderator