日期:2014-05-18  浏览次数:20777 次

急救!C#调用C++的dll,未能封装类型
//********************************************************
#define   EFMI_POINTNAMELENGTH 48
//结构
typedef   struct   defefSTReadRtInfoRequest{
long   time;
char   pointName[EFMI_POINTNAMELENGTH+1];
         
char   ednaServ[EFMI_POINTCOMMLENGTH+1];
}efSTReadRtInfoRequest;

//****************************************************************

//****************************************************************
typedef   struct   defefSTReadRtResponse{

double   value;
long   time;
unsigned   short   status;/////////////////////////////////////////
char   pointName[EFMI_POINTNAMELENGTH+1];//点名,扩展ID
}efSTReadRtInfoResponse;

函数:
BOOL     effnEDClientCheckPointInfoByTimeEx(
efSTReadRtInfoRequest*pReqBuffer,
efSTReadRtInfoResponse   *   pResBuffer,
unsigned long   Count  
);获取实时数据。


//c#调用
        [StructLayout(LayoutKind.Sequential)]  
        public     struct   defefSTReadRtInfoRequest
        {
          public     long   time;
     
            [MarshalAs(UnmanagedType.ByValArray,   SizeConst   =   49)]
          public     char[]   pointName;
                [MarshalAs(UnmanagedType.ByValArray,   SizeConst   =   48)]
                public   char[]   ednaServ;

     
        }

//****************************************************************

//****************************************************************
        [StructLayout(LayoutKind.Sequential)]  
  public   struct   defefSTReadRtResponse{
          public   double   value;
          public   long   time;
          public   UInt16   status;
          [MarshalAs(UnmanagedType.ByValArray,   SizeConst   =   48)]
          public   char[]   pointName;//
     
};

//函数

  [DllImport( "efEDClient.dll ",   EntryPoint   =   "effnEDClientCheckPointInfoByTimeEx ",   CharSet   =   CharSet.Unicode)]
                public   static   extern   bool   effnEDClientCheckPointInfoByTimeEx(ref   defefSTReadRtInfoRequest   requestBuffer,out   defefSTReadRtResponse   responseBuffer,[MarshalAs(UnmanagedType.Error)]UInt32   count);


//调用

defefSTReadRtInfoRequest   req=new   defefSTReadRtInfoRequest();
                  char[]   arrP   =   new   char[49];
                  char[]   arrServ   =   new   char[48];

                  arrP   =   "GDHYSSIS.U31_RTS.1EHC:C47.RO01 ".ToCharArray();
  &