本帖最后由 y459618250 于 2012-12-04 11:16:11 编辑

解决方案 »

  1.   

    type
      SSR_User = packed record
       PIN: word;
       Privilege: byte;
       Password: array[0..7] of byte;
       Name: array[0..23] of byte;
       Card: array[0..3] of byte;
       Group: byte;
       TimeZones: array[0..3] of word;//the timezones that the user can use
       PIN2: array[0..23] of byte;
     end;procedure GetSSRUserInfoFromDat(DataBuf: array of byte;
      var PIN, Privilege: integer;
      var Password, Name: string;
      var Card, Group: integer;
      var TimeZone, PIN2: string);
    var
      i: integer;
      PasswordBuf: array[0..7] of Char;
      NameBuf: array[0..23] of Char;
      TimeZoneBuf: array[0..7] of Char;
      PIN2Buf: array[0..23] of Char;
      ssruser: SSR_User;
    begin
      //ssruser = (SSR_User)Raw.RawDeserialize(DataBuf, typeof(3));
      PIN := ssruser.PIN;
      Privilege := ssruser.Privilege;
      Move(DataBuf[3], PasswordBuf[0], 8);
      Password := StrPas(PasswordBuf);  //"default" is to read the system's current ANSI code page encoding
      Move(DataBuf[11], NameBuf[0], 24);
      Name := StrPas(NameBuf);
      Card := 0;
      for i := 35 to 38 do
        Card := Card + Round(DataBuf[i] * Math.Power(16, 2 * (i - 35)));
      Group := ssruser.Group;  Move(DataBuf[40], TimeZoneBuf[0], 8);
      TimeZone := StrPas(TimeZoneBuf);  Move(DataBuf[48], PIN2Buf[0], 24);
      PIN2 := StrPas(PIN2Buf);
    end;
      

  2.   

    //ssruser = (SSR_User)Raw.RawDeserialize(DataBuf, typeof(3));
      CopyMemory(@ssruser, @DataBuf[0], SizeOf(SSR_User));  PIN := ssruser.PIN;
      Privilege := ssruser.Privilege;还查不到Raw.RawDeserialize这个函数的参数说明,我知道大致是强制转换的意思,所以暂时只能按上面的方式翻译下
      

  3.   

    不好意思!经过你刚才的提醒我找到了这个函数,能看看这个怎么翻译吗?感激不尽啊! public static object RawDeserialize(byte[] rawdatas, Type anytype)
            {
                int rawsize = Marshal.SizeOf(anytype);
                if (rawsize > rawdatas.Length)
                    return null;
                IntPtr buffer = Marshal.AllocHGlobal(rawsize);
                Marshal.Copy(rawdatas, 0, buffer, rawsize);
                object retobj = Marshal.PtrToStructure(buffer, anytype);
                Marshal.FreeHGlobal(buffer);
                return retobj;
            }
      

  4.   

    Type 类
    表示类型声明:类类型、接口类型、数组类型、值类型、枚举类型、类型参数、泛型类型定义,以及开放或封闭构造的泛型类型。
      

  5.   

    delphi中就用CopyMemory函数即可,或者Move。