Use C # To develop ActiveX controls and use web calls,

Source: Internet
Author: User

Use C # To develop ActiveX controls and use web calls,

  After nearly two months of employment, students have gradually moved to the workplace, accumulating knowledge and constantly updating themselves. In a recent project, some problems are involved, because the SDK only provides winform for use, but we must complete it if necessary, therefore, the ActiveX controls involved are developed and displayed on the web. They are also summarized. They have never been used in school before. There are tutorials on the Internet, but most of them have problems, you can rest assured that you have passed the test.

1. Develop ActiveX Controls

1. Create a new class library named "user. cs ";

2. Add the Custom User Control "UserControl1" to the class library to implement various custom functions;

3. To solve the impact of browser security settings on controls, you must add the IObjectSafety interface to the component. Therefore, add an Interface Class "IObjectSafety. cs"

Using System; using System. collections. generic; using System. text; using System. web. UI. webControls. webParts; // This package using System must be referenced. security; using System. runtime. interopServices; // The package namespace user {[Guid ("CB5BDC81-93C1-11CF-8F20-00805F2CD064"), InterfaceType (ComInterfaceType. interfaceIsIUnknown)] // The GUID does not need to be modified. The fixed public interface IObjectSafety {// method defines void GetInterfacceSafyOptions (System. int32 riid, out System. int32 pdwSupportedOptions, out System. int32 pdwEnabledOptions); void SetInterfaceSafetyOptions (System. int32 riid, System. int32 dwOptionsSetMask, System. int32 dwEnabledOptions );}}

4. inherited Interfaces

Public partial class UserControl1: UserControl, IObjectSafety {public UserControl1 () {InitializeComponent ();} public void GetInterfacceSafyOptions (System. int32 riid, out System. int32 pdwSupportedOptions, out System. int32 pdwEnabledOptions) {pdwSupportedOptions = 1; // do not modify the code pdwEnabledOptions = 2; // do not modify the return code;} public void SetInterfaceSafetyOptions (System. int32 riid, System. int32 dwOptionsSetMask, System. int32 dwEnabledOptions) {return;} public void YourFunc (){}}

5. Introduce two namespaces in UserControl1

Using System. Security;

Using System. Runtime. InteropServices;

6. Tools -- create GUID -- select Item 5 -- copy to close the window and paste it under the namespace, as shown below:

Namespace user {[Guid ("7F29ACED-AD84-4EEE-9E1A-58BE255F9EF7")] // this GUID is the public partial class UserControl1: UserControl, IObjectSafety {......

7. In the last step, modify the project-user attribute (the last item ).

① Application -- assembly information -- √ make the Assembly COM visible

② Generate -- √ register for COM interoperability

8. Right-click the project user to generate

Ii. web ActiveX Control

 

The web call is concise. reference the generated dll file and add

<body>    <form id="form1" runat="server">    <div >     <object id="VisioDisPlay"        classid="clsid:7F29ACED-AD84-4EEE-9E1A-58BE255F9EF7"         width="1250"        height="600"            >        </object>    </div>    </form>

. Note: The string in the classid contains "clsid:". Do not forget. The GUID generated in Step 6 must be consistent!


Well, it's time to have lunch. If there are any shortcomings, forget the criticism of the big coffee in garden.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.