Click here to Skip to main content
Click here to Skip to main content

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

, 6 Aug 2002
Rate this:
Please Sign up or sign in to vote.
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:

  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:

  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:

  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.

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

  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).

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

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

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

  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).

  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:

  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.

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

  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.

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

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

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

Share

About the Author

MADHANMOHAN
Web Developer
India India
No Biography provided

Comments and Discussions

 
Generalthank uuu!!!!!!! PinmemberMember 999976519-Apr-13 8:17 
GeneralNative Pinmembersenproin14-Dec-05 23:26 
Are you from Tamil Nadu.
GeneralAdding Events PinmemberMassoud.Kh9-Sep-04 18:23 
GeneralGood article for beginner PinsussAnonymous7-Aug-02 16:02 
GeneralRe: Good article for beginner PinsussAnonymous28-Oct-02 5:41 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411019.1 | Last Updated 7 Aug 2002
Article Copyright 2002 by MADHANMOHAN
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid