ActiveX DLL ID

Discussion in 'AutoCAD' started by Dale Levesque, Aug 7, 2003.

  1. I have 2 seperate DLL's projects. One DLL references the other. A DVB
    project references the main DLL. When I make certain changes in the DLL
    projects and run them again, I assume the ID is modified and I have to
    manually reset the reference by using "Tools->References", unselecting the
    missing reference, then use "Tools->References" to reset the reference.

    Is there any way to have this done automatically? I'd like the DLL to check
    it's own references and update them when I try to run it (for debugging).
    I'd like the DVB file to do the same.

    Dale
     
    Dale Levesque, Aug 7, 2003
    #1
  2. Dale Levesque

    Kevin Terry Guest

    I'm not sure if this will work for the dll, but here's what i use for the
    dvb's:

    'Checks to see if reference file is present, makes reference if not.
    '
    'Function:
    'Returns true if reference exists or was successful in adding
    '
    'Passed variables:
    'sReference = complete path and filename for reference
    '
    'Quirk: If there is a reference missing, then the fullpath method will throw
    an error.
    '
    Public Function Reference_Exists(sReference As String) As Boolean
    On Error GoTo Reference_Exists_Error

    Dim oVBIDE As VBIDE.VBE
    Dim fRef As Boolean
    Dim i As Integer

    'need this to prevent crashing from missing references or files
    On Error Resume Next

    Set oVBIDE = Application.VBE

    'make quick test in case only filename was passed
    If Not VBA.InStr(1, sReference, "\") > 0 Or VBA.InStr(1, sReference,
    "/") > 0 Then
    For i = 1 To oVBIDE.ActiveVBProject.References.Count
    'if error, missing reference. clear error after using once
    If VBA.Err.Number = 0 Then
    If VBA.InStr(1,
    VBA.UCase(oVBIDE.ActiveVBProject.References.item(i).FullPath), _
    VBA.UCase(sReference)) > 0 Then
    'do nothing, reference exists
    fRef = True
    Reference_Exists = True
    'jump out
    Set oVBIDE = Nothing
    Exit Function
    End If
    Else
    VBA.Err.Clear
    End If
    Next i
    End If

    'make sure the file is there
    'this will throw error if no file exists
    i = VBA.CInt(VBA.Left(VBA.FileLen(sReference), 4))
    'now if error, no file
    If VBA.Err.Number = 0 Then
    'see if reference already exists
    For i = 1 To oVBIDE.ActiveVBProject.References.Count
    'if error, missing reference. clear error after using once
    If VBA.Err.Number = 0 Then
    If sReference =
    oVBIDE.ActiveVBProject.References.item(i).FullPath Then
    'do nothing, reference exists
    fRef = True
    Reference_Exists = True
    Exit For
    End If
    Else
    VBA.Err.Clear
    End If
    Next i

    'add reference if needed
    If Not fRef Then
    oVBIDE.ActiveVBProject.References.AddFromFile sReference
    Reference_Exists = True
    End If
    End If

    Set oVBIDE = Nothing

    Exit Function

    Reference_Exists_Error:
    sErrDesc = Err.Description & " " & Err.Number & vbCrLf & vbCrLf & _
    "Could not find or make reference to " & sReference & "." & vbCrLf &
    sErrDesc
    sErrApp = "(FUNCTION: Reference_Exists) " & vbCrLf & sErrApp
    Reference_Exists = False
    Set oVBIDE = Nothing

    End Function
     
    Kevin Terry, Aug 7, 2003
    #2
  3. Thanks Kevin. Where do you call the function? I'm still not sure this will
    work because the reference displays as missing in the reference list. I'm
    not sure if that will cause the error or whether the DLL file itself not
    being found causes the error.

    Dale
     
    Dale Levesque, Aug 7, 2003
    #3
  4. Kevin,

    I've referenced MS VB Extensibility 6.0 but from VBA it seems that there is
    a type difference between:

    VBIDE.VBE and Application.VBE. Is this because Application.VBE is VBA?


    After Set oVBIDE = Application.VBE is evaluated, oVBIDE still equals
    Nothing. If I copy the statement to the immediate window I get the type
    error.

    Dale
     
    Dale Levesque, Aug 7, 2003
    #4
  5. Dale Levesque

    Kevin Terry Guest

    this is a stretch here, and I have not tried this, but what about creating a
    dummy file on the hard drive at run time named the same thing as the missing
    reference, then removing the reference and killing the file?

    Kevin
     
    Kevin Terry, Aug 8, 2003
    #5
  6. I have a dll that is referenced by a dvb and when I make changes to the
    dll,
    My acad.dvb is basically just a stub which calls the main sub included in my
    first DLL. This DLL is running on my PC at the time so that I can debug ,
    modify it. The reason I have it in a DLL is so that I can use Visual source
    safe with it. Having a very large amount of code stored in a binary DVB file
    is not what I want. So, Any time I change the signature of a sub (by
    changing arg's , etc) included in the DLL project, VB modifies the CLSID
    which means my reference gets broken.
    There is. Opening the references, unselecting the reference, opening the
    references, reselecting the reference. This has grown very tiresome and I'd
    like a toolbar button to do it programmatically. I've managed to get
    everything to work but for some reason the remove method of the References
    collection doesn't work on missing references as far as I can tell.

    Best regards,

    Dale Levesque

    The IsBroken property returns true but Remove doesn't work.
    I've found multiple posts around the net identifying this but no solution.

    If oVBIDE.ActiveVBProject.References.Item(i).IsBroken
    Then
    oVBIDE.ActiveVBProject.References.Remove
    oVBIDE.ActiveVBProject.References.Item(i)
    End If
     
    Dale Levesque, Aug 8, 2003
    #6
  7. Dale Levesque

    Kevin Terry Guest

    Dale, I know you've probably tried this but just in case -
    Is your sub stopping at the remove method, or just continuing on like it
    worked? I remember having trouble where the function would crash, I think
    that's why I put the resume next statement in there to begin with. What if
    you wrap the remove method in a separate function into which you pass the
    reference itself. Then with some aggressive error handling maybe you can
    successfully remove the reference and keep the code running...

    Kevin
     
    Kevin Terry, Aug 8, 2003
    #7
  8. Your code helped alot! I've tried various different things with it but the
    remove method seems to be the problem. I've even learned alot about VB (and
    VBA) add-ins while mucking about.

    Thanks!!

    Dale
     
    Dale Levesque, Aug 8, 2003
    #8
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.