Results 1 to 3 of 3

Thread: How do you pass a "namespace.interface" as a parameter to a function?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2012
    Location
    Wiltshire, England
    Posts
    211

    How do you pass a "namespace.interface" as a parameter to a function?

    Hi,

    I'm trying to write a function to test if a dll I'm about to use is registered or not,. I've got lots of 3rd party dlls which I use which may not be registered, so I want to call a function, where I pass it the "namespace.interface" I'm about to use and the name of the dll to use if it needs to register it.

    Here's my code for 1 dll which I'm trying to replace with my function, but I don't know how to pass "FitManager.CFitManager" into my function:

    Code:
            Dim processRegister_DLL As New Process
            processRegister_DLL.StartInfo.UseShellExecute = False
            processRegister_DLL.StartInfo.RedirectStandardOutput = True
            processRegister_DLL.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            processRegister_DLL.StartInfo.CreateNoWindow = False
            processRegister_DLL.StartInfo.FileName = Environment.SystemDirectory & "\regsvr32"
    
    
            MsgBox("About to test FitManager.dll")
    
            Try
                Dim oFitManager_Test As New FitManager.CFitManager
                oFitManager_Test = Nothing
                MsgBox("FitManager.dll already registered")
    
            Catch ex As Exception
    
                MsgBox("FitManager.dll is not registered")
                MsgBox("About to register FitManager.dll")
                processRegister_DLL.StartInfo.Arguments = ".\FitManager.dll"
                processRegister_DLL.Start()
                processRegister_DLL.WaitForExit()
    
                If processRegister_DLL.ExitCode <> 0 Then
                    MsgBox("Failed to Register FitManager.dll. Admin Rights are required to register a DLL")
                    Exit Sub
                Else
                    MsgBox("FitManager.dll registered OK")
                End If
    
            End Try

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,830

    Re: How do you pass a "namespace.interface" as a parameter to a function?

    Just because something is a ".dll" doesn't mean it has to be registered. Only ActiveX DLLs would need to be registered. Since this is VB.NET code, I'm assuming that what you're tapping into is a .NET Assembly, which doesn't need to be registered. You can find out if the file exists, and if so, use reflection to load the assembly and then get a list of all the classes in it and test the results to make sure that "FitManager.CFitManager" exists.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2012
    Location
    Wiltshire, England
    Posts
    211

    Re: How do you pass a "namespace.interface" as a parameter to a function?

    Quote Originally Posted by techgnome View Post
    Just because something is a ".dll" doesn't mean it has to be registered. Only ActiveX DLLs would need to be registered. Since this is VB.NET code, I'm assuming that what you're tapping into is a .NET Assembly, which doesn't need to be registered. You can find out if the file exists, and if so, use reflection to load the assembly and then get a list of all the classes in it and test the results to make sure that "FitManager.CFitManager" exists.

    -tg
    I think the libraries are either vb6 or Fortran and my code crashes if they are not registered (but as you said I noticed that some of the newer dlls don't need registering). Under references, they are a mixture of COM or .NET and most of the .NET ones have interops. A while ago I tried to use reflection to load them but had problems - maybe because it was a COM dll. I forgot to mention that this is for a Winform app running on Windows 7. As I need to test if the dlls exist in several places I just wanted to write a function to do the test, but struggled passing the namespace.interface

Tags for this Thread

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