GithubHelp home page GithubHelp logo

test-mass-forker-org-1 / component-object-model-sample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoft/component-object-model-sample

0.0 0.0 0.0 53 KB

Sample code for Component Object Model (COM) setup and registration.

License: MIT License

C++ 91.15% C 8.85%

component-object-model-sample's Introduction

Component Object Model (COM) Sample

COM is a very powerful technology to componentize software based on object oriented design. Please see documentation here for more details.

One of the major drawbacks of COM is the initial boilerplate required to set up the COM components. ATL is a set of libraries that help build the boilerplate, but comes with its own complexity.

This sample here provides the skeletal code that would do the heavylifting of COM setup and registration so that developers can focus on the business logic alone rather than worrying about the infrastructure. It does not use ATL. Instead it uses simple plain C++ code so that developers can understand and debug the underlying skeleton if required.

Terms used

  • A COM Server is an object that provides the business logic.
  • A COM Client is the code that access the COM Server through any interface exposed by the COM Server.
  • The interaction between the COM Client and COM Server happens via marshaling, and requires a Proxy-Stub DLL.
  • Please see documentation here for more details.

This project

Here is the summary about the various directories in this sample.

  • ComSampleProxy: ProxyStub DLL. To add a new interface, simply add a new IDL file to the project.
  • COMSampleServer: Support for activating the COM Server in-process as well as out-of-process (in an OS provided DLL Surrogate namely DllHost.exe).
  • COMSampleService: Support for activating the COM Server in a LocalSystem Service.
  • ComSampleClient: A sample COM Client that calls into and tests the COM Servers mentioned above.

Creating and registering a new COM Component

Creating a new COM component is super easy with this model.

  1. Add your interface:
  • Add a new IDL file with your interface to ComSampleProxy project. See sample file /ComSampleProxy/IComTest.idl.
  1. Implement your COM class:
  • For in-process activation or out-of-process in surrogate activatation: Add your class implementation to ComSampleServer project. See example ComSampleServer/CComServerTest.cpp. Now go to ComSampleServer/Dll.cpp and simply add your class entries to "g_Classes".
  • For out-of-process activation in a LocalSystem service: Add your add your class implementation to ComSampleService project. See example ComSampleService/CComServiceTest.cpp. Now go to ComSampleService/Main.cpp and simply add your class entries to "g_Classes".
  1. Register your COM components:
  • Copy ComSampleProxy.dll onto your target machine. From an elevated prompt, run: regsvr32 ComSampleProxy.dll.
  • For in-process activation or out-of-process in surrogate activatation: Copy ComSampleServer.dll onto your target machine. From an elevated prompt, run: regsvr32 ComSampleServer.dll.
  • For out-of-process activation in a LocalSystem service: Copy ComSampleService.exe onto your target machine. From an elevated command prompt, run: ComSampleService.exe /RegisterServer.

That is it!

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must followMicrosoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

component-object-model-sample's People

Contributors

microsoftopensource avatar chittur avatar microsoft-github-operations[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.