Results 1 to 13 of 13

Thread: Kedaman - Master in Class Module

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    247
    Kedaman!

    If I made a function in a class module and compile it into a dll, how do I use it. A co-worker of mine, told me that it would be use like the way how I call an API.

    Can you give me an example of a compile class module into a dll?
    Mako Shark
    Great White

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I'm not kedaman, but here goes:

    The class modules in an ActiveX DLL are exposed as COM objects, so using the References dialogue, add a reference to the newly created DLL. You can then use the objects as if they were class modules in your own project.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Open a new project (ActiveX.dll) type instead of standard
    Go to the project Properties and name it accordingly.
    When this opens it has a Class1 without code
    Copy this code into the code section:
    
    set the name property of the class1 to clsElasticForms
    'save as clsElasticForms
    
    Option Explicit
    
    ' Title:    Elastic Forms
    ' Author:   Leigh Bowers
    ' Email:    [email protected]
    ' WWW:      http://www.esheep.freeserve.co.uk/compulsion
    ' Version:  1.01
    ' Date:     19th June 1999
    ' Requires: N/A
    ' License:  Freely Distributable (non-commercial use)
    
    Public fForm As Form
    
    Public lOriginalWidth As Long
    Public lOriginalHeight As Long
    
    Public lMinWidth As Long
    Public lMinHeight As Long
    
    Public Type udtControl
        lLeft As Long
        lTop As Long
        lWidth As Long
        lHeight As Long
    End Type
    Private aControls() As udtControl
    
    Private Property Let Form(ByVal fPassForm As Form)
        
    Dim iCount As Integer
    Dim cControl As Control
    
        Set fForm = fPassForm
        
        ' Store form's original Width & Height
        
        lOriginalWidth = fForm.Width
        lOriginalHeight = fForm.Height
    
        ' Use error trapping to ignore components that don't
        ' support certain properties being read at run-time
    
        On Error Resume Next
    
        ' Store the form's component's properties
    
        iCount = 0
        ReDim aControls(fForm.Controls.Count)
    
        For Each cControl In fForm.Controls
            iCount = iCount + 1
            With aControls(iCount)
                If TypeOf cControl Is Line Then
                    .lLeft = cControl.X1
                    .lTop = cControl.Y1
                    .lWidth = cControl.X2
                    .lHeight = cControl.Y2
                Else
                    .lLeft = cControl.Left
                    .lTop = cControl.Top
                    .lWidth = cControl.Width
                    .lHeight = cControl.Height
                End If
            End With
        Next ' Each
    
    End Property
    
    Public Sub FormResize()
    
        ' v1.01 (19/06/1999)
        '
        ' bDisableResize:
        ' Used to avoid unnecessary *recursive* resizing
        '
        ' lPreviousWidth/Height:
        ' Used to avoid unnecessary resizing
    
        ' Resize the form's controls
    
    Dim iCount As Integer
    Dim cControl As Control
    Dim iTaskBarHeight As Integer
    Dim sOriginalWidthUnit As Single
    Dim sOriginalHeightUnit As Single
    Static bDisableResize As Boolean
    Static lPreviousWidth As Long
    Static lPreviousHeight As Long
    
        If fForm Is Nothing Or bDisableResize Then Exit Sub
    
        ' Don't process minimized forms
        
        If fForm.WindowState = vbMinimized Then Exit Sub
    
        ' Check form size against minimums
        
        bDisableResize = True
        If fForm.Width < lMinWidth Then fForm.Width = lMinWidth
        If fForm.Height < lMinHeight Then fForm.Height = lMinHeight
        bDisableResize = False
        
        ' Ensure form size has changed
        
        If lPreviousWidth = fForm.Width And lPreviousHeight = fForm.Height Then Exit Sub
        lPreviousWidth = fForm.Width
        lPreviousHeight = fForm.Height
    
        ' Perform calculations in advance (speed increase)
    
        iTaskBarHeight = 28 * Screen.TwipsPerPixelY ' Standard height
        sOriginalWidthUnit = lOriginalWidth / fForm.Width
        sOriginalHeightUnit = (lOriginalHeight - iTaskBarHeight) / (fForm.Height - iTaskBarHeight)
    
        ' Use error trapping to ignore components that don't
        ' support certain properties being set at run-time
    
        On Error Resume Next
    
        ' Do the resize...
        
        iCount = 0
    
        For Each cControl In fForm.Controls
            iCount = iCount + 1
            With cControl
                If TypeOf cControl Is Line Then
                    .X1 = Int(aControls(iCount).lLeft / sOriginalWidthUnit)
                    .Y1 = Int(aControls(iCount).lTop / sOriginalHeightUnit)
                    .X2 = Int(aControls(iCount).lWidth / sOriginalWidthUnit)
                    .Y2 = Int(aControls(iCount).lHeight / sOriginalHeightUnit)
                Else
                    .Left = Int(aControls(iCount).lLeft / sOriginalWidthUnit)
                    .Top = Int(aControls(iCount).lTop / sOriginalHeightUnit)
                    .Width = Int(aControls(iCount).lWidth / sOriginalWidthUnit)
                    .Height = Int(aControls(iCount).lHeight / sOriginalHeightUnit)
                End If
            End With
        Next ' Each
    
    End Sub
    
    
    Public Sub Class_Terminate()
    
        Set fForm = Nothing
    
    End Sub
    
    
    
    
    Public Property Let MinWidth(ByVal lPassMinWidth As Long)
    
        lMinWidth = lPassMinWidth
    
    End Property
    Public Property Let MinHeight(ByVal lPassMinHeight As Long)
    
        lMinHeight = lPassMinHeight
    
    End Property
    
    '...................................................
    
    When that is done save the project and then under file Make the project into a DLL
    
    Once that is done Open A Standard Project and add a commandbutton and a label and a textbox..Use the default names.
    
    'copy and paste this code into it.
    
    Option Explicit
    
    Private clsElastic As clsElasticForms
    
    Private Sub Command1_Click()
    
    Set clsElastic = Nothing
    Unload Me
    End Sub
    
    Private Sub Form_Load()
    
    '====================================================================
    
    'this goes in the form load event of each form in app
    
        Set clsElastic = New clsElasticForms
        clsElastic.MinHeight = 1950
        clsElastic.MinWidth = 6960
    
    
    End Sub
    
    Private Sub Form_Resize()
    
    clsElastic.FormResize
    End Sub
    
    Private Sub Form_Terminate()
    
    Set clsElastic = Nothing
    
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    
    Set clsElastic = Nothing
    
    End Sub
    
    Then go to your project references and use the browse button
    to find the dll you just saved clsElasticForms.dll and check it off. You will be returned to your form.
    
    Run your app and take note of it's size and spacing.
    
    Then go to your windows desktop properties and change
    your resolution.
    
    Then rerun your application and see that it has change
    it's sizes to accomodate the screen. That is because it
    has used the code itn the referenced dll.
    
    Hope you have fun with it.
    Wayne
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    247
    Thanks HeSaidJoe,

    I know you went out your way to help, but do you have anything a little bit more simple to explain that process. I kind of understand that project, but do you have anything with less lines of codes in the class module so I can trace through easier?

    Thanks again HeSaidJoe.
    Mako Shark
    Great White

  5. #5
    Guest

    Thumbs up This may or may not help

    There is a tutorial about classes/user objects on this site. Read through that then ask Karl to clarify any points you need elaboration on, that's where l got the hang of the thing.

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Shark:
    Sorry it took so long to get back...I'm at work and every now and then I actually have to work...Sucks..
    anyway, here is an over simple version and I hope I don't insult you in any way or form..It is simply meant as a little spark to get you interested enough to get down and dirty and learn about this stuff. MSDN or books are helpers as well as tutorials. You can visit my links page and pick up the url of a few good vb sites and you should find turorials on most or all of them..not mine.
    Code:
    'open a project  activeX dll not the standard one
    'it opens up with class1
    
    'paste this code in the code section
    
    Option Explicit
    
    
    Public Sub MessageMe()
        MsgBox "Help is here, partially, anyway"
    End Sub
    
    
    Public Property Get cmdCaption() As String
      cmdCaption = "It's not that simple"
    End Property
    
    'save the project as whatever
    'save the class1 as class1
    'make the thing into a dll (same as when you make an exe
    'except this one says dll
    
    'Call your dll whatever your want
    
    
    '<<<<<<<<<<<<<<  Form Code  >>>>>>>>>>>>>>>
    
    'open a project the standard one
    
    'create a form with 3 command buttons
    'use the default names
    '
    'go to the project properties and change Project1  to
    'MyClassProject
    '
    'set your reference to the dll you created
    'normally it would be placed in your windows\system dir
    'but it doesn't really matter for now
    
    
    'this one is relatively simple
    'command1 displays a message box
    'from the code within the dll
    
    'command2 changes the caption on command1
    'agian from code within the dll
    
    'command3 just unloads the form and sets the
    'class = nothing to free up the memory used
    
    Option Explicit
    
    Public Class1 As New Class1
    
    Private Sub Command1_Click()
        Set Class1 = New Class1
        Class1.MessageMe
    
    End Sub
    
    Private Sub Command2_Click()
        Set Class1 = New Class1
        Command1.Caption = Class1.cmdCaption
    End Sub
    
    Private Sub Command3_Click()
        Set Class1 = Nothing
        Unload Me
    End Sub
    
    Private Sub Form_Activate()
        Command1.Width = 3000
        Command1.Height = 500
        Command2.Height = 500
        Command2.Width = 3000
        Command1.Left = 240
        Command2.Left = 240
        Command3.Left = 1080
        Command1.Top = 120
        Command2.Top = 720
        Command3.Top = 1320
        Form1.WindowState = 0
        
        Form1.Width = 3585
        Form1.Height = 2340
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    247
    Thanks for the advice Jethro.

    HeSaidJoe... I don't know how to express my appreciation for your generosity and time. You are the best!
    Mako Shark
    Great White

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    247
    Your example works fabulously. I have one more question. How come you want it me to do this?

    'go to the project properties and change Project1 to
    'MyClassProject

    Thanks again HeSaidJoe.
    Mako Shark
    Great White

  9. #9
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    I'm not HeSaidJoe (unless I have a multiple personality disorder which I don't know about), however, adding a reference to the DLL tells VB that whenever you use something in 'MyClassProject' that it should use the MyClassProject DLL. Otherwise, VB doesn't know what any of the functions using MyClassProject mean since they aren't in the project.
    Courgettes.

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    uh, i'm not HeSaidJoe, but i (maybe i am, funny idea V(ery)) but i saw my name and thought that i would have to drop a comment
    You shouldn't mix up ActiveX Dll's with APi Dll's, they are refered with declaration statements to particular functions and subs, but by refering activeX Dll's (you check the box or browse for it in references) you can use any class (that are public in the dll, you put the methods in the classes of course.

    By pressing F2, object browser appears, and you can search for all objects and their methods and usage in the dll project. If you know how to create an object of a classmodule, (if you don't look at HesaidJoes example with New keyword) you can create any public creatable class the same way.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  11. #11
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Shark:
    When I created the dll I left the project name as Project1 so when I made the standard app, it has to have a different name. It could very well be V(ery)Basic or LOL or anything.

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Again, i may not be HeSaidJoe, but i think i could answer some of them anyway?

    the exp and lib files are not nessesary, i'm not sure but they may be as oca files to ocx files, just info about the dll created.

    No actual diffenrece between classes in activeX dll projects and standard exes, just that you can create public creatable or multiuse classmodules, but not private or public notcreatable, although you can refer to publicnotcreatable objects used by the dll, just like nodes object in treeview.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    The .exp file contains a list of the DLL's exported functions/objects. The .lib file is only useful if you want to use compile-time dynamic linking with another language (ouch).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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