Click here to Skip to main content
15,879,535 members
Articles / Desktop Programming / ATL
Article

Simple Example to show the functioning of ActiveX control with VB client in ATL COM

Rate me:
Please Sign up or sign in to vote.
4.27/5 (8 votes)
6 Aug 20023 min read 79.4K   923   25   5
Using an ActiveX control in COM Server. Accessing the Server using a VB Client.

Introduction

My application is used to add a simple ActiveX control in COM Server and add the ActiveX control into a VB client. We can check for the correct functioning of the control in VB client. For checking the client application, please build the DLL from test.zip and then run VB client.

Two properties are available from the server.

  1. square.
  2. cube.

These two properties does mathematical calculation as its name indicates.

For embedding it into your VB project go to the Components settings in project menu and locate the DLL namely Test 1.0 Type Library. Then check it. This task I have given diagram for easy understanding. After you add the control, an icon will come in the tool bar. Just drag the control and put it in your form. Now you can access all the properties defined in that control (in this case you have two properties).

STEP 1

Creating an ActiveX control into a COM server.

  1. Open VC++ Application.
  2. In File Menu, Click New.
  3. In the popup window click the Project tab and select ATLCOM AppWizard (Refer figure 1).

    Figure1:

    Image 1

  4. Give any name you like( I have given name as Test).
  5. After clicking OK, accept the default settings in the Wizard (Refer figure 2).

    Figure2:

    Image 2

  6. Accept the New Project Information.
  7. We have the basic framework of our Component.
  8. Class view in workspace window will be like this:

    Image 3

  9. We can add controls to our component.
  10. For this click New ATL object from the task bar.
  11. ATL object wizard will be displayed.

    Image 4

  12. In the Category Area select Controls, then select FullControl from Objects Area.

    Image 5

  13. Click Next. In short name, enter SomeProperty and click Ok (I am taking every thing as default in this screen, if you want, you can modify your self).

    Image 6

  14. Now a new interface will be created.
  15. Class view will look like this:

    Image 7

  16. Right Click the interface in the class view(a class with lollypop symbol).

    Image 8

  17. Click Add Property.
  18. A Property sheet will be displayed.

    Image 9

  19. Enter the following:
    1. Property Type (in my example long).
    2. Property Name (in our example cube and square. i.e., two properties separately).
    3. Parameters (in our case no parameters).

    Image 10

  20. There is no parameter because, put method will accept one parameter and get method will give away one parameter (see the generated definiton).
  21. Add the required code as given below:

    Image 11

  22. Build the project.
  23. If no error, then the component is generated and it is running in your system.
  24. You can use it in your client application.

Step2

Building a Client

  1. Open VB.
  2. Create Standard exe project.
  3. Open Project from menu.
  4. In this, select components.
  5. In components, scroll to find Test 1.0 Type Library and check it.

    Image 12

  6. Click Ok, now you will find an ICON in red color in your toolbar (I have circled to easily notify you).

    Image 13

  7. Click the icon and drag into your form.
  8. Default properties along with our defined property will come in the property sheet.
  9. Now our control can be treated as normal controls in VB.
  10. You can fix the property at design time as well as run time.
  11. Please check out the code I have given so that you get the idea of using a user defined property.
  12. My application screen shots
  • ScreenShot 1: Default Form when run.

    Image 14

  • ScreenShot 2: When I gave value 2 and pressed square button.

    Image 15

  • ScreenShoot 3: When I pressed Cube button with 2 as value .

    Image 16

Thank you.

This is my first article of life. I have tried my level best to explain you the things. I will improve myself in future articles.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralGood article for beginner Pin
Anonymous7-Aug-02 15:02
Anonymous7-Aug-02 15:02 
Thanks . It's a good article for beginner.

GeneralRe: Good article for beginner Pin
Anonymous28-Oct-02 4:41
Anonymous28-Oct-02 4:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.