Select and attach to specific COM EXE instance as COM object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Davis

    Select and attach to specific COM EXE instance as COM object

    I am working with an application that is compiled as a COM EXE (written in
    Delphi 7). I don't know if it's the nature of COM EXE or if it's implemented
    in the COM EXE, but when I create a new object based on the COM interface
    using C#, it references the first process/instance it finds of this
    interface. This is not ideal for me; I would like to create a modal dialog
    box that makes the user select which process to "attach" to. Getting a list
    of processes isn't a problem, rather it's getting my COM references in the
    C# RCW of the COM interface to attach to the preferred COM EXE rather than
    the first one it finds.

    I asked the developer of the app as to how to "select" which COM instance
    you're attaching to, but he said he was busy and hasn't gotten back to me.
    However, I tend to believe that this is something that is pretty generic to
    COM EXEs, and I was hoping someone out there might know and could give me a
    tip on this?

    Thanks,
    - Jon


  • Alvin Bruney - ASP.NET MVP

    #2
    Re: Select and attach to specific COM EXE instance as COM object

    i don't think that is the case, that sounds like internal code making sure
    that there is only one instance. however, without source, i'm just taking a
    stab in the dark so you should take that with a large dose of rock salt.

    --
    Warm Regards,
    Alvin Bruney [MVP ASP.NET]

    [Shameless Author plug]
    The Microsoft Office Web Components Black Book with .NET
    Now Available @ www.lulu.com/owc
    Professional VSTO 2005 - Wrox/Wiley 2006
    Blog: http://msmvps.com/blogs/Alvin/
    -------------------------------------------------------



    "Jon Davis" <jon@REMOVE.ME. PLEASE.jondavis .net> wrote in message
    news:Om96GQmWGH A.3740@TK2MSFTN GP03.phx.gbl...[color=blue]
    > I am working with an application that is compiled as a COM EXE (written in
    > Delphi 7). I don't know if it's the nature of COM EXE or if it's[/color]
    implemented[color=blue]
    > in the COM EXE, but when I create a new object based on the COM interface
    > using C#, it references the first process/instance it finds of this
    > interface. This is not ideal for me; I would like to create a modal dialog
    > box that makes the user select which process to "attach" to. Getting a[/color]
    list[color=blue]
    > of processes isn't a problem, rather it's getting my COM references in the
    > C# RCW of the COM interface to attach to the preferred COM EXE rather than
    > the first one it finds.
    >
    > I asked the developer of the app as to how to "select" which COM instance
    > you're attaching to, but he said he was busy and hasn't gotten back to me.
    > However, I tend to believe that this is something that is pretty generic[/color]
    to[color=blue]
    > COM EXEs, and I was hoping someone out there might know and could give me[/color]
    a[color=blue]
    > tip on this?
    >
    > Thanks,
    > - Jon
    >
    >[/color]


    Comment

    • Brian Muth

      #3
      Re: Select and attach to specific COM EXE instance as COM object

      You are confusing COM object instances with COM executable instances. They
      are different.

      Generally speaking, each client will be allocated their own COM object
      whenever they call CoCreateInstanc e(Ex). Usually the same COM executable
      will act as host for all those COM object instances. For obvious reasons,
      this is usually desirable for efficiency reasons. There are exceptions to
      this scenario. For example, if there are two clients running under different
      user accounts and the COM Server executable is set up to run as the
      launching user, then COM services will start a second executable in order to
      establish a separate security boundary.

      There is no direct support from COM to do what you are asking for. However,
      I suspect there is a clever way of implementing this (with some considerable
      research on your part if you haven't done this before) by building a custom
      class factory.

      To carry this discussion further, I think it would be helpful if you would
      explain why there are multiple COM executables, how this was configured and
      why. I suspect there may be a cleaner design and a better solution at hand
      if you explained more.

      Brian


      Comment

      • Willy Denoyette [MVP]

        #4
        Re: Select and attach to specific COM EXE instance as COM object

        You can bind to a specific instance using the IRunningObjectT able & IMoniker
        interfaces, see using System.Runtime. InteropServices .ComTypes; in MSDN
        (version 2 of the Framework!).

        Willy.

        "Jon Davis" <jon@REMOVE.ME. PLEASE.jondavis .net> wrote in message
        news:Om96GQmWGH A.3740@TK2MSFTN GP03.phx.gbl...
        |I am working with an application that is compiled as a COM EXE (written in
        | Delphi 7). I don't know if it's the nature of COM EXE or if it's
        implemented
        | in the COM EXE, but when I create a new object based on the COM interface
        | using C#, it references the first process/instance it finds of this
        | interface. This is not ideal for me; I would like to create a modal dialog
        | box that makes the user select which process to "attach" to. Getting a
        list
        | of processes isn't a problem, rather it's getting my COM references in the
        | C# RCW of the COM interface to attach to the preferred COM EXE rather than
        | the first one it finds.
        |
        | I asked the developer of the app as to how to "select" which COM instance
        | you're attaching to, but he said he was busy and hasn't gotten back to me.
        | However, I tend to believe that this is something that is pretty generic
        to
        | COM EXEs, and I was hoping someone out there might know and could give me
        a
        | tip on this?
        |
        | Thanks,
        | - Jon
        |
        |


        Comment

        • Jon Davis

          #5
          Re: Select and attach to specific COM EXE instance as COM object

          > You are confusing COM object instances with COM executable instances. They[color=blue]
          > are different.[/color]

          Not at all; C# sees the COM interface, wrapped in the CLR, as an object. I
          think you might be confusing my special use of "COM object" with COM
          components or server instances.
          [color=blue]
          > There is no direct support from COM to do what you are asking for.
          > However, I suspect there is a clever way of implementing this (with some
          > considerable research on your part if you haven't done this before) by
          > building a custom class factory.[/color]

          If you're certain that COM doesn't support this without hacks then I will
          stop researching this.
          [color=blue]
          > To carry this discussion further, I think it would be helpful if you would
          > explain why there are multiple COM executables, how this was configured
          > and why. I suspect there may be a cleaner design and a better solution at
          > hand if you explained more.[/color]

          It's just a shrink-wrapped business application, compiled as an ActiveX EXE,
          that supports Active Scripting and I was extending it with .NET by running
          my own .NET process and accessing the EXE's COM interfaces. The application
          supports multiple instances though--this is useful because each one can
          point to a different database or log in as a different user--but the .NET
          process I built can only "see" the first one.

          I was also trying to "hook" into its interfaces from the Active Scripting
          environment using the COM interfaces, but with multiple processes running,
          the second instance's script would be confusing its host's COM interface
          with the first process.

          - Jon


          "Brian Muth" <bmuth@mvps.org > wrote in message
          news:eZgsDNnWGH A.1192@TK2MSFTN GP03.phx.gbl...[color=blue]
          > You are confusing COM object instances with COM executable instances. They
          > are different.
          >
          > Generally speaking, each client will be allocated their own COM object
          > whenever they call CoCreateInstanc e(Ex). Usually the same COM executable
          > will act as host for all those COM object instances. For obvious reasons,
          > this is usually desirable for efficiency reasons. There are exceptions to
          > this scenario. For example, if there are two clients running under
          > different user accounts and the COM Server executable is set up to run as
          > the launching user, then COM services will start a second executable in
          > order to establish a separate security boundary.
          >
          > There is no direct support from COM to do what you are asking for.
          > However, I suspect there is a clever way of implementing this (with some
          > considerable research on your part if you haven't done this before) by
          > building a custom class factory.
          >
          > To carry this discussion further, I think it would be helpful if you would
          > explain why there are multiple COM executables, how this was configured
          > and why. I suspect there may be a cleaner design and a better solution at
          > hand if you explained more.
          >
          > Brian
          >[/color]


          Comment

          • Jon Davis

            #6
            Re: Select and attach to specific COM EXE instance as COM object

            > There is no direct support from COM to do what you are asking for.[color=blue]
            > However, I suspect there is a clever way of implementing this (with some
            > considerable research on your part if you haven't done this before) by
            > building a custom class factory.[/color]

            If you're certain that COM doesn't support this without hacks then I will
            stop researching this.
            [color=blue]
            > To carry this discussion further, I think it would be helpful if you would
            > explain why there are multiple COM executables, how this was configured
            > and why. I suspect there may be a cleaner design and a better solution at
            > hand if you explained more.[/color]

            It's just a shrink-wrapped business application, compiled as an ActiveX EXE,
            that supports Active Scripting and I was extending it with .NET by running
            my own .NET process and accessing the EXE's COM interfaces. The application
            supports multiple instances though--this is useful because each one can
            point to a different database or log in as a different user--but the .NET
            process I built can only "see" the first one.

            I was also trying to "hook" into its interfaces from the Active Scripting
            environment using the COM interfaces, but with multiple processes running,
            the second instance's script would be confusing its host's COM interface
            with the first process.

            - Jon


            "Brian Muth" <bmuth@mvps.org > wrote in message
            news:eZgsDNnWGH A.1192@TK2MSFTN GP03.phx.gbl...[color=blue]
            > You are confusing COM object instances with COM executable instances. They
            > are different.
            >
            > Generally speaking, each client will be allocated their own COM object
            > whenever they call CoCreateInstanc e(Ex). Usually the same COM executable
            > will act as host for all those COM object instances. For obvious reasons,
            > this is usually desirable for efficiency reasons. There are exceptions to
            > this scenario. For example, if there are two clients running under
            > different user accounts and the COM Server executable is set up to run as
            > the launching user, then COM services will start a second executable in
            > order to establish a separate security boundary.
            >
            > There is no direct support from COM to do what you are asking for.
            > However, I suspect there is a clever way of implementing this (with some
            > considerable research on your part if you haven't done this before) by
            > building a custom class factory.
            >
            > To carry this discussion further, I think it would be helpful if you would
            > explain why there are multiple COM executables, how this was configured
            > and why. I suspect there may be a cleaner design and a better solution at
            > hand if you explained more.
            >
            > Brian
            >[/color]


            Comment

            • Brian Muth

              #7
              Re: Select and attach to specific COM EXE instance as COM object

              > It's just a shrink-wrapped business application, compiled as an ActiveX[color=blue]
              > EXE, that supports Active Scripting and I was extending it with .NET by
              > running my own .NET process and accessing the EXE's COM interfaces. The
              > application supports multiple instances though--this is useful because
              > each one can point to a different database or log in as a different
              > user--but the .NET process I built can only "see" the first one.[/color]

              I'm still confused. Define what you mean by the last phrase: "... the .NET
              process can only "see" the first one."

              The first what? EXE? or COM instance?

              As I said before, you should only have one EXE but that EXE can host
              multiple COM instances.

              Brian


              Comment

              • Jon Davis

                #8
                Re: Select and attach to specific COM EXE instance as COM object


                "Brian Muth" <bmuth@mvps.org > wrote in message
                news:OXPhU%23qX GHA.4248@TK2MSF TNGP05.phx.gbl. ..[color=blue][color=green]
                >> It's just a shrink-wrapped business application, compiled as an ActiveX
                >> EXE, that supports Active Scripting and I was extending it with .NET by
                >> running my own .NET process and accessing the EXE's COM interfaces. The
                >> application supports multiple instances though--this is useful because
                >> each one can point to a different database or log in as a different
                >> user--but the .NET process I built can only "see" the first one.[/color]
                >
                > I'm still confused. Define what you mean by the last phrase: "... the .NET
                > process can only "see" the first one."
                >
                > The first what? EXE? or COM instance?[/color]

                Process. (EXE instance.)
                [color=blue]
                > As I said before, you should only have one EXE but that EXE can host
                > multiple COM instances.[/color]

                As I said before, there already are multiple EXE instances, and third party
                EXEs and COM objects must talk to them individually; I'm trying to figure
                out how. Come to think of it I think I can implement what I need using
                Remoting or Indigo; fortunately, each EXE instance is scriptable.

                Jon


                Comment

                • Jon Davis

                  #9
                  Re: Select and attach to specific COM EXE instance as COM object

                  Somehow I overlooked this yesterday when I replied to Brian. Thanks Willy!!

                  Jon


                  "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                  news:OQkqOSnWGH A.1204@TK2MSFTN GP04.phx.gbl...[color=blue]
                  > You can bind to a specific instance using the IRunningObjectT able &
                  > IMoniker
                  > interfaces, see using System.Runtime. InteropServices .ComTypes; in MSDN
                  > (version 2 of the Framework!).
                  >
                  > Willy.
                  >
                  > "Jon Davis" <jon@REMOVE.ME. PLEASE.jondavis .net> wrote in message
                  > news:Om96GQmWGH A.3740@TK2MSFTN GP03.phx.gbl...
                  > |I am working with an application that is compiled as a COM EXE (written
                  > in
                  > | Delphi 7). I don't know if it's the nature of COM EXE or if it's
                  > implemented
                  > | in the COM EXE, but when I create a new object based on the COM
                  > interface
                  > | using C#, it references the first process/instance it finds of this
                  > | interface. This is not ideal for me; I would like to create a modal
                  > dialog
                  > | box that makes the user select which process to "attach" to. Getting a
                  > list
                  > | of processes isn't a problem, rather it's getting my COM references in
                  > the
                  > | C# RCW of the COM interface to attach to the preferred COM EXE rather
                  > than
                  > | the first one it finds.
                  > |
                  > | I asked the developer of the app as to how to "select" which COM
                  > instance
                  > | you're attaching to, but he said he was busy and hasn't gotten back to
                  > me.
                  > | However, I tend to believe that this is something that is pretty generic
                  > to
                  > | COM EXEs, and I was hoping someone out there might know and could give
                  > me
                  > a
                  > | tip on this?
                  > |
                  > | Thanks,
                  > | - Jon
                  > |
                  > |
                  >
                  >[/color]


                  Comment

                  • Jon Davis

                    #10
                    Re: Select and attach to specific COM EXE instance as COM object

                    Willy,

                    These are interfaces; does the app need to implement these as a starting
                    point in order to allow for the functionality I seek?

                    I am not on the dev team that built the app, so that won't work for me. I
                    suppose I will have to pursue other avenues (remoting, etc), unless you can
                    assist me further.

                    Thanks,
                    Jon


                    "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
                    news:OQkqOSnWGH A.1204@TK2MSFTN GP04.phx.gbl...[color=blue]
                    > You can bind to a specific instance using the IRunningObjectT able &
                    > IMoniker
                    > interfaces, see using System.Runtime. InteropServices .ComTypes; in MSDN
                    > (version 2 of the Framework!).
                    >
                    > Willy.
                    >
                    > "Jon Davis" <jon@REMOVE.ME. PLEASE.jondavis .net> wrote in message
                    > news:Om96GQmWGH A.3740@TK2MSFTN GP03.phx.gbl...
                    > |I am working with an application that is compiled as a COM EXE (written
                    > in
                    > | Delphi 7). I don't know if it's the nature of COM EXE or if it's
                    > implemented
                    > | in the COM EXE, but when I create a new object based on the COM
                    > interface
                    > | using C#, it references the first process/instance it finds of this
                    > | interface. This is not ideal for me; I would like to create a modal
                    > dialog
                    > | box that makes the user select which process to "attach" to. Getting a
                    > list
                    > | of processes isn't a problem, rather it's getting my COM references in
                    > the
                    > | C# RCW of the COM interface to attach to the preferred COM EXE rather
                    > than
                    > | the first one it finds.
                    > |
                    > | I asked the developer of the app as to how to "select" which COM
                    > instance
                    > | you're attaching to, but he said he was busy and hasn't gotten back to
                    > me.
                    > | However, I tend to believe that this is something that is pretty generic
                    > to
                    > | COM EXEs, and I was hoping someone out there might know and could give
                    > me
                    > a
                    > | tip on this?
                    > |
                    > | Thanks,
                    > | - Jon
                    > |
                    > |
                    >
                    >[/color]


                    Comment

                    Working...