github.com/gotranspile/cxgo@v0.3.7/libs/windows.go (about)

     1  package libs
     2  
     3  const (
     4  	windowsH = "windows.h"
     5  )
     6  
     7  func init() {
     8  	RegisterLibrary(windowsH, func(c *Env) *Library {
     9  		return &Library{
    10  			// TODO
    11  			Header: `
    12  #include <` + BuiltinH + `>
    13  #include <` + stddefH + `>
    14  #include <` + sysSocketH + `>
    15  #include <` + unistdH + `>
    16  
    17  #define __cdecl
    18  #define __fastcall
    19  #define __stdcall
    20  #define WINAPI
    21  #define WINAPIV
    22  
    23  #define VOID void
    24  #define FALSE 0
    25  #define TRUE 1
    26  
    27  #define MAX_PATH 260
    28  #define INFINITE ((DWORD)-1)
    29  
    30  #define BYTE _cxgo_uint8
    31  #define WORD _cxgo_uint16
    32  #define DWORD _cxgo_uint32
    33  #define QWORD _cxgo_uint64
    34  
    35  #define _BYTE _cxgo_uint8
    36  #define _WORD _cxgo_uint16
    37  #define _DWORD _cxgo_uint32
    38  #define _QWORD _cxgo_uint64
    39  
    40  #define BOOL int
    41  
    42  #define CHAR _cxgo_int8
    43  #define WCHAR wchar_t
    44  
    45  #define INT int
    46  #define UINT unsigned int
    47  #define LONG long
    48  #define ULONG unsigned long
    49  #define LONGLONG long long
    50  #define ULONGLONG unsigned long long
    51  
    52  #define PLONG LONG*
    53  
    54  #define LPVOID VOID*
    55  #define LPBOOL BOOL*
    56  #define LPBYTE BYTE*
    57  #define LPWORD WORD*
    58  #define LPDWORD DWORD*
    59  #define LPQWORD QWORD*
    60  
    61  #define WORD_PTR WORD*
    62  #define DWORD_PTR DWORD*
    63  #define QWORD_PTR QWORD*
    64  
    65  #define LPCCH const char*
    66  #define LPCSTR const char*
    67  #define LPSTR char*
    68  #define LPCWSTR const wchar_t*
    69  #define LPWSTR wchar_t*
    70  
    71  #define INT_PTR intptr_t
    72  #define UINT_PTR uintptr_t
    73  
    74  typedef void* HINSTANCE;
    75  typedef void* HMODULE;
    76  typedef int HANDLE;
    77  typedef int HWND;
    78  typedef int HDC;
    79  typedef int HIMC;
    80  
    81  typedef INT_PTR LRESULT;
    82  typedef INT_PTR LSTATUS;
    83  typedef INT_PTR LPARAM;
    84  typedef UINT_PTR WPARAM;
    85  
    86  typedef struct _REGKEY* HKEY;
    87  typedef HKEY* PHKEY;
    88  #define HKEY_LOCAL_MACHINE ((HKEY)1)
    89  
    90  typedef int SOCKET;
    91  
    92  typedef int LCID;
    93  typedef int REGSAM;
    94  
    95  typedef struct {
    96  	WORD wFormatTag;
    97  	WORD nChannels;
    98  	DWORD nSamplesPerSec;
    99  	DWORD nAvgBytesPerSec;
   100  	WORD nBlockAlign;
   101  } WAVEFORMAT;
   102  
   103  typedef struct _WAVEOUT {};
   104  
   105  #define HWAVEOUT struct _WAVEOUT*
   106  
   107  #define LPWAVEFORMAT WAVEFORMAT*
   108  #define LPHWAVEOUT HWAVEOUT*
   109  
   110  #pragma pack(push, 1)
   111  typedef struct {
   112  	WORD wFormatTag;
   113  	WORD nChannels;
   114  	DWORD nSamplesPerSec;
   115  	DWORD nAvgBytesPerSec;
   116  	WORD nBlockAlign;
   117  	WORD wBitsPerSample;
   118  	WORD cbSize;
   119  } WAVEFORMATEX;
   120  
   121  typedef struct {
   122  	WAVEFORMATEX wfx;
   123  	WORD wID;
   124  	DWORD fdwFlags;
   125  	WORD nBlockSize;
   126  	WORD nFramesPerBlock;
   127  	WORD nCodecDelay;
   128  } MPEGLAYER3WAVEFORMAT;
   129  #pragma pack(pop)
   130  
   131  typedef struct _GUID {
   132  	DWORD Data1;
   133  	WORD Data2;
   134  	WORD Data3;
   135  	BYTE Data4[8];
   136  } GUID;
   137  typedef GUID IID;
   138  
   139  typedef struct _SYSTEMTIME {
   140  	WORD wYear;
   141  	WORD wMonth;
   142  	WORD wDayOfWeek;
   143  	WORD wDay;
   144  	WORD wHour;
   145  	WORD wMinute;
   146  	WORD wSecond;
   147  	WORD wMilliseconds;
   148  } SYSTEMTIME, *LPSYSTEMTIME;
   149  
   150  typedef struct _MEMORYSTATUS {
   151  	DWORD dwLength;
   152  } MEMORYSTATUS, *LPMEMORYSTATUS;
   153  
   154  typedef union _LARGE_INTEGER {
   155  	QWORD QuadPart;
   156  	DWORD LowPart;
   157  } LARGE_INTEGER, *PLARGE_INTEGER;
   158  
   159  typedef struct _FILETIME {
   160  	DWORD dwLowDateTime;
   161  	DWORD dwHighDateTime;
   162  } FILETIME, *LPFILETIME;
   163  
   164  typedef struct _SECURITY_ATTRIBUTES {
   165  } SECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
   166  
   167  typedef struct _CRITICAL_SECTION {
   168  	void* opaque;
   169  } CRITICAL_SECTION, *LPCRITICAL_SECTION;
   170  
   171  typedef struct _OSVERSIONINFOA {
   172  	DWORD dwOSVersionInfoSize;
   173  	DWORD dwMajorVersion;
   174  	DWORD dwMinorVersion;
   175  	DWORD dwBuildNumber;
   176  	DWORD dwPlatformId;
   177  	BYTE szCSDVersion[128];
   178  } OSVERSIONINFOA, *LPOSVERSIONINFOA;
   179  
   180  typedef struct _WIN32_FIND_DATAA {
   181  	DWORD dwFileAttributes;
   182  	FILETIME ftCreationTime;
   183  	FILETIME ftLastAccessTime;
   184  	FILETIME ftLastWriteTime;
   185  	DWORD nFileSizeHigh;
   186  	DWORD nFileSizeLow;
   187  	DWORD dwReserved0;
   188  	DWORD dwReserved1;
   189  	CHAR cFileName[MAX_PATH];
   190  	CHAR cAlternateFileName[14];
   191  } WIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;
   192  
   193  typedef struct _OVERLAPPED {
   194  } OVERLAPPED, *LPOVERLAPPED;
   195  
   196  typedef struct _RECT {
   197  	LONG left;
   198  	LONG top;
   199  	LONG right;
   200  	LONG bottom;
   201  } RECT, *LPRECT;
   202  
   203  typedef struct _POINT {
   204  	LONG x;
   205  	LONG y;
   206  } POINT;
   207  
   208  typedef struct WSAData {
   209  	WORD wVersion;
   210  	WORD wHighVersion;
   211  	CHAR szDescription[257];
   212  	CHAR szSystemStatus[129];
   213  	WORD iMaxSockets;
   214  	WORD iMaxUdpDg;
   215  	LPVOID lpVendorInfo;
   216  } WSADATA, *LPWSADATA;
   217  
   218  struct _stat {
   219  	DWORD st_dev;
   220  	WORD st_ino;
   221  	WORD st_mode;
   222  	WORD st_nlink;
   223  	WORD st_uid;
   224  	WORD st_gid;
   225  	DWORD st_rdev;
   226  	DWORD st_size;
   227  	DWORD st_mtime;
   228  	DWORD st_atime;
   229  	DWORD st_ctime;
   230  };
   231  
   232  struct in_addr {
   233  	union {
   234  		DWORD S_addr;
   235  	} S_un;
   236  };
   237  
   238  #define _strdup strdup
   239  #define _strcmpi strcasecmp
   240  #define _strnicmp strncasecmp
   241  #define _fileno fileno
   242  #define _read read
   243  #define _write write
   244  #define _close close
   245  #define _onexit atexit
   246  
   247  unsigned int _control87(unsigned int new_, unsigned int mask);
   248  unsigned int _controlfp(unsigned int new_, unsigned int mask);
   249  int _open(const char* filename, int oflag, ...);
   250  int _chmod(const char* filename, int mode);
   251  int _access(const char* filename, int mode);
   252  int _stat(const char* path, struct _stat* buffer);
   253  int _mkdir(const char* path);
   254  int _unlink(const char* filename);
   255  char* _getcwd(char* buffer, int maxlen);
   256  uintptr_t _beginthread(void(__cdecl* start_address)(void*), unsigned int stack_size, void* arglist);
   257  char* _strrev(char* str);
   258  char* _itoa(int val, char* s, int radix);
   259  wchar_t* _itow(int val, wchar_t* s, int radix);
   260  void _makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext);
   261  void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext);
   262  
   263  VOID WINAPI DebugBreak();
   264  BOOL WINAPI CloseHandle(HANDLE hObject);
   265  DWORD WINAPI GetLastError();
   266  VOID WINAPI GetLocalTime(LPSYSTEMTIME lpSystemTime);
   267  HANDLE WINAPI FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
   268  BOOL WINAPI FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData);
   269  BOOL WINAPI FindClose(HANDLE hFindFile);
   270  HANDLE WINAPI CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
   271  			  LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
   272  			  DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
   273  BOOL WINAPI ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead,
   274  		     LPOVERLAPPED lpOverlapped);
   275  DWORD WINAPI SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod);
   276  BOOL WINAPI CopyFileA(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExists);
   277  BOOL WINAPI DeleteFileA(LPCSTR lpFileName);
   278  BOOL WINAPI MoveFileA(LPCSTR lpExistingFileName, LPCSTR lpNewFileName);
   279  BOOL WINAPI CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
   280  BOOL WINAPI RemoveDirectoryA(LPCSTR lpPathName);
   281  DWORD WINAPI GetCurrentDirectoryA(DWORD nBufferLength, LPSTR lpBuffer);
   282  BOOL WINAPI SetCurrentDirectoryA(LPCSTR lpPathName);
   283  int WINAPI GetDateFormatA(LCID Locale, DWORD dwFlags, const SYSTEMTIME* lpDate, LPCSTR lpFormat, LPSTR lpDateStr,
   284  			  int cchDate);
   285  LSTATUS WINAPI RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult);
   286  LSTATUS WINAPI RegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData,
   287  				LPDWORD lpcbData);
   288  LSTATUS WINAPI RegSetValueExA(HKEY, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, const BYTE* lpData, DWORD cbData);
   289  LSTATUS WINAPI RegCloseKey(HKEY hKey);
   290  int WINAPI MulDiv(int nNumber, int nNumerator, int nDenominator);
   291  LSTATUS WINAPI RegCreateKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD Reserved, LPSTR lpClass, DWORD dwOptions,
   292  			       REGSAM samDesired, const LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult,
   293  			       LPDWORD lpdwDisposition);
   294  VOID WINAPI GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer);
   295  DWORD WINAPI GetModuleFileNameA(HMODULE hModule, LPSTR lpFileName, DWORD nSize);
   296  BOOL WINAPI QueryPerformanceCounter(LARGE_INTEGER* lpPerformanceCount);
   297  BOOL WINAPI QueryPerformanceFrequency(LARGE_INTEGER* lpFrequency);
   298  VOID WINAPI InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection);
   299  VOID WINAPI DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection);
   300  VOID WINAPI EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection);
   301  VOID WINAPI LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection);
   302  BOOL WINAPI HeapDestroy(HANDLE hHeap);
   303  BOOL WINAPI GetVersionExA(LPOSVERSIONINFOA lpVersionInformation);
   304  VOID WINAPI OutputDebugStringA(LPCSTR lpOutputString);
   305  HINSTANCE WINAPI ShellExecuteA(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory,
   306  			       INT nShowCmd);
   307  int WINAPI GetTimeFormatA(LCID Locale, DWORD dwFlags, const SYSTEMTIME* lpTime, LPCSTR lpFormat, LPSTR lpTimeStr,
   308  			  int cchTime);
   309  BOOL WINAPI SystemTimeToFileTime(const SYSTEMTIME* lpSystemTime, LPFILETIME lpFileTime);
   310  LONG WINAPI CompareFileTime(const FILETIME* lpFileTime1, const FILETIME* lpFileTime2);
   311  HANDLE WINAPI CreateMutexA(LPSECURITY_ATTRIBUTES lpSecurityAttributes, BOOL bInitialOwner, LPCSTR lpName);
   312  BOOL WINAPI ReleaseMutex(HANDLE hMutex);
   313  BOOL WINAPI SetEvent(HANDLE hEvent);
   314  DWORD WINAPI WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds);
   315  char* WINAPI inet_ntoa(struct in_addr in);
   316  int WINAPI WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar,
   317  			       LPSTR lpMultiByteStr, int cbMultiByte, LPCCH lpDefaultChar, LPBOOL lpUsedDefaultChar);
   318  
   319  LONG InterlockedExchange(volatile LONG* Target, LONG Value);
   320  LONG InterlockedDecrement(volatile LONG* Addend);
   321  LONG InterlockedIncrement(volatile LONG* Addend);
   322  int WINAPI MessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType);
   323  int WINAPI WSAStartup(WORD wVersionRequested, struct WSAData* lpWSAData);
   324  int WINAPI WSACleanup();
   325  int WINAPI closesocket(SOCKET s);
   326  int WINAPI ioctlsocket(SOCKET s, long cmd, unsigned long* argp);
   327  int WINAPI WSAGetLastError();
   328  SOCKET WINAPI socket(int domain, int type, int protocol);
   329  int WINAPI setsockopt(SOCKET s, int level, int opt, const void* value, unsigned int len);
   330  int WINAPI bind(int sockfd, const struct sockaddr* addr, unsigned int addrlen);
   331  int WINAPI recvfrom(int sockfd, void* buffer, unsigned int length, int flags, struct sockaddr* addr,
   332  		    unsigned int* addrlen);
   333  int WINAPI sendto(int sockfd, void* buffer, unsigned int length, int flags, const struct sockaddr* addr,
   334  		  unsigned int addrlen);
   335  `,
   336  		}
   337  	})
   338  }