SlideShare a Scribd company logo
1 of 9
Download to read offline
Steps how to create activeX using Visual Studio 2008 (Details Steps)
Written by: Yudep Apoi
INFORMATION: This information is derived from: Creating an ActiveX control in .Net
using C# by Olav Aukan
1. Open your Visual Studio 2008.
FILE > New Project
Select Visual C# > Class Library
Name your project as AxControls
2. Rename your Class1.cs to HelloWorld.cs
Right Click on project AxControls to add reference System.Windows.Form
3. Create a new interface that exposes the controls methods and properties to
COM interop.
Right click the project in Visual Studio and click Add –> New Item
Select ‘Interface’ from the list of components, named it as ‘IHelloWorld.cs’ and
click add.
Replace the code with this:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace AxControls
{
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("E66C39CB-BB8B-4738-AA0E-5E0D1F2DB230")]
public interface IHelloWorld
{
string GetText();
}
}
[ComVisible(true)] makes the interface visible to COM.
[Guid("E66C39CB-BB8B-4738-AA0E-5E0D1F2DB230")] lets us manually assign a
GUID to the interface. Use guidgen.exe to generate your own.
4. Mark the control as safe for scripting and initialization. By default IE will not
allow initializing and scripting an ActiveX control unless it is marked as safe. This
means that we won’t be able to create instances of our ActiveX class with
JavaScript by default. We can get around this by modifying the browser security
settings, but a more elegant way would be to mark the control as safe. Before
you do this to a “real” control, be sure to understand the consequences. We will
mark the control as safe by implementing the IObjectSafety interface.
Right click the project in Visual Studio and click Add -> New Item.
Select ‘Interface’ from the list of components, name it ‘IObjectSafety.cs’ and click
Add.
Put these lines of codes inside IObjectSafety.cs:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace AxControls
{
[ComImport()]
[Guid("51105418-2E5C-4667-BFD6-50C71C5FD15C")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IObjectSafety
{
[PreserveSig()]
int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out
int pdwEnabledOptions);
[PreserveSig()]
int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int
dwEnabledOptions);
}
}
5. Go to HelloWorld make the HelloWorld class implement the IObjectSafety
interface by replacing HelloWorld.cs with these lines of code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace AxControls
{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("D100C392-030A-411C-92B6-4DBE9AC7AA5A")]
[ProgId("AxControls.HelloWorld")]
[ComDefaultInterface(typeof(IHelloWorld))]
public class HelloWorld : UserControl, IHelloWorld, IObjectSafety
{
#region IHelloWorld Members
public string GetText()
{
return "Hello ActiveX World!";
}
#endregion
#region IObjectSafety Members
public enum ObjectSafetyOptions
{
INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001,
INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002,
INTERFACE_USES_DISPEX = 0x00000004,
INTERFACE_USES_SECURITY_MANAGER = 0x00000008
};
public int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions,
out int pdwEnabledOptions)
{
ObjectSafetyOptions m_options =
ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_CALLER |
ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_DATA;
pdwSupportedOptions = (int)m_options;
pdwEnabledOptions = (int)m_options;
return 0;
}
public int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int
dwEnabledOptions)
{
return 0;
}
#endregion
}
}
6. Create a .msi installer for the control. Before an ActiveX control can be used it
must be installed and registered on the client. This can be done in a number of
ways, from manually editing the registry to using regasm.exe, but we’re going to
create a Vistual Studio setup project to handle the installation for us.
Right click the Visual Studio solution, select Add -> New Project and select Setup
Project under Other Project Types.
Call the project ‘AxControlsInstaller’ and click OK.
But before that you need to save the project. I named the folder as AxControl1.
Then click save.
After saved this interface will appear.
Right click the ‘AxControlsInstaller’ project, select Add -> Project Output, select
‘Primary output’ from the ‘AxControls’.
Right click 'Primary output from AxControls (Active)' and select Properties.
Change the Register property from 'vsdrpDoNotRegister' to 'vsdrpCOM'.
Right click the 'AxControlsInstaller' project and select Build.
The installer should now be located in the AxControlsInstaller's output folder
(binDebug or binRelease). In the corporate domain this .msi file can de run
manually on the client, or automatically with a Group Policy.
7. Package the installer in a .cab file for web deployment. For public web sites we
obviously can't deploy our ActiveX control to the client with a Group Policy. In this
case we're going to have to use Internet Explores built-in ability to download and
install controls that are packaged in .cab files.
1. Download the Microsoft Cabinet Software Development Kit.
2. Unpack the kit to a local folder and copy Cabarc.exe to the 'AxControlsInstaller'
folder.
3. Create a new file named 'AxControls.inf' in the 'AxControlsInstaller' folder and
add the following content:
[version]
signature="$CHICAGO$"
AdvancedINF=2.0
[Add.Code]
AxControlsInstaller.msi=AxControlsInstaller.msi
[AxControlsInstaller.msi]
file-win32-x86=thiscab
clsid={1FC0D50A-4803-4f97-94FB-2F41717F558D}
FileVersion=1,0,0,0
[Setup Hooks]
RunSetup=RunSetup
[RunSetup]
run="""msiexec.exe""" /i
"""%EXTRACT_DIR%AxControlsInstaller.msi""" /qn
8. Click the AxControlsInstaller project and then click the Properties window (View ->
Properties Window if it's not visible).
Click the '...' button next to the PostBuildEvent property and add the following
content:
"$(ProjectDir)CABARC.EXE" N "$(ProjectDir)AxControls.cab"
"$(ProjectDir)AxControls.inf" "$(ProjectDir)$(Configuration)AxControlsInstaller.msi"
9. Right click the 'AxControlsInstaller' project and select Build.There should now be a
'AxControls.cab' file in the 'AxControlsInstaller' folder.Take Note: Make sure you use
ANSI encoding for the 'AxControls.inf' file or you will be unable to install the control.
10. Initialize and test the control with JavaScript.
1. Right click the AxControls solution, select Add -> New Project and select 'ASP.Net
Web Application' under 'Web'.
2. Call the project 'WebAppTest' and click OK.
3. Right click the 'WebAppTest' project, select Add -> New Item and select 'HTML
Page'.
4. Call it 'index.html' and click OK.
5. Add the following content to index.html:
<html>
<head>
<object name="axHello" style='display:none' id='axHello'
classid='CLSID:1FC0D50A-4803-4f97-94FB-2F41717F558D'
codebase='AxControls.cab#version=1,0,0,0'></object>
<script language="javascript">
<!-- Load the ActiveX object -->
var x = new ActiveXObject("AxControls.HelloWorld");
<!-- Display the String in a messagebox -->
alert(x.GetText());
</script>
</head>
<body>
</body>
</html>
Note that 'classid' matches the GUID of the HelloWorld control.
11. Right click 'index.html' and select 'Set as start page'.
12. Right click the 'WebAppTest' project and select 'Set as startup project'.
13. Copy 'AxControls.cab' from the 'AxControlsInstaller' folder to the same folder as
index.html.
14. Uninstall the control from the client by going to Control Panel -> Programs and
Features, selecting 'AxControlsInstaller' on the list and clicking Uninstall. This forces
Internet Explorer to download and install the .cab file and is an important step in
case you've already installed the control.
15. Run the application (F5). This will open 'index.html' in Internet Explorer.
16. Internet Explorer will display a security warning, asking if you want to install
'AxControls.cab'. Click Install.
17. When the page loads it should display a message box with the string you defined in
HelloWorld's GetText() method.
18. If the message box displayed without any more warnings or errors we've
implemented everyting correctly.

More Related Content

Similar to Steps how to create active x using visual studio 2008

Adding a view
Adding a viewAdding a view
Adding a view
Nhan Do
 
Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDE
Benjamin Cabé
 
MEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr WlodekMEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr Wlodek
infusiondev
 

Similar to Steps how to create active x using visual studio 2008 (20)

Paytm integration in swift
Paytm integration in swiftPaytm integration in swift
Paytm integration in swift
 
Aspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_cs
 
Creating web api and consuming- part 1
Creating web api and consuming- part 1Creating web api and consuming- part 1
Creating web api and consuming- part 1
 
Mixpanel Integration in Android
Mixpanel Integration in AndroidMixpanel Integration in Android
Mixpanel Integration in Android
 
Labs And Walkthroughs
Labs And WalkthroughsLabs And Walkthroughs
Labs And Walkthroughs
 
Mvc acchitecture
Mvc acchitectureMvc acchitecture
Mvc acchitecture
 
PVS-Studio in the Clouds: Azure DevOps
PVS-Studio in the Clouds: Azure DevOpsPVS-Studio in the Clouds: Azure DevOps
PVS-Studio in the Clouds: Azure DevOps
 
Scaffolding
ScaffoldingScaffolding
Scaffolding
 
ASP DOT NET
ASP DOT NETASP DOT NET
ASP DOT NET
 
Adding a view
Adding a viewAdding a view
Adding a view
 
Micro services from scratch - Part 1
Micro services from scratch - Part 1Micro services from scratch - Part 1
Micro services from scratch - Part 1
 
Titanium Appcelerator - Beginners
Titanium Appcelerator - BeginnersTitanium Appcelerator - Beginners
Titanium Appcelerator - Beginners
 
WAC Widget Upload Process
WAC Widget Upload ProcessWAC Widget Upload Process
WAC Widget Upload Process
 
Drag &amp; drop calendar javaScript add-in for dynamics nav
Drag &amp; drop calendar javaScript add-in for dynamics navDrag &amp; drop calendar javaScript add-in for dynamics nav
Drag &amp; drop calendar javaScript add-in for dynamics nav
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
 
Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDE
 
Using prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile servicesUsing prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile services
 
MEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr WlodekMEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr Wlodek
 
Creating a dot netnuke
Creating a dot netnukeCreating a dot netnuke
Creating a dot netnuke
 
Internet and Web Technology (CLASS-9) [React.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-9) [React.js] | NIC/NIELIT Web TechnologyInternet and Web Technology (CLASS-9) [React.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-9) [React.js] | NIC/NIELIT Web Technology
 

More from Yudep Apoi (9)

Amalan Pertanian Yang Baik Untuk Penanaman Lada
Amalan Pertanian Yang Baik Untuk Penanaman LadaAmalan Pertanian Yang Baik Untuk Penanaman Lada
Amalan Pertanian Yang Baik Untuk Penanaman Lada
 
RHB SE User Manual Draft
RHB SE User Manual DraftRHB SE User Manual Draft
RHB SE User Manual Draft
 
Web aggregation and mashup with kapow mashup server
Web aggregation and mashup with kapow mashup serverWeb aggregation and mashup with kapow mashup server
Web aggregation and mashup with kapow mashup server
 
MIT521 software testing (2012) v2
MIT521   software testing  (2012) v2MIT521   software testing  (2012) v2
MIT521 software testing (2012) v2
 
MIT520 software architecture assignments (2012) - 1
MIT520   software architecture assignments (2012) - 1MIT520   software architecture assignments (2012) - 1
MIT520 software architecture assignments (2012) - 1
 
Intranet (leave management module) admin
Intranet (leave management module) adminIntranet (leave management module) admin
Intranet (leave management module) admin
 
Intranet (hiring module)
Intranet (hiring module)Intranet (hiring module)
Intranet (hiring module)
 
Intranet (callback module)
Intranet (callback module)Intranet (callback module)
Intranet (callback module)
 
Intranet (attendance module)
Intranet (attendance module)Intranet (attendance module)
Intranet (attendance module)
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Steps how to create active x using visual studio 2008

  • 1. Steps how to create activeX using Visual Studio 2008 (Details Steps) Written by: Yudep Apoi INFORMATION: This information is derived from: Creating an ActiveX control in .Net using C# by Olav Aukan 1. Open your Visual Studio 2008. FILE > New Project Select Visual C# > Class Library Name your project as AxControls 2. Rename your Class1.cs to HelloWorld.cs Right Click on project AxControls to add reference System.Windows.Form
  • 2. 3. Create a new interface that exposes the controls methods and properties to COM interop. Right click the project in Visual Studio and click Add –> New Item Select ‘Interface’ from the list of components, named it as ‘IHelloWorld.cs’ and click add.
  • 3. Replace the code with this: using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace AxControls { [ComVisible(true)] [InterfaceType(ComInterfaceType.InterfaceIsDual)] [Guid("E66C39CB-BB8B-4738-AA0E-5E0D1F2DB230")] public interface IHelloWorld { string GetText(); } } [ComVisible(true)] makes the interface visible to COM. [Guid("E66C39CB-BB8B-4738-AA0E-5E0D1F2DB230")] lets us manually assign a GUID to the interface. Use guidgen.exe to generate your own. 4. Mark the control as safe for scripting and initialization. By default IE will not allow initializing and scripting an ActiveX control unless it is marked as safe. This means that we won’t be able to create instances of our ActiveX class with JavaScript by default. We can get around this by modifying the browser security settings, but a more elegant way would be to mark the control as safe. Before you do this to a “real” control, be sure to understand the consequences. We will mark the control as safe by implementing the IObjectSafety interface. Right click the project in Visual Studio and click Add -> New Item. Select ‘Interface’ from the list of components, name it ‘IObjectSafety.cs’ and click Add.
  • 4. Put these lines of codes inside IObjectSafety.cs: using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace AxControls { [ComImport()] [Guid("51105418-2E5C-4667-BFD6-50C71C5FD15C")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IObjectSafety { [PreserveSig()] int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions); [PreserveSig()] int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions); } } 5. Go to HelloWorld make the HelloWorld class implement the IObjectSafety interface by replacing HelloWorld.cs with these lines of code:
  • 5. using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace AxControls { [ComVisible(true)] [ClassInterface(ClassInterfaceType.None)] [Guid("D100C392-030A-411C-92B6-4DBE9AC7AA5A")] [ProgId("AxControls.HelloWorld")] [ComDefaultInterface(typeof(IHelloWorld))] public class HelloWorld : UserControl, IHelloWorld, IObjectSafety { #region IHelloWorld Members public string GetText() { return "Hello ActiveX World!"; } #endregion #region IObjectSafety Members public enum ObjectSafetyOptions { INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001, INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002, INTERFACE_USES_DISPEX = 0x00000004, INTERFACE_USES_SECURITY_MANAGER = 0x00000008 }; public int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions) { ObjectSafetyOptions m_options = ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_CALLER | ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_DATA; pdwSupportedOptions = (int)m_options; pdwEnabledOptions = (int)m_options; return 0; } public int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions) { return 0; } #endregion } } 6. Create a .msi installer for the control. Before an ActiveX control can be used it must be installed and registered on the client. This can be done in a number of
  • 6. ways, from manually editing the registry to using regasm.exe, but we’re going to create a Vistual Studio setup project to handle the installation for us. Right click the Visual Studio solution, select Add -> New Project and select Setup Project under Other Project Types. Call the project ‘AxControlsInstaller’ and click OK. But before that you need to save the project. I named the folder as AxControl1. Then click save. After saved this interface will appear. Right click the ‘AxControlsInstaller’ project, select Add -> Project Output, select ‘Primary output’ from the ‘AxControls’.
  • 7. Right click 'Primary output from AxControls (Active)' and select Properties. Change the Register property from 'vsdrpDoNotRegister' to 'vsdrpCOM'. Right click the 'AxControlsInstaller' project and select Build. The installer should now be located in the AxControlsInstaller's output folder (binDebug or binRelease). In the corporate domain this .msi file can de run manually on the client, or automatically with a Group Policy. 7. Package the installer in a .cab file for web deployment. For public web sites we obviously can't deploy our ActiveX control to the client with a Group Policy. In this case we're going to have to use Internet Explores built-in ability to download and install controls that are packaged in .cab files. 1. Download the Microsoft Cabinet Software Development Kit. 2. Unpack the kit to a local folder and copy Cabarc.exe to the 'AxControlsInstaller' folder. 3. Create a new file named 'AxControls.inf' in the 'AxControlsInstaller' folder and add the following content: [version] signature="$CHICAGO$" AdvancedINF=2.0
  • 8. [Add.Code] AxControlsInstaller.msi=AxControlsInstaller.msi [AxControlsInstaller.msi] file-win32-x86=thiscab clsid={1FC0D50A-4803-4f97-94FB-2F41717F558D} FileVersion=1,0,0,0 [Setup Hooks] RunSetup=RunSetup [RunSetup] run="""msiexec.exe""" /i """%EXTRACT_DIR%AxControlsInstaller.msi""" /qn 8. Click the AxControlsInstaller project and then click the Properties window (View -> Properties Window if it's not visible). Click the '...' button next to the PostBuildEvent property and add the following content: "$(ProjectDir)CABARC.EXE" N "$(ProjectDir)AxControls.cab" "$(ProjectDir)AxControls.inf" "$(ProjectDir)$(Configuration)AxControlsInstaller.msi" 9. Right click the 'AxControlsInstaller' project and select Build.There should now be a 'AxControls.cab' file in the 'AxControlsInstaller' folder.Take Note: Make sure you use ANSI encoding for the 'AxControls.inf' file or you will be unable to install the control. 10. Initialize and test the control with JavaScript. 1. Right click the AxControls solution, select Add -> New Project and select 'ASP.Net Web Application' under 'Web'. 2. Call the project 'WebAppTest' and click OK. 3. Right click the 'WebAppTest' project, select Add -> New Item and select 'HTML Page'. 4. Call it 'index.html' and click OK. 5. Add the following content to index.html: <html> <head> <object name="axHello" style='display:none' id='axHello' classid='CLSID:1FC0D50A-4803-4f97-94FB-2F41717F558D' codebase='AxControls.cab#version=1,0,0,0'></object> <script language="javascript"> <!-- Load the ActiveX object --> var x = new ActiveXObject("AxControls.HelloWorld"); <!-- Display the String in a messagebox --> alert(x.GetText()); </script>
  • 9. </head> <body> </body> </html> Note that 'classid' matches the GUID of the HelloWorld control. 11. Right click 'index.html' and select 'Set as start page'. 12. Right click the 'WebAppTest' project and select 'Set as startup project'. 13. Copy 'AxControls.cab' from the 'AxControlsInstaller' folder to the same folder as index.html. 14. Uninstall the control from the client by going to Control Panel -> Programs and Features, selecting 'AxControlsInstaller' on the list and clicking Uninstall. This forces Internet Explorer to download and install the .cab file and is an important step in case you've already installed the control. 15. Run the application (F5). This will open 'index.html' in Internet Explorer. 16. Internet Explorer will display a security warning, asking if you want to install 'AxControls.cab'. Click Install. 17. When the page loads it should display a message box with the string you defined in HelloWorld's GetText() method. 18. If the message box displayed without any more warnings or errors we've implemented everyting correctly.