Form appears locked 2nd time VB6 dll runs

Discussion in 'AutoCAD' started by schesser, Mar 3, 2004.

  1. schesser

    schesser Guest

    Please help me figure this out.
    I have spent almost 2 weeks stuck on this.

    I use a group of projects - most use vba code and vb6 dlls without forms, 2 of them use vb6 dlls that show forms and produce a drawing.

    The projects worked in AutoCAD R14, but we are now upgrading to 2004.

    I use menus with AutoLISP to unload the currently loaded project, load the desired project, and run the appropriate macro.
    After some modifications, all projects work great except for the 2 that show vb6 forms.

    The problem: The first time I run a project that uses VB6 forms, it works.
    The second time I run a project that uses vb6 forms, the form appears to be locked!
    It does not respond to the mouse or to the keyboard keys, except if the form has a Cancel button, the Esc button closes the form. Once the form is closed, AutoCAD and the projects without vb6 forms work fine.
    Any subsequent attempts to run a project with vb6 forms respond the same way - the form appears to be locked.

    I have set all AutoCAD related object variables in my dlls to Nothing when I am done using them, but this still happens.
    I tried keeping track of when classes are initialized and terminated - the main class and the forms terminate upon unloading the vba project. Is this causing my problem?

    Any suggestions would be appreciated - I am close to pulling my hair out over this!
     
    schesser, Mar 3, 2004
    #1
  2. Hmmm....first you don't need to unload/load projects in 2004. You can have
    as many loaded as you want but that isn't causing your problem. Are you
    unloading the form and killing the object that holds reference to your DLL?

    Post your code that loads/unloads the projects and the code that calls the
    DLL. Then wew can see what might be causing your issue.
     
    Mike Tuersley, Mar 4, 2004
    #2
  3. schesser

    schesser Guest

    I have a set of 11 projects, and some of them have multiple UserForms, will keeping them loaded use up too much resources?

    Here is the code I am using - I am including VBA code from 2 projects, since I revised one, but both have the same problem:

    ___AutoLisp (to load and unload projects and call macros)___


    (defun NEWPROJ ( ProjName MacroName / VBName) ;VBName is a local variable, ProjName and MacroName are arguments
    (setq VBName (vl-bb-ref '*VBName*)) ;Retrieve *VBName* global value from the blackboard

    (if (= VBName (findfile "acadmsr.dvb")) ;If acadmsr is currently loaded, call EndRafter to release object references before unloading it.
    (COMMAND "-VBARUN" "MENUOPTIONSMODULE.ENDRAFTER") ;rafter project loaded - run EndRafter.
    )

    (if VBName (command "vbaunload" VBName)) ;If a VBA project is loaded, unload it
    (setq VBName (findfile ProjName)) ;Set global *VBAProjName* to the full path name to the file to open.
    (vl-bb-set '*VBName* VBName) ;Write *VBName* global value to the blackboard
    (if VBName
    (progn
    (command "vbaload" VBName) ;Load the current VBA project
    (COMMAND "-VBARUN" MacroName) ;Run the macro
    )
    )
    (prin1)
    )


    (defun c:EWCOLUMN ()
    (NEWPROJ "acadewc.dvb" "MENUOPTIONSMODULE.DETAILEWCOLUMN")
    )


    (defun c:MSRAFTER ()
    (NEWPROJ "acadmsr.dvb" "MENUOPTIONSMODULE.MULTISEGRAFTER")
    )


    (defun c:NEXTSEG ( / VBName) ;VBName is a local variable
    (setq VBName (vl-bb-ref '*VBName*)) ;Retrieve *VBName* global value from the blackboard
    (if (= VBName (findfile "acadmsr.dvb"))
    (COMMAND "-VBARUN" "MENUOPTIONSMODULE.DETAILNEXTSEG") ;rafter project loaded - run DetailNextSeg.
    (princ "No rafter is currently being detailed.\n") ;rafter project not loaded - display message.
    )
    )


    (defun c:ENDWALLRAFTER4MS ()
    (NEWPROJ "acadmewr.dvb" "MENUOPTIONSMODULE.ENDWALLRAFTER")
    )


    ___VBA for project 1_____

    Option Explicit
    Public MSR As MSRaf.Detail


    Public Sub MultiSegRafter()
    'Change the current directory to the AutoCAD directory
    ChDir ThisDrawing.Application.Path

    Set MSR = New MSRaf.Detail
    Set MSR.AcadApp = ThisDrawing.Application
    MSR.MultiSegRafter
    End Sub


    Public Sub DetailNextSeg()
    'Change the current directory to the AutoCAD directory
    ChDir ThisDrawing.Application.Path

    If MSR Is Nothing Then
    MultiSegRafter
    Else
    MSR.NextPiece
    End If
    End Sub


    Public Sub EndRafter()
    'Set MSR.AcadApp to Nothing, then set MSR to Nothing.
    MsgBox "MSR = Nothing"
    Set MSR.AcadApp = Nothing
    Set MSR = Nothing
    End Sub


    ___VBA for project 2_____

    Option Explicit
    Dim EWC As DetailColumn


    Public Sub DetailEWColumn()

    'Change the current directory to the AutoCAD directory
    ChDir ThisDrawing.Application.Path

    Set EWC = ThisDrawing.Application.GetInterfaceObject("EWColumn.DetailColumn")
    EWC.EndwallColumn ThisDrawing.Application
    End Sub


    Thanks in advance.
     
    schesser, Mar 4, 2004
    #3
  4. schesser

    schesser Guest

    Some new info on the problem:
    I was using a messagebox on the Initialize and Terminate events of some of my classes to see when they were being created and destroyed. I removed the messageboxes, and now DetailEWColumn in project 2 works fine.
    However, Project 1 still causes a problem. After the first time I run MultiSegRafter, whether I run MultiSegRafter again, DetailNextSeg, or DetailEWColumn, the vb6 form appears to be locked.
    Projects that show vba UserForms continue to work.

    Again, thanks for any suggestions.
     
    schesser, Mar 4, 2004
    #4
  5. schesser

    schesser Guest

    Mike, thanks for your suggestion.
    It got me thinking in a different direction, and sometimes that is all it takes.

    I figured out that the problem is being caused by messageboxes being displayed while an AutoCAD drawing is being edited.
    (Both the messageboxes and editing the AutoCAD drawing are done from inside the VB6 dll.)
    This also causes the AutoCAD VBA editor to lock up, although AutocAD keeps working.

    If anyone knows why this is a problem, I would be very interested to hear it.
     
    schesser, Mar 4, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.