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.
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).
Creating an ActiveX control into a COM server.
- Open VC++ Application.
- In File Menu, Click New.
- In the popup window click the Project tab and select ATLCOM AppWizard (Refer figure 1).
- Give any name you like( I have given name as Test).
- After clicking OK, accept the default settings in the Wizard (Refer figure 2).
- Accept the New Project Information.
- We have the basic framework of our Component.
- Class view in workspace window will be like this:
- We can add controls to our component.
- For this click New ATL object from the task bar.
- ATL object wizard will be displayed.
- In the Category Area select Controls, then select
FullControl from Objects Area.
- 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).
- Now a new interface will be created.
- Class view will look like this:
- Right Click the interface in the class view(a class with lollypop symbol).
- Click Add Property.
- A Property sheet will be displayed.
- Enter the following:
- Property Type (in my example long).
- Property Name (in our example cube and square. i.e., two properties separately).
- Parameters (in our case no parameters).
- There is no parameter because, put method will accept one parameter and get method will give away one parameter (see the generated definiton).
- Add the required code as given below:
- Build the project.
- If no error, then the component is generated and it is running in your system.
- You can use it in your client application.
Building a Client
- Open VB.
- Create Standard exe project.
- Open Project from menu.
- In this, select components.
- In components, scroll to find Test 1.0 Type Library and check it.
- Click Ok, now you will find an ICON in red color in your toolbar (I have circled to easily notify you).
- Click the icon and drag into your form.
- Default properties along with our defined property will come in the property sheet.
- Now our control can be treated as normal controls in VB.
- You can fix the property at design time as well as run time.
- Please check out the code I have given so that you get the idea of using a user defined property.
- 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 .
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.