LARGE_INTEGER and BYTE types in Linux?

2019-09-10 06:03发布

问题:

I am studying one Windows code which converting to Linux and this answer here. It is possible that there are no injective datatypes between LARGE_INTEGER and BYTE in Linux so special situations may need to be considered.

The two data types could possibly replaced by the following two in Linux

  • uint64_t
  • unsigned char

where the first one is a part of stdint.h. I would propose replace both LARGE_INTEGER and BYTE by uint64_t but not certain.

Which Linux datatypes can use in place of LARGE_INTEGER and BYTE?


The following file is a case example of National Instruments' driver for MCA 8000A described here.

MictoTime.h

//////////////////////////////////////////////////////////////////////
//
// MicroTime.h: interface for the MicroTime class.
//
// This header file is a part of the PMCA COM package
//
// Amptek Inc. 2000
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MICROTIME_H__495147C7_F0B7_11D1_B62F_9CFF0CC10000__INCLUDED_)
#define AFX_MICROTIME_H__495147C7_F0B7_11D1_B62F_9CFF0CC10000__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

class MicroTimeType  
{
    LARGE_INTEGER m_startTime;
    double m_microScale;
    BOOL m_waiting;
public:
    MicroTimeType();
    LARGE_INTEGER GetCounter();
    double Get(void);
    double Wait(double microSec);
    void CancelWait(void);
};

#endif // !defined(AFX_MICROTIME_H__495147C7_F0B7_11D1_B62F_9CFF0CC10000__INCLUDED_)

Do you need to add here new types of this answer? Do you need to define uint8_t anywhere else?

回答1:

You can see the reference for data types in C supported by Windows API and toolchain.

LARGE_INTEGER is actually a union representing signed 64-bit integers which has been historically used in some APIs. Simple typedef int64_t LARGE_INTEGER; won't work as expected.

You will need something like this:

#include <stdint.h>

typedef uint8_t BYTE;
typedef uint32_t DWORD;
typedef int32_t LONG;
typedef int64_t LONGLONG;

typedef union _LARGE_INTEGER {
  struct {
    DWORD LowPart;
    LONG  HighPart;
  };
  struct {
    DWORD LowPart;
    LONG  HighPart;
  } u;
  LONGLONG QuadPart;
} LARGE_INTEGER, *PLARGE_INTEGER;


标签: linux windows