会VC的请进,帮忙把这几句代码翻译成DELPHI的,谢谢了~ 高分相送!(300)

  • 主题发起人 主题发起人 bigface
  • 开始时间 开始时间
B

bigface

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟需要用到timeval时间结构,该结构在winsock单元中!麻烦大侠把gettimeofday函数翻译成DELPHI版,谢谢了。还有请问116444736000000000LL是什么类型的,在DELPHI中怎么表达?------------------------------------------------------#ifdef WIN32#define WIN32_LEAN_AND_MEAN#include <windows.h>#include <time.h>#ifndef __GNUC__#define EPOCHFILETIME (116444736000000000i64)#else#define EPOCHFILETIME (116444736000000000LL)#endif/*struct timeval { long tv_sec; long tv_usec;};struct timezone { int tz_minuteswest; int tz_dsttime;};*/int gettimeofday(struct timeval *tv, struct timezone *tz){ FILETIME ft; LARGE_INTEGER li; __int64 t; static int tzflag; if (tv) { GetSystemTimeAsFileTime(&ft); li.LowPart = ft.dwLowDateTime; li.HighPart = ft.dwHighDateTime; t = li.QuadPart; /* In 100-nanosecond intervals */ t -= EPOCHFILETIME; /* Offset to the Epoch time */ t /= 10; /* In microseconds */ tv->tv_sec = (long)(t / 1000000); tv->tv_usec = (long)(t % 1000000); } return 0;}
 
116444736000000000LL 就是 int64 类型的常量吧,8字节。const EPOCHFILETIME: Int64 = 116444736000000000;应该可以吧.
 
// 刚才没事自己转了下,个人才疏学浅,仅供参考。。。type PTimeVal = ^TTimeVal; TTimeVal = record tv_sec : Longint; tv_usec: Longint; end; PTimeZone = ^TTimeZone; TTimeZone = record tz_minuteswest: Integer; tz_dsttime : Integer; end;const EPOCHFILETIME = Int64(116444736000000000);function gettimeofday(tv: PTimeVal; tz: PTimeZone): Integer;{$J+}const tzflag : Integer = 0; // 可以用全局变量。。。{$J-}var ft: FILETIME; li: LARGE_INTEGER; t: Int64;begin if Assigned(tv) then begin GetSystemTimeAsFileTime(ft); li.LowPart := ft.dwLowDateTime; li.HighPart := ft.dwHighDateTime; t := li.QuadPart; (* In 100-nanosecond intervals *) t := t - EPOCHFILETIME; (* Offset to the Epoch time *) t := t div 10; (* In microseconds *) tv^.tv_sec := LongInt(t div 1000000); tv^.tv_usec := LongInt(t mod 1000000); end; //...... //Inc(tzflag); Result := 0;end;
 
接受答案了.
 
后退
顶部