zoukankan      html  css  js  c++  java
  • 函数指针声明与调用分析

    hdf5库函数指针和win32函数指针示例

    hdf5库:
    H5_DLL herr_t  H5Aiterate(hid_t loc_id, unsigned *attr_num, H5A_operator_t op,void *op_data)
    转到H5A_operator_t定义:
    typedef herr_t (*H5A_operator_t)(hid_t location_id/*in*/, const char *attr_name/*in*/, void

    *operator_data/*in,out*/);
    解释:H5A_operator_t为指向函数的指针,该指针指向的函数参数列表与上同;
    调用示例:
    //函数声明
    herr_t attr_info(hid_t loc_id, const char *name, void *opdata);
    //传递函数指针给调用函数
    int idx = H5Aiterate(dataset, NULL, attr_info, NULL);

    Win32:
    typedef struct tagWNDCLASSEXA {
        UINT        cbSize;
        /* Win 3.x */
        UINT        style;
        WNDPROC     lpfnWndProc;
        int         cbClsExtra;
        int         cbWndExtra;
        HINSTANCE   hInstance;
        HICON       hIcon;
        HCURSOR     hCursor;
        HBRUSH      hbrBackground;
        LPCSTR      lpszMenuName;
        LPCSTR      lpszClassName;
        /* Win 4.0 */
        HICON       hIconSm;
    } WNDCLASSEXA, *PWNDCLASSEXA, NEAR *NPWNDCLASSEXA, FAR *LPWNDCLASSEXA;
    window结构,其中,指针lpfnWndProc指向窗口消息处理函数,指针对象为指向函数的指针:
    typedef LRESULT (CALLBACK* WNDPROC)(HWND, UINT, WPARAM, LPARAM);
    解释:WNDPROC为指向函数的指针,不仅声明了函数参数列表,还指定了函数的调用方式CALLBACK(__stdcall)。
    调用示例:
    //函数声明
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    //传递函数指针给结构体成员
         WNDCLASSA     wndclass ;

         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = szAppName ;

  • 相关阅读:
    选择本地照片之后即显示在Img中(客户体验)
    解决JQuery.ajax.post乱码问题
    浅析MVC模式与三层架构的区别01
    照片上传(缩略图实现)
    基于Netty的聊天系统(三)协议定制----消息篇
    基于Netty的聊天系统(二)协议定制----登录篇
    基于Netty的聊天系统(一)通讯原理篇
    Centos6.5下配置SVN服务器
    FreeMarker-TemplateLoader
    移动UI自动化-Page Objects Pattern
  • 原文地址:https://www.cnblogs.com/faceang/p/1719839.html
Copyright © 2011-2022 走看看