我有个C++写的DLL,并提供了.H文件。 其中有个东东在H文件中的定义是这样的:
/* 
 * typedef: 
 * PemnCommHandle
 *------------------------------------------------------------------
 * Description:
 *  Communication handle to the agent/PEM returned by PemnOpen
 * This handle is used with all subsequent call to the agent (e.g
 * PemnSend, PemnReceive).
 *------------------------------------------------------------------ 
 */
typedef void *PemnCommHandle;
使用这个东东的方法定义如下:
/*
 * Function:  
 * PemnOpen
 *------------------------------------------------------------------
 * Purpose : 
 *  Open a connection to a PATROL agent.
 * The caller specifies the host name and port number. For other
 * communication attributes see PemnSet/GetCommAttributes below.
 *
 *  When the connection is opened successfully the OpenCallback is called.
 *  If the connection could not be opened then CloseCall back is called.
 *
 * IMPORTANT pOpenCallback should call the PemnSendIdentity()
 *      immediatly to authenticate the connection. (V31*)
 *------------------------------------------------------------------
 * Arguments:
 * iPort - port number of the agent/PEM
 * pcRemoteHost - Host name of the agent/PEM.
 * pCloseCallback, pOpenCallback - PEM API calls these
 * routines when the connection with agent/PEM is closed/opened
 * pCloseClientData, pOpenClientData - The PEM API passes 
 * pCloseClientData (resp. pOpenClientData) 
 * when calling pCloseCallback (resp. pOpenCallback).
 * phComm - address in the application of the variable which 
 * will holds the communication handles.
 * The PEM API store internally the address of where to 
 * return the Comm. handler.
 *
 * THE VARIABLE HOLDING THIS COMMUNICATION
 * HANDLE SHOULD BE A STATIC VARIABLE IN THE PROGRAM.
 *
 */
DLL_IMPORT void PemnOpen(
int  iPort,
char         *pcRemoteHost,
PemnCommCallback   pCloseCallback,
PemnClientData pCloseClientData,
PemnCommCallback pOpenCallback,
PemnClientData pOpenClientData,
PemnCommHandle         *phComm
);
而我的C#调用代码如下:        public delegate void PemnCommHandle();        [DllImport("pemapi.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern string PemnBOpen(
            PemnCommHandle phComm,
            string pcHostName,
            int iPort,
            string pcUserName,
            string pcEncryptedPassword,
            int iMaxRetry,
            PemnBDisconnectCallback pDisconnectCallback,
            PemnClientData pClientData
            );        public void Temp() 
        {
            Console.WriteLine("PemnCommHandle被调用。");
        }
        PemnCommHandle pHandle = new PemnCommHandle(Temp);
        strOpenResult = PemnBOpen(pHandle, "10.10.198.12", 3181, "patrol", sbEncryptedPwd.ToString(), 1, pCallBack, null);我想问下:1. PemnCommHandle 是函数指针么? 2. 我写的C#代码写得对吗,PemnCommHandle对我的程序没什么意义嘛

解决方案 »

  1.   

    你c#中的参数都是什么类型啊,人家c++的是什么类型,你搞清楚了吗,PemnCommCallback 之类的都是什么类型啊,PemnCommHandle 应该就是个句柄,干吗用的你要不知道就问接口提供者
      

  2.   


    你的“PemnCommHandle 应该就是个句柄”解决了我的问题,谢谢能否再帮忙再帮我解释下,下面的C++代码的含义吗?其实我不懂C++,知道含义我就知道如何从C#去访问:
    /* 
     * typedef: (V31)
     * PemnParamAttrEnum, PemnParamAttrArray
     *------------------------------------------------------------------
     * Description: 
     * The 'PemnParamAttrArray' type defines the 
     * read-only attributes of an parameter.
     * The 'PemnParamAttrEnum' defines the index to these attributes.
     *------------------------------------------------------------------ 
     */
    typedef enum {
    PEMN_PARAMNAME=0, /* should be always ZERO */
    PEMN_PARAMCURRENTTIME,
    PEMN_PARAMPOLLINGINT,
    PEMN_PARAMRETRIES,
    PEMN_PARAMCURRENTVALUE,
    PEMN_PARAMSTATE,
    PEMN_PARAMOUTPUTMODE,
    PEMN_PARAMAUTOSCALE,
    PEMN_PARAM_Y_AXIS_MIN,
    PEMN_PARAM_Y_AXIS_MAX,
    PEMN_PARAM_MAX_ATTR /* should be always last */
    } PemnParamAttrEnum;typedef  char* PemnParamAttrArray[PEMN_PARAM_MAX_ATTR];
    请问PemnParamAttrArray是什么东东?
      

  3.   

    C#的数据类型和C++的有些是不一样的,比如char [] 和C#里的char []就不一回事
      

  4.   

    char* PemnParamAttrArray[PEMN_PARAM_MAX_ATTR];
    char* PemnParamAttrArray[10]这样写的好处是当修改了枚举个数,数组长度也会动态的改变。