Results 1 to 9 of 9

Thread: [RESOLVED] [2005] Question about DLL and New

  1. #1

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Resolved [RESOLVED] [2005] Question about DLL and New

    Ok, I wrote a class that I use in many projects that is used to encrypt and decrypt strings. I ahve decided to just compile it into a dll and use it like that, but what I was wondering is how do I change the class so that I do not have to call the new function when I dim the object? First of all, is there a way to do this and second, how?

    for example right now I use it like so
    VB Code:
    1. Dim enc As New Encrypt.StringEncrypt
    2. enc.Encrypt("Hello World")

    What I would like to do is just write
    VB Code:
    1. Dim enc As Encrypt.StringEncrypt
    2. enc.Encrypt("Hello World")

    Thanks in advance
    Last edited by bmahler; Oct 12th, 2006 at 10:15 AM.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Question about DLL and New

    Make your Encrypt function a Shared function:

    VB Code:
    1. Friend Shared Function Encrypt (s As String) As String

  3. #3

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Question about DLL and New

    When I do that, I can no longer call those functions
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Question about DLL and New

    Make it public instead of friend. I didn't take into account that it is in a separate DLL.

  5. #5

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Question about DLL and New

    When I do that I get the following error

    Warning 1 Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated. C:\Documents and Settings\bhmahler\My Documents\Visual Studio 2005\Projects\EDMS\EDMS\frmAdministration.vb 3267 9 EDMS

    with this code

    VB Code:
    1. Dim enc As Encrypt.StringEncrypt
    2.         enc.Encrypt("Hello")

    This is my class for the dll

    VB Code:
    1. Imports System.Text
    2. Imports System.Security.Cryptography
    3. Imports System
    4. Imports System.IO
    5.  
    6. Public Class StringEncrypt
    7.     Public Shared Function Encrypt(ByVal strText As String) As String
    8.         Dim strPwd As String = "***"
    9.         Dim i As Integer, c As Integer
    10.         Dim strBuff As String = String.Empty
    11.  
    12.  
    13.         For i = 1 To Len(strText)
    14.             c = Asc(Mid$(strText, i, 1))
    15.             c = c + Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
    16.             strBuff &= Chr(c And &HFF)
    17.         Next i
    18.  
    19.         Return strBuff
    20.     End Function
    21.  
    22.     Public Sub New()
    23.         MyBase.New()
    24.     End Sub
    25.     Public Shared Function Decrypt(ByVal strText As String) As String
    26.         Dim strPwd As String = "***"
    27.         Dim i As Integer, c As Integer
    28.         Dim strBuff As String = String.Empty
    29.  
    30.         For i = 1 To Len(strText)
    31.             c = Asc(Mid$(strText, i, 1))
    32.             c = c - Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
    33.             strBuff = strBuff & Chr(c And &HFF)
    34.         Next i
    35.         Return strBuff
    36.     End Function
    37.  
    38.     Public Shared Function GenerateHash(ByVal text As String) As String
    39.         Dim Ue As New UnicodeEncoding()
    40.         Dim ByteSourceText() As Byte = Ue.GetBytes(text)
    41.         Dim Md5 As New MD5CryptoServiceProvider()
    42.         Dim ByteHash() As Byte = Md5.ComputeHash(ByteSourceText)
    43.         Return Convert.ToBase64String(ByteHash)
    44.     End Function
    45.  
    46. End Class
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  6. #6
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Question about DLL and New

    Are you using 2003 or 2005?

  7. #7

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Question about DLL and New

    2005 sorry, meant to put that in my title
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  8. #8
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] Question about DLL and New

    I am not getting that Warning in 2003, but I think it is there to inform you that your code may be a bit misleading. Here is microsofts answer: http://msdn2.microsoft.com/en-us/library/y6t76186.aspx

    In your code, you should just be able to go:

    VB Code:
    1. Encrypt.StringEncrypt.Encrypt("Blah")

    To get it to work.

    I don't have 2005 on my machine, but if you did something like:

    VB Code:
    1. Dim oMath As System.Math
    2.         Dim dblVal As Double
    3.  
    4.         dblVal = oMath.Cos(6.0)

    Do you get the same warning?

  9. #9

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Question about DLL and New

    Ok I got it, Thanks for your help
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width