Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Com DLL file reference access ...

Com DLL file reference access ...

Scheduled Pinned Locked Moved C#
csharpvisual-studiocomquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shahin77
    wrote on last edited by
    #1

    I have a com object dll file called MyCom.dll with some classes, interfaces, methods and events. I can add it as a reference to my project in visual studio IDE and create an instance from one interface that i need: MyDllLib.InterfaceName myobject = new MyDllLib.InterfaceName(); I can also access all the events and methods for this interface via myobject. So by some reason i dont want to add this com dll file to my project references and dont ask why! My question is how can instantiate an interface from a com dll file and access it's methods and events. If i dont add it as a reference in .Net IDE so i can't reference it. Could someone recommend the best solution for this. Thank You,:confused:

    D 1 Reply Last reply
    0
    • S Shahin77

      I have a com object dll file called MyCom.dll with some classes, interfaces, methods and events. I can add it as a reference to my project in visual studio IDE and create an instance from one interface that i need: MyDllLib.InterfaceName myobject = new MyDllLib.InterfaceName(); I can also access all the events and methods for this interface via myobject. So by some reason i dont want to add this com dll file to my project references and dont ask why! My question is how can instantiate an interface from a com dll file and access it's methods and events. If i dont add it as a reference in .Net IDE so i can't reference it. Could someone recommend the best solution for this. Thank You,:confused:

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Shahin77 wrote:

      i dont want to add this com dll file to my project references and dont ask why! My question is how can instantiate an interface from a com dll file and access it's methods and events.

      Shahin77 wrote:

      Could someone recommend the best solution for this.

      There is no "best solution". Doing this just makes your life so much more difficult, it's not worth it. You've just about trippled the amount of time it'll take to write your code to consume this library, being that you lose all type safety and Intellisense, not to mention that you'll have to write the code to load this library and initialize it. You'll also need to write the code to lookup and instantiate objects, manually wire up events, ..., ..., yada, yada, yada... Why would you want to ignore all the benefits of early binding and having the compiler do all the dirty work for you??

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Shahin77 wrote:

        i dont want to add this com dll file to my project references and dont ask why! My question is how can instantiate an interface from a com dll file and access it's methods and events.

        Shahin77 wrote:

        Could someone recommend the best solution for this.

        There is no "best solution". Doing this just makes your life so much more difficult, it's not worth it. You've just about trippled the amount of time it'll take to write your code to consume this library, being that you lose all type safety and Intellisense, not to mention that you'll have to write the code to load this library and initialize it. You'll also need to write the code to lookup and instantiate objects, manually wire up events, ..., ..., yada, yada, yada... Why would you want to ignore all the benefits of early binding and having the compiler do all the dirty work for you??

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        S Offline
        S Offline
        Shahin77
        wrote on last edited by
        #3

        The reason is im working on a project which is shared between 20 developers and i dont want to add any reference to the project, I dont want any dependency to this dll file when i compile. So any idea? Thank You

        D 1 Reply Last reply
        0
        • S Shahin77

          The reason is im working on a project which is shared between 20 developers and i dont want to add any reference to the project, I dont want any dependency to this dll file when i compile. So any idea? Thank You

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          There isn't a way around this. The dependancy is GOING to be there no matter if you use a reference or not. With the reference, you just made using this library about 100x harder to use because now your developers have to write their own code to load the library, init it, lookup and instantiate objects, wire up events, ..., ..., ... It's simply not worth it. There is no "easy" way around this. If you've chosen to export your library as a COM-based .DLL, you've also locked yourself into DllHell and the dependancies that come with COM. You simply have no way around this. Now, if the library is exported as a normal .NET library, the dependancies go away and you can even setup the app's app.config file to redirect dependancies to new version of the library assembly.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          S 1 Reply Last reply
          0
          • D Dave Kreskowiak

            There isn't a way around this. The dependancy is GOING to be there no matter if you use a reference or not. With the reference, you just made using this library about 100x harder to use because now your developers have to write their own code to load the library, init it, lookup and instantiate objects, wire up events, ..., ..., ... It's simply not worth it. There is no "easy" way around this. If you've chosen to export your library as a COM-based .DLL, you've also locked yourself into DllHell and the dependancies that come with COM. You simply have no way around this. Now, if the library is exported as a normal .NET library, the dependancies go away and you can even setup the app's app.config file to redirect dependancies to new version of the library assembly.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            S Offline
            S Offline
            Shahin77
            wrote on last edited by
            #5

            We didnt create this com dll file, we just have to use it and there are just one method call & one event handeling from dll. I tried this: Type comType = Type.GetTypeFromCLSID(new Guid("{95D4B070-6A73-11D5-95B0-0008C7E92339}")); object instance = Activator.CreateInstance(comType); But the second line fails, i dont know why!! might be some dependency, but anyway there should be a way!! Thank You

            D 1 Reply Last reply
            0
            • S Shahin77

              We didnt create this com dll file, we just have to use it and there are just one method call & one event handeling from dll. I tried this: Type comType = Type.GetTypeFromCLSID(new Guid("{95D4B070-6A73-11D5-95B0-0008C7E92339}")); object instance = Activator.CreateInstance(comType); But the second line fails, i dont know why!! might be some dependency, but anyway there should be a way!! Thank You

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Shahin77 wrote:

              But the second line fails

              Standard question #1: What's the error message?? There's about a dozen reasons this can fail... I've found a rather good explanation of the pain you're about to put yourselve through here[^]. It's a 6 page article from back in 2002, but just about everything still applies today.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              modified on Wednesday, January 09, 2008 3:43:09 PM

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups