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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. COM
  4. Converting exe to com

Converting exe to com

Scheduled Pinned Locked Moved COM
c++com
9 Posts 3 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.
  • A Offline
    A Offline
    ashokvishnu
    wrote on last edited by
    #1

    Hi All, We have a project which is standard exe. Our new requirement is to convert it into a COM application. I would like to know what are the minimum steps required to make a standard exe application (that is make minimal changes to existing code)into a COM one. Any links or suggestions would be most welcome. Thanks

    C++beginer

    M 1 Reply Last reply
    0
    • A ashokvishnu

      Hi All, We have a project which is standard exe. Our new requirement is to convert it into a COM application. I would like to know what are the minimum steps required to make a standard exe application (that is make minimal changes to existing code)into a COM one. Any links or suggestions would be most welcome. Thanks

      C++beginer

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      I have to ask why you want a 'COM application'. Generally the only reasons for exposing existing code as COM objects are to support OLE linking and embedding, or to offer an automation interface to allow your program (and its data) to be manipulated by another application. If you simply want to write some COM objects which run in another process context, with no user interface, you generally don't start from an existing program. If I were starting from scratch in C++ I would use the ATL AppWizard to generate a new EXE project. The easiest way to support the first two requirements - OLE and/or Automation - will depend on the language and libraries you have used to produce your application. If you're already using MFC, you will probably want to use MFC's OLE support, which is based around the CDocument class. See the Servers: Implementing a Server[^] topic in MSDN Library. If you're using C++ but not MFC you may find ATL helpful. However, it's pretty complex for a beginner.

      Stability. What an interesting concept. -- Chris Maunder

      A 1 Reply Last reply
      0
      • M Mike Dimmick

        I have to ask why you want a 'COM application'. Generally the only reasons for exposing existing code as COM objects are to support OLE linking and embedding, or to offer an automation interface to allow your program (and its data) to be manipulated by another application. If you simply want to write some COM objects which run in another process context, with no user interface, you generally don't start from an existing program. If I were starting from scratch in C++ I would use the ATL AppWizard to generate a new EXE project. The easiest way to support the first two requirements - OLE and/or Automation - will depend on the language and libraries you have used to produce your application. If you're already using MFC, you will probably want to use MFC's OLE support, which is based around the CDocument class. See the Servers: Implementing a Server[^] topic in MSDN Library. If you're using C++ but not MFC you may find ATL helpful. However, it's pretty complex for a beginner.

        Stability. What an interesting concept. -- Chris Maunder

        A Offline
        A Offline
        ashokvishnu
        wrote on last edited by
        #3

        Actually its a requirement from the client. The existing app is used as a component manager. It is used to start/stop/activate/deactivate etc other modules. Now the client is changing the interfaces of the other modules. And we will have to use those changed interface. So its not a question of converting an exe to com, rather we have to make it a com server. How we do it is left to us. Either we can start from the scratch (that will be lot rework) and build a com application or use the existing one, make the necessary changes with respect to com standards and run it as a com server. I hope you got the point.

        C++beginer

        M M 2 Replies Last reply
        0
        • A ashokvishnu

          Actually its a requirement from the client. The existing app is used as a component manager. It is used to start/stop/activate/deactivate etc other modules. Now the client is changing the interfaces of the other modules. And we will have to use those changed interface. So its not a question of converting an exe to com, rather we have to make it a com server. How we do it is left to us. Either we can start from the scratch (that will be lot rework) and build a com application or use the existing one, make the necessary changes with respect to com standards and run it as a com server. I hope you got the point.

          C++beginer

          M Offline
          M Offline
          mpk1979
          wrote on last edited by
          #4

          Hi, you need not write it from the scratch, if it is a c++ application, just register your application with SCM(service control manager)so that an entry is made into SCM for controlling your service..just what you need is two functions... Service_main and Service_CtrlHandler in the start up you will be giving Service_main function to SCM and inside Service_Main you will be registering Service_CtrlHandler...normally Service_CtrlHandler will be containing evets like SERVICE_STOP, SERVICE_PAUSE e.t.c...so when ever you are performing an event like SERVICE_STOP, Service_CtrlHandler will be called to perform necessary functionality.Hope this will help you mpk1979

          M 1 Reply Last reply
          0
          • M mpk1979

            Hi, you need not write it from the scratch, if it is a c++ application, just register your application with SCM(service control manager)so that an entry is made into SCM for controlling your service..just what you need is two functions... Service_main and Service_CtrlHandler in the start up you will be giving Service_main function to SCM and inside Service_Main you will be registering Service_CtrlHandler...normally Service_CtrlHandler will be containing evets like SERVICE_STOP, SERVICE_PAUSE e.t.c...so when ever you are performing an event like SERVICE_STOP, Service_CtrlHandler will be called to perform necessary functionality.Hope this will help you mpk1979

            M Offline
            M Offline
            Mike Dimmick
            wrote on last edited by
            #5

            I think you've misunderstood the question - or possibly I have - but it sounds like this application needs to load COM objects, not be turned into a service.

            Stability. What an interesting concept. -- Chris Maunder

            M 1 Reply Last reply
            0
            • A ashokvishnu

              Actually its a requirement from the client. The existing app is used as a component manager. It is used to start/stop/activate/deactivate etc other modules. Now the client is changing the interfaces of the other modules. And we will have to use those changed interface. So its not a question of converting an exe to com, rather we have to make it a com server. How we do it is left to us. Either we can start from the scratch (that will be lot rework) and build a com application or use the existing one, make the necessary changes with respect to com standards and run it as a com server. I hope you got the point.

              C++beginer

              M Offline
              M Offline
              Mike Dimmick
              wrote on last edited by
              #6

              So you're saying that the interface to the other modules is changing from a flat interface (calling into DLL entry points) to a COM interface (calling through an interface pointer)? The client should be able to supply you with the interface that the other modules will expose. Ideally they would be able to supply the .idl file containing the interface definition(s) or the .h file that is generated from the .idl. Worst case, you might have to use #import to get the compiler to extract the interface(s) from a type library. It depends how the components are implemented; if they're in C++ you can probably get the .idl or header. You will have to compile the IDL with the MIDL tool. If you just need to manipulate, call through, those interfaces, you don't really need to do anything special. I normally use ATL's CComPtr and CComQIPtr class templates to manage the reference counts properly. Include the atlbase.h header to use these templates. If the component has to call back into your manager application, then you will have to check with the client how they intend to do this. The simplest way from your application's perspective is if you define a regular COM interface containing the methods that the component will call, and pass this to a method in the component's interface. You will then need to implement a class that implements the interface. You might find ATL helpful to do this. If the components are written in some other language, they may not be able to handle this. They might be raising events using the Automation event mechanism. This will require you to implement the dispatch interface defined in the component's type library (shown as a 'source' interface) so that the component can call you back, and to call the component's connection point container to connect your callback interface to the component. See ATL's CONNECT sample[^] for an example of how to do this.

              Stability. What an interesting concept. -- Chris Maunder

              A 1 Reply Last reply
              0
              • M Mike Dimmick

                So you're saying that the interface to the other modules is changing from a flat interface (calling into DLL entry points) to a COM interface (calling through an interface pointer)? The client should be able to supply you with the interface that the other modules will expose. Ideally they would be able to supply the .idl file containing the interface definition(s) or the .h file that is generated from the .idl. Worst case, you might have to use #import to get the compiler to extract the interface(s) from a type library. It depends how the components are implemented; if they're in C++ you can probably get the .idl or header. You will have to compile the IDL with the MIDL tool. If you just need to manipulate, call through, those interfaces, you don't really need to do anything special. I normally use ATL's CComPtr and CComQIPtr class templates to manage the reference counts properly. Include the atlbase.h header to use these templates. If the component has to call back into your manager application, then you will have to check with the client how they intend to do this. The simplest way from your application's perspective is if you define a regular COM interface containing the methods that the component will call, and pass this to a method in the component's interface. You will then need to implement a class that implements the interface. You might find ATL helpful to do this. If the components are written in some other language, they may not be able to handle this. They might be raising events using the Automation event mechanism. This will require you to implement the dispatch interface defined in the component's type library (shown as a 'source' interface) so that the component can call you back, and to call the component's connection point container to connect your callback interface to the component. See ATL's CONNECT sample[^] for an example of how to do this.

                Stability. What an interesting concept. -- Chris Maunder

                A Offline
                A Offline
                ashokvishnu
                wrote on last edited by
                #7

                Well our requirement is to turn our exe into a com server. The question is whether we can do so without starting from the scratch. What I am looking at is, we will add the COM interface and implementing classes to the project and build the exe as a com exe by, if possible changing the project settings. I was just wondering is there any well defined steps for this.

                C++beginer

                M 1 Reply Last reply
                0
                • M Mike Dimmick

                  I think you've misunderstood the question - or possibly I have - but it sounds like this application needs to load COM objects, not be turned into a service.

                  Stability. What an interesting concept. -- Chris Maunder

                  M Offline
                  M Offline
                  mpk1979
                  wrote on last edited by
                  #8

                  ohh, sorry i think i have misunderstood it

                  1 Reply Last reply
                  0
                  • A ashokvishnu

                    Well our requirement is to turn our exe into a com server. The question is whether we can do so without starting from the scratch. What I am looking at is, we will add the COM interface and implementing classes to the project and build the exe as a com exe by, if possible changing the project settings. I was just wondering is there any well defined steps for this.

                    C++beginer

                    M Offline
                    M Offline
                    mpk1979
                    wrote on last edited by
                    #9

                    yes, you need to add your functionality to interfaces and implement a class for it. i think ATL would be the best option mpk1979

                    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