zoukankan      html  css  js  c++  java
  • 异步操作样本

    Sample C code calling it:

    OVERLAPPED overlapped;   
    overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);   
    fns.NotifyStateChange(&overlapped);   
    WaitForSingleObject(overlapped.hEvent, INFINITE);   
    // ...query for the new state or whatever... 
    

    This is how I approached it in C#:

    [DllImport("myfuncs.dll")] 
    unsafe public static extern int NotifyStateChange(NativeOverlapped* lpOverlapped); 
     
    static private ManualResetEvent m_stateChangeEvent = new ManualResetEvent(false); 
     
    public static DeviceState WaitForStateChange() 
    { 
        unsafe 
        { 
            Overlapped overlapped = new Overlapped(0, 0,  
                m_stateChangeEvent.SafeWaitHandle.DangerousGetHandle(), null); 
            IOCompletionCallback callback = StateChangeCallback; 
            byte[] userData = new byte[100]; 
            NativeOverlapped* nativeOverlapped = overlapped.Pack(callback, userData); 
            NotifyStateChange(nativeOverlapped); 
            m_stateChangeEvent.WaitOne(); 
            Overlapped.Unpack(nativeOverlapped); 
            Overlapped.Free(nativeOverlapped); 
        } 
        return GetCurrentState(); 
    } 
     
    [ComVisibleAttribute(true)] 
    unsafe static public void StateChangeCallback ( 
        uint errorCode,  
        uint bytesTransferred,  
        NativeOverlapped* overlapped) 
    { 
        m_stateChangeEvent.Set(); 
    } 
    
  • 相关阅读:
    广佛肇城轨年内通车 佛山西站预计2017年中通车
    MTK+Android编译
    电量检测芯片BQ27510使用心得
    放大电路的分析方法
    放大电路的分析方法
    模拟电子放大电路分析
    模拟电子技术二极管
    unsigned 整型实现无溢出运算
    hdu 5317 RGCDQ(前缀和)
    CodeForces 429 B Working out(递推dp)
  • 原文地址:https://www.cnblogs.com/kevinzhwl/p/3878903.html
Copyright © 2011-2022 走看看