Win32 data type equivalent on Linux

I am trying to convert a C ++ library that makes extensive use of DWORD, CString and BYTE in a program, and now I am converting code from a Win32 C ++ library to a linux program. I also use openSUSE 12.3 and Anjuta IDE for this, please help me, what types should I use instead of the specified types? I think I should use unsigned int for DWORD and string for CString and unsigned char instead of BYTE, is this correct?

+4
source share
4 answers

CString not converted directly to std::string , but it is an approximate equivalent.

BYTE really an unsigned char , and DWORD is an unsigned int . WORD unsigned short .

You must definitely use typedef actual_type WINDOWS_NAME; To fix the code, do not go everywhere to replace types. I would add a new header file, which is called something like "wintypes.h", and includes that "windows.h" is used everywhere.

Edit comment: With CString it really depends on how it is used (and whether the code uses what MS calls "Unicode" or "ASCII"). I would have a desire to create a CString class, and then use std::string inside this. Most of them can probably be done simply by calling the equivalent function std::string , but some functions may need a bit more programming - again, it depends on which member functions from CString actually used.

For LP<type> is just a pointer to <type> , so typedef BYTE* LPBYTE; and typedef DWORD* LPDWORD; will do it.

+7
source
 typedef unsigned long DWORD; typedef unsigned char BYTE; CString -> maybe basic_string<TCHAR> ? 
+1
source

I would suggest using uint32_t and uint8_t for DWORD and BYTE and normal char * or const char * for strings (or the std: string class for C ++).

It is probably best to use typedef for existing code:

 typedef unsigned char BYTE; 

They can be easily changed.

If you rewrite the use of char, int, long code were useful and (u) intX_t, you need a certain size.

+1
source
  • DWORD = uint32_t
  • BYTE = uint8_t

These types are not OS specifications and were added in C ++ 11. You need to include <cstdint> to get them. If you have an old compiler, you can use boost / cstdint, which is just the header.

Use std::string instead of CString , but you will need to change the code.

With these changes, your code should compile on both Windows and Linux.

+1
source

All Articles