示例#1
0
文件: Form1.cs 项目: 12019/svn.gov.pt
        private void AttachEvents()
        {
            try
            {
                PTEID_ReaderContext reader;
                ReaderRef readerRef;
                uint i;

                PTEID_SetEventDelegate MyCallback= new PTEID_SetEventDelegate(CallBack);

                string readerName;

                for(i = 0;i<ReaderSet.readerCount();i++)
                {
                    reader = ReaderSet.getReaderByNum(i);
                    readerName = ReaderSet.getReaderName(i);

                    readerRef = new ReaderRef();

                    readerRef.reader = reader;
                    readerRef.ptr = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(readerName);
                    readerRef.cardId = 0;
                    MyReadersSet.Add(readerName, readerRef);
                    readerRef.eventHandle = reader.SetEventCallback(MyCallback, readerRef.ptr);
                }

            }
            catch (PTEID_Exception ex)
            {
                MessageBox.Show("Crash PTEID_Exception!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Crash System.Exception!");
            }

        }
示例#2
0
  public uint SetEventCallback(PTEID_SetEventDelegate callback, IntPtr pvRef) { 
	pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.countRef++;	
	IntPtr ptrCount = new IntPtr(pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.countRef);

	//We add the references to the hash table
	pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.delegateRef callbackRef =  new pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.delegateRef();
	callbackRef.functionRef = callback;
	callbackRef.ptrRef = pvRef;
	callbackRef.handleRef = 0;
	pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.delegateRefs.Add(pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.countRef,callbackRef);

	//We call the SetEvent with the internal reference (countRef)
	uint ulRslt = pteidlib_dotNetPINVOKE.PTEID_ReaderContext_SetEventCallback(swigCPtr, 0, ptrCount);
	if (pteidlib_dotNetPINVOKE.SWIGPendingException.Pending) 
	{
		pteidlib_dotNetPINVOKE.CUSTOM_SetEventHelper.delegateRefs.Remove(callbackRef);
		throw pteidlib_dotNetPINVOKE.SWIGPendingException.Retrieve();
	}
	else
	{
		callbackRef.handleRef = ulRslt;
	}

	return ulRslt; 
}