110,533
社区成员
发帖
与我相关
我的任务
分享
namespace CardRead
{
[Guid("70c17068-5d76-4135-bd07-94357dc57715"),ProgId("CardRead.MyActiveX")]
public partial class MyActiveX : UserControl, IObjectSafe
{
public MyActiveX()
{
InitializeComponent();
}
#region IObjectSafe 成员
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
private void MyActiveX_Load(object sender, EventArgs e)
{
}
//自己的代码
//public class CardRead
//{
[DllImport("sdtapi.dll", EntryPoint = "SDT_OpenPort",
CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern Int32 SDT_OpenPort(int iPort);
//找卡
[DllImport("sdtapi.dll", EntryPoint = "SDT_StartFindIDCard",
CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern Int32 SDT_StartFindIDCard(int iPort, ref byte pucManaInfo, int iIfOpen);
//选卡
[DllImport("sdtapi.dll", EntryPoint = "SDT_SelectIDCard",
CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern Int32 SDT_SelectIDCard(int iPort, ref byte pucManaMsg, int iIfOpen);
//读取居民身份证机读文字信息和相片信息
[DllImport("sdtapi.dll", EntryPoint = "SDT_ReadBaseMsg",
CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern Int32 SDT_ReadBaseMsg(int iPort, byte[] pucCHMsg, ref int puiCHMsgLen, byte[] pucPHMsg, ref int puiPHMsgLen, int iIfOpen);
//读取居民身份证机读文字信息和相片信息,将读取到的信息写到输入参数所指定的文件中。
[DllImport("sdtapi.dll", EntryPoint = "SDT_ReadBaseMsgToFile",
CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern Int32 SDT_ReadBaseMsgToFile(int iPort, string pcCHMsgFileName, ref int puiCHMsgFileLe, string pcPHMsgFileName, ref int puiPHMsgFileLen, int iIfOpen);
//关闭端口
[DllImport("sdtapi.dll", EntryPoint = "SDT_ClosePort",
CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern Int32 SDT_ClosePort(int iPort);
//读图像
[DllImport("WltRS.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int GetBmp(string file_name, int intf);
public delegate void De_ReadICCardComplete(clsEDZ objEDZ);
private clsEDZ objEDZ = new clsEDZ();
bool bUsbPort = false;
int intOpenPortRtn = 0;
const int maxErrorTextLen = 32;
//检测usb口的机具连接,必须先检测usb
public int OpenCardReader(int id)
{
int a = id;
for (int iPort = a; iPort <= 1016; iPort++)
{
intOpenPortRtn = SDT_OpenPort(iPort);
if (intOpenPortRtn == 144)
{
EdziPortID = iPort;
bUsbPort = true;
break;
}
}
//检测串口的机具连接
if (!bUsbPort)
{
for (int iPort = a; iPort <= 10; iPort++)
{
intOpenPortRtn = SDT_OpenPort(iPort);
if (intOpenPortRtn == 144)
{
EdziPortID = iPort;
bUsbPort = false;
break;
}
}
}
if (intOpenPortRtn != 144)
{
//return;
}
return a;
}
太长了,加个高亮再看。