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

Aspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAspnet mvc tutorial_01_cs
Aspnet mvc tutorial_01_csAlfa Gama Omega
 
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 1Dipendra Shekhawat
 
Mixpanel Integration in Android
Mixpanel Integration in AndroidMixpanel Integration in Android
Mixpanel Integration in Androidmobi fly
 
Labs And Walkthroughs
Labs And WalkthroughsLabs And Walkthroughs
Labs And WalkthroughsBryan Tuttle
 
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 DevOpsAndrey Karpov
 
Adding a view
Adding a viewAdding a view
Adding a viewNhan Do
 
Micro services from scratch - Part 1
Micro services from scratch - Part 1Micro services from scratch - Part 1
Micro services from scratch - Part 1Azrul MADISA
 
Titanium Appcelerator - Beginners
Titanium Appcelerator - BeginnersTitanium Appcelerator - Beginners
Titanium Appcelerator - BeginnersAmbarish Hazarnis
 
WAC Widget Upload Process
WAC Widget Upload ProcessWAC Widget Upload Process
WAC Widget Upload Processwacapps
 
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 navMehdi Meddah
 
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...Andrey Karpov
 
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 IDEBenjamin Cabé
 
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 servicesDavid Voyles
 
MEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr WlodekMEF Deep Dive by Piotr Wlodek
MEF Deep Dive by Piotr Wlodekinfusiondev
 
Creating a dot netnuke
Creating a dot netnukeCreating a dot netnuke
Creating a dot netnukeNguyễn Anh
 
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 TechnologyAyes Chinmay
 
03 integrate webapisignalr
03 integrate webapisignalr03 integrate webapisignalr
03 integrate webapisignalrErhwen Kuo
 

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

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
 
03 integrate webapisignalr
03 integrate webapisignalr03 integrate webapisignalr
03 integrate webapisignalr
 

More from Yudep Apoi

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 LadaYudep Apoi
 
RHB SE User Manual Draft
RHB SE User Manual DraftRHB SE User Manual Draft
RHB SE User Manual DraftYudep Apoi
 
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 serverYudep Apoi
 
MIT521 software testing (2012) v2
MIT521   software testing  (2012) v2MIT521   software testing  (2012) v2
MIT521 software testing (2012) v2Yudep Apoi
 
MIT520 software architecture assignments (2012) - 1
MIT520   software architecture assignments (2012) - 1MIT520   software architecture assignments (2012) - 1
MIT520 software architecture assignments (2012) - 1Yudep Apoi
 
Intranet (leave management module) admin
Intranet (leave management module) adminIntranet (leave management module) admin
Intranet (leave management module) adminYudep Apoi
 
Intranet (hiring module)
Intranet (hiring module)Intranet (hiring module)
Intranet (hiring module)Yudep Apoi
 
Intranet (callback module)
Intranet (callback module)Intranet (callback module)
Intranet (callback module)Yudep Apoi
 
Intranet (attendance module)
Intranet (attendance module)Intranet (attendance module)
Intranet (attendance module)Yudep Apoi
 

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

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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 StreamsRoshan Dwivedi
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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 2024Rafal Los
 
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 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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 AutomationSafe Software
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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 WorkerThousandEyes
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

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.