b/S Operation Client Hardware solutions

Source: Internet
Author: User

In general, the client is a Windows system, the use of hardware drivers are DLLs then we want to use client hardware on the client, we must use Microsoft's COM technology, currently I found two specific solutions

One is to use MFC ActiveX, here is a note, if the Win7 system, in the MFC ActiveX Project properties can not be used in the static library (Lib), otherwise it will not be able to register

One is the Windows Forms Control Library in C #

Here are a few notes.

One, application, properties, project-Right, item--check: Make assembly COM visible

Two, item right--Property--Build, tick: Register for COM Interop

You also need to define an interface

[ComImport, GuidAttribute ("cb5bdc81-93c1-11cf-8f20-00805f2cd064")]
[InterfaceTypeAttribute (Cominterfacetype.interfaceisiunknown)]
public interface IObjectSafety
{
[PreserveSig]
int getinterfacesafetyoptions (ref Guid riid, [MarshalAs (UNMANAGEDTYPE.U4)] ref int pdwsupportedoptions, [MarshalAs ( UNMANAGEDTYPE.U4)] ref int pdwenabledoptions);

[PreserveSig ()]
int SetInterfaceSafetyOptions (ref Guid riid, [MarshalAs (UNMANAGEDTYPE.U4)] int dwoptionsetmask, [MarshalAs ( UNMANAGEDTYPE.U4)] int dwenabledoptions);
}

Let the main class inherit this interface as follows:

Using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

Namespace WindowsFormsControlLibrary3
{
[Guid ("a67a174d-0074-4806-99a1-1a75043a822c"), ProgId ("Myfirstactivex.usercontrol1"), ComVisible (true)]
Public partial class Usercontrol1:usercontrol, IObjectSafety
{
Public UserControl1 ()
{
InitializeComponent ();
}
public void Test ()
{
MessageBox.Show ("AA");
}

#region IObjectSafety Members

        Private Const string _iid_idispatch = "{00020400-0000-0000- c000-000000000046} ";
        Private Const string _iid_idispatchex = "{ A6EF9860-C720-11D0-9337-00A0C90DCAA9} ";
        Private Const string _iid_ipersiststorage = "{ 0000010a-0000-0000-c000-000000000046} ";
        Private Const string _iid_ipersiststream = "{00000109-0000-0000- c000-000000000046} ";
        Private Const string _iid_ipersistpropertybag = "{ 37d84f60-42cb-11ce-8135-00aa004bb851} ";

Private Const int interfacesafe_for_untrusted_caller = 0x00000001;
Private Const int interfacesafe_for_untrusted_data = 0x00000002;
Private Const int S_OK = 0;
Private Const int E_FAIL = unchecked ((int) 0x80004005);
Private Const int E_NOINTERFACE = unchecked ((int) 0x80004002);

private bool _fsafeforscripting = true;
private bool _fsafeforinitializing = true;

public int getinterfacesafetyoptions (ref Guid riid, ref int pdwsupportedoptions, ref int pdwenabledoptions)
{
int Rslt = E_FAIL;

String strguid = riid. ToString ("B");
Pdwsupportedoptions = Interfacesafe_for_untrusted_caller | Interfacesafe_for_untrusted_data;
Switch (STRGUID)
{
Case _iid_idispatch:
Case _iid_idispatchex:
Rslt = S_OK;
pdwenabledoptions = 0;
if (_fsafeforscripting = = True)
Pdwenabledoptions = Interfacesafe_for_untrusted_caller;
Break
Case _iid_ipersiststorage:
Case _iid_ipersiststream:
Case _iid_ipersistpropertybag:
Rslt = S_OK;
pdwenabledoptions = 0;
if (_fsafeforinitializing = = True)
Pdwenabledoptions = Interfacesafe_for_untrusted_data;
Break
Default
Rslt = E_nointerface;
Break
}

return Rslt;
}

public int setinterfacesafetyoptions (ref Guid riid, int dwoptionsetmask, int dwenabledoptions)
{
int Rslt = E_FAIL;
String strguid = riid. ToString ("B");
Switch (STRGUID)
{
Case _iid_idispatch:
Case _iid_idispatchex:
if (((Dwenabledoptions & dwoptionsetmask) = = Interfacesafe_for_untrusted_caller) && (_fsafeforscripting = = true))
Rslt = S_OK;
Break
Case _iid_ipersiststorage:
Case _iid_ipersiststream:
Case _iid_ipersistpropertybag:
if (((Dwenabledoptions & dwoptionsetmask) = = Interfacesafe_for_untrusted_data) && (_fsafeforinitializing = = True))
Rslt = S_OK;
Break
Default
Rslt = E_nointerface;
Break
}

return Rslt;
}

#endregion
}
}
The GUID used here is generated from the GUID generated by the menu item tool, and the CLSID that is called later in JS is also the ID

Either way, COM components in the local registration is the only way, the MFC ActiveX registration method is: Win7 command prompt interface path under the boot to c:/windows/syswow64 run regsvr32 OCX full path to complete the registration,

How the Windows Forms Control Library is registered for Web enrollment

<object id= "Mytt" classid= "clsid:a67a174d-0074-4806-99a1-1a75043a822c" codebase= "c:/Debug/ WindowsFormsControlLibrary3.dll "></object>

In addition, JS and COM interaction mode is


JS Callfunction Open () {var value_string = document.getelementsbyname ("open_param1") [0].value;
var returnvalue = Cdmctrl.open (value_string);document.getelementsbyname ("Open_result") [0].value = returnvalue;
}
Call JS<input type= "button" Name= "Button1" value= "open" onclick= "open ()"/>
Handling Events:<script type= "Text/javascript" for= "Cdmctrl" event= "oncashinstarted (p_lretcode)" >document.getelementsbyname ("Log") [0].value + = "Fire oncashinstarted (long P_lretcode) event \ n P_lretcode =" + P_lret Code + "\ n";</SCRIPT>

b/S Operation Client Hardware solutions

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.