Writing an ActiveX Control in .NET

Writing an ActiveX Control in .NET

 
In this example, I will walk you through creating an ActiveX control that will show a simple user interface and accept input from a web page.
 
Technologies: .NET 1.0/1.1,Visual C# .NET
 

Software developers have used ActiveX controls on their web pages to add advanced functionality to the web experience. With my migration from a Visual Basic 6 world to a Microsoft .NET C# world, I had some question as to how I can create an ActiveX control with .NET. After some research I found out that the solution is really quite simple. Create a Windows control project in Visual Studio .NET and expose an interface to the COM world.

In this example, I will walk you through creating an ActiveX control that will show a simple user interface and accept input from a web page. This process will involve the following steps:

  1. Create an assembly (class library project) that contains an item of type User Control.
  2. Expose an interface for the control.
  3. Embed the user control into a web page.
  4. Transfer data from a web form to the control and display the data on the control.

Step 1: Create an assembly.

You can use the example provided for download, or simply create your own project from scratch. In this section I will outline everything you need to do in order to properly create your assembly.

First, you create a new project of type Class Library. Name the class library ActiveXDotNet.




Once the project is created, delete the Class1.cs file from your project as it will not be necessary. Next, add a User Control to the project by right clicking on the project in your solution explorer, choose Add, then User Control. Name your user control myControl.





On the user control, add some UI elements, and a text box control named txtUserText. The txtUserText control will display the user data that is typed into the web form. This will demonstrate how to pass data to your User Control.

When you are done adding your user interface to the control we now have to add a key element to the control, an Interface. The interface will allow COM/COM+ objects to know what properties they can use. In this case, we are going to expose one public property named UserText. That property will allow us to set the value of the text box control.

Step 2: Expose the Interface for the control.

First, create a private String to hold the data passed from the web form to the control:

private String mStr_UserText;

Place this String just inside the Class myControl.

Next, we will create a public property. The web page will use this property to pass text back to your control. This property will allow reading and writing of the value mStr_UserText.

public String UserText
{
get { return mStr_UserText; }
set
{
mStr_UserText =
value;
//Update the text box control value also.
txtUserText.Text = value;
}
}

In this example, you will note the extra code in the set section of the public property. When a value is passed from the web form to the control we will set the private String value equal to the value passed to the property. In addition, we are simply going to modify the value of the Text Box control directly. Typically you would NOT do this. Instead, you would raise an event and then validate the data being passed by examining the private variable mStr_UserText. Then you would set the value of the Text Box Control. However, that would add significant code to this example and for simplicity sake I am omitting that security precaution.

Now that you have a public property that .NET assemblies can use, you need to make that property available to the COM world. We do this by creating an Interface and making the myControl class inherit the interface. This will allow COM objects to see what properties we have made available.

Your code will now look like this:

namespace ActiveXDotNet
{
public interface AxMyControl
{
String UserText {
set; get ; }
}
public class myControl : System.Windows.Forms.UserControl, AxMyControl
{
private String mStr_UserText;
public String UserText
{
get { return mStr_UserText; }
set
{
mStr_UserText =
value;
//Update the text box control value also.
txtUserText.Text = value;
}
}
...

Notice that we now have an interface defined, the interface tells COM/COM+ that there is a public property available for use that is of type String and is readable (get) and writeable (set). All we do now is have the Class myControl inherit the interface and viola! We have a .NET assembly that acts like an ActiveX Control.

Step 3: Embed the user control in a web page.

The last thing we do now is use the control in an example web page.

<html>
 <body color=white>
  <hr>  
      <font face=arial size=1>
       <OBJECT id="myControl1" name="myControl1" classid="ActiveXDotNet.dll#ActiveXDotNet.myControl" width=288 height=72>
       </OBJECT>
     </font>  
     <form name="frm" id="frm">
       <input type="text" name="txt" value="enter text here"><input type=button value="Click me" onClick="doScript();">
      </form>
  <hr>
 </body> 
<script language="javascript">
      function doScript()
       {
        myControl1.UserText = frm.txt.value;
       }
</script>
</html>

You will notice in the HTML code above, that you call your .NET assembly very similar to an ActiveX control; however there is no GUID, and no .OCX file. Your CLASSID is now the path to your DLL and the Namespace.Classname identifier. Refer to the code above to understand the syntax of the CLASSID object tag property. Place the HTML file and your DLL in the same directory on your web server and navigate to the HTML document. (Do not load the HTML document by double clicking on it, navigate to it in your browser by using the Fully Qualified URL.) *NOTE: You might need to add your web server to your Trusted Sites list in your Internet Explorer browser.

Step 4: Transfer data from the web form to the user control.

When you load the HTML page, your control should load into the page and you will see a web form with a text box and a button. In this example, if you type some text into the text box and click the button, it will use JavaScript to send the text from the web page form, to the User Control that you just built. Your User Control will then display the text in the Text Box control that I on the form.

Where do I go from here?

There are many issues that you should investigate in order to properly create User Controls that work on a web page. .NET Security plays a big part in what you can actually do within the confines of your code. You should also investigate code signing your control.


 

sweet SSMS

Kitni jaldi ye mulakat guzar jati hai, payas bujhti nahi barsat guzar jati hai,apni yadon se kehdo is tarah na aaya kare ,need aati nahi our raat guzar jati hai


When I was alone I miss u most !
When I stay with others , I knew the value of u !
When U R with me I like to miss this whole world ……..


SOME SAY-love is a dynamic complexity of matters
" "- love is laughing with others not at them
" "-some say love is a disease ,then if it's SO I AM AT THE LAST STAGE


When I was alone I miss u most !
When I stay with others , I knew the value of u !
When U R with me I like to miss this whole world ……..

sweet SMS

1. Measured by miles,
U r far from me ....
Measures by thoughts
U r closer to me...
Measured by closed eyes
U r with me ....
Measured by heart
U r in me......

2. The height of pain in life is to sit near the person
u love d most .....
knowing that the person can neve b urs ...!!!!!

3. Never ask for a SMILE.....
JUST GIVE IT !
Never expect love from others ...
JUST LOVE THEM!
Never say I can't leav without u ...
JUST SAY I LIVE FOR U !!!!!!!!!!

4. Never try alone to take the weights of tear
that comes out of ur heart &
falls through ur eyes ……..
ALWAYS REMEMBER A FRIEND IS HERE TO SHARE…..!

5. A Wonderful saying ….
"Trying to forget someone you love is like
Trying to remember someone u've never met ..!!!"

6. When I was alone I miss u most !
When I stay with others , I knew the value of u !
When U R with me I like to miss this whole world ……..

7. Hundred words does not give pain…..
But
A true friend s silence makes more tears in heart ……
So always keep in touch my FRIEND………….

8. Liking U is my nature ,
Missing U is my disappointment …..
Fighting with U is my Time pass…
Forgetting U is never in my life time …..

9. I Hide my tears when I say ur name
But
The pain in my heart is still the same
Altho
I smile and seem carefree,
There 's No one who misses u More than me …!!!

10. Never Ignore a person who
Luvs u
Cares 4 u &
Misses U
Bcoz
One day u may wake up frm ur sleep
And realize that u've lost the moon while counting stars ……..!!!!

Sony Ericsson Secret Codes

To get Sony Ericsson Secret Menu:
-> * <- <- * <- *
(-> means press joystick, arrow keys or jogdial to the right and <- means left.)
You'll see phone model, software info, IMEI, configuration info, sim lock status, REAL time clock, total call time and text labels.
You can also test your phones services and hardware from this menu (main display, camera, LED/illumination, Flash LED, keyboard, earphone, speaker, microphone, radio and vibrator tests)

IMEI Number: *#06#
Lockstatus: <- * * <-
Shortcut to last dialed numbers: 0#
Shortcut to sim numbers: On main menu type a number and press #

If you change the language from default to any other language, then it may be difficult to switch to default language. The shortcut is very simple. Older Ericssons *#0000# & Newer Ericssons <0000> & Also, pressing <8888> on the newer Ericssons changes the language to Automatic. < stands for left arrow button or joystick and > stands for right arrow button or joystick.

Copy & Paste when using phonebook:
Go into "Edit contact", and select the Contact
Scroll down to the number you want to cut and paste.
Without selecting it (ie without clicking on the joystick or the yes button) press and hold the * key, and then press the 1 key. When you release both keys, the highlighted number should disappear
Now move to the appropriate entry (eg the "Mob" entry) and press and hold the * key, then press the 3 key. When you release both, the number is pasted into this entry. (1 for cut, 2 for copy and 3 for paste)

If you've cleared your call list you can easily find unsaved dialed no:
Go to Message then Write New & Press yes. Click on Continue. In the menu to let you key in the number to send msg, press the right up key for more menu & you go to the following list.
Phone book, Groups, Sim entries and Unsaved nos.
Select Unsaved nos, there you will see last 10 unsaved number.
Those numbers can't be erased even you clear your entire call list.

Nokia Code

*#06# for checking the IMEI (International Mobile Equipment Identity).

*#7780# reset to factory settings.

*#67705646# This will clear the LCD display(operator logo).

*#0000# To view software version.

*#2820# Bluetooth device address.

*#746025625# Sim clock allowed status.

#pw+1234567890+1# Shows if sim have restrictions.

*#92702689# - takes you to a secret menu where you may find some of the information below:

1. Displays Serial Number.
2. Displays the Month and Year of Manufacture
3. Displays (if there) the date where the phone was purchased (MMYY)
4. Displays the date of the last repair - if found (0000)
5. Shows life timer of phone (time passes since last start)

*#3370# - Enhanced Full Rate Codec (EFR) activation. Increase signal strength, better signal reception. It also help if u want to use GPRS and the service is not responding or too slow. Phone battery will drain faster though.

*#3370* - (EFR) deactivation. Phone will automatically restart. Increase battery life by 30% because phone receives less signal from network.

*#4720# - Half Rate Codec activation.

*#4720* - Half Rate Codec deactivation. The phone will automatically restart
If you forgot wallet code for Nokia S60 phone, use this code reset: *#7370925538#
Note, your data in the wallet will be erased. Phone will ask you the lock code. Default lock code is: 12345

Press *#3925538# to delete the contents and code of wallet.

Unlock service provider: Insert sim, turn phone on and press vol up(arrow keys) for 3 seconds, should say pin code. Press C,then press * message should flash, press * again and 04*pin*pin*pin# \

*#7328748263373738# resets security code.
Default security code is 12345
Change closed caller group (settings >security settings>user groups) to 00000 and ure phone will sound the message tone when you are near a radar speed trap. Setting it to 500 will cause your phone 2 set off security alarms at shop exits, gr8 for practical jokes! (works with some of the Nokia phones.) Press and hold "0" on the main screen to open wap browser.