Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Win32 data types equivalant in Linux

Tags:

c++

linux

I am trying to convert a C++ library which is using widely DWORD, CString and BYTE in the program, and now I am converting the code from C++ Win32 library to linux program . Also I am using openSUSE 12.3 and Anjuta IDE to do this , please help me which types I should use instead of mentioned types ? I think I should use unsigned int for DWORD and string for CString and unsigned char instead of BYTE is it right ?

like image 253
Bahram Avatar asked Apr 30 '13 09:04

Bahram


2 Answers

CString will not convert directly to std::string, but it is a rough equivalent.

BYTE is indeed unsigned char and DWORD is unsigned int. WORD is unsigned short.

You should definitely use typedef actual_type WINDOWS_NAME; to fix the code up, don't go through everywhere to replace the types. I would add a new headerfile that is called something like "wintypes.h", and include that everywhere the "windows.h" is used.

Edit for comment: With CString, it really depends on how it is used (and whether the code is using what MS calls "Unicode" or "ASCII" strings). I would be tempted to create a class CString and then use std::string inside that. Most of it can probably be done by simply calling the equivalent std::string function, but some functions may need a bit more programming - again, it does depend on what member functions of CString are actually being used.

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

like image 99
Mats Petersson Avatar answered Oct 24 '22 09:10

Mats Petersson


  • DWORD = uint32_t
  • BYTE = uint8_t

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

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

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

like image 41
Aymeric Barthe Avatar answered Oct 24 '22 09:10

Aymeric Barthe