license checking inside Class_Initialize()

Posted on 2005-05-17
Last Modified: 2008-03-10
I have a VB6 dll that contains a lot of the functions for my asp application. I need to put a license key check inside the dll in order to prevent the app from running if a valid key is not found, or if it's expired.

I would like to put this check inside Class_Initialize() so that it is only executed once -- when the object is created. Is there any danger in this, or pitfalls I should be aware of? Would this create instability in the component or webapp? Is there a better solution? Are there certain types of code that should not be executed inside Class_Initialize()?

Can Class_Initialize() return a value to signify expired or invalid key? Or can it call a function to do so? If not, how can I alert the calling asp page that this is the case?

I will split points for any useful responses.
Question by:SweatCoder
    1 Comment
    LVL 28

    Accepted Solution

    I don't see any issues using Class_Initialize.  I have used it for my own license checking in my components.  There is no way to return a value directly, but you can fill a variable made accessible via a public property that can be accessed once the component is created, e.g.,

    Private m_blnLicenseValid As Boolean

    Public Property Get LicenseValid() As Boolean
        LicenseValid = m_blnLicenseValid
    End Property

    Private Sub Class_Initialize()
        'ensure initially false
        m_blnLicenseValid = False

        'do license checking
        'fill m_blnLicenseValid with results
    End Sub

    From ASP:

    Dim obj

    Set obj = Server.CreateObject("MyDLL.MyClass")
    If obj.LicenseValid = False Then
        Response.Write "Invalid License"
        'proceed with ASP code
    End If

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now