How do you allow access to class library within solution but not externally

UncleRonin

Well-known member
Joined
Feb 28, 2006
Messages
230
Location
South Africa
Programming Experience
5-10
I have an application with two executables and a common class library in my solution. I want the class library accessible ONLY to these two applications and not to any external applications through the DLL.

How can I make this library 100% open to my solution's projects but prevent outsiders from calling this DLL? I'm doing this in VB and C# so I need to try and work out a way for both languages to accomplish this. I've tried fiddling with Friend and C#'s Internal keywords but at the moment I'm just settling for Public since I have no other choice. At this stage it seems the only way to lock down my logic would be to duplicate my library classes within each individual project :|

Any assistance would be greatly appreciated!
 
Hi,

I do not know of any formalised VB/C way of doing this but could you not try something like this:-

VB.NET:
Public Class Form1
 
  Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    'Denied Access to class
    Dim ReturnValue As String = MyProtectedClass.MyFunction("Some Data")
    If Not IsNothing(ReturnValue) Then
      MsgBox(ReturnValue)
    End If
 
    'granted access to class
    MyProtectedClass.MyUsagePassword = "EncryptedPassword"
    MsgBox(MyProtectedClass.MyFunction("Some Data"))
  End Sub
 
  Private Class MyProtectedClass
    Private Shared myEncryptedPassword As String = "EncryptedPassword"
    Public Shared Property MyUsagePassword As String
 
    Public Sub New()
      MyUsagePassword = Nothing
    End Sub
 
    Public Shared Function MyFunction(ByVal MyValue As String) As String
      If MyUsagePassword = myEncryptedPassword Then
      'do some work etc      
        Return "Returned Some Functionallity!"
      Else
        MsgBox("Class Access Denied!")
        Return Nothing
      End If
    End Function
  End Class
End Class
Cheers,

Ian
 
Back
Top