-1

Recently I convert a windows c++ program to linux,I write a .h file to convet some type where linux does not have that the prgram use.

#define _MAX_PATH           260 /* max. length of full pathname */

#define HANDLE              int
#define MAX_PATH            260
#define TRUE                true 
#define FALSE               false

#define max(a,b)            (((a) > (b)) ? (a) : (b))
#define min(a,b)            (((a) < (b)) ? (a) : (b))

typedef int                 BOOL;
typedef unsigned long       DWORD;
typedef void                VOID;

typedef wchar_t             WCHAR;
typedef WCHAR               *LPWSTR;
typedef unsigned char       BOOLEAN;

I am not familiar with windows types,Just use vs 2010 select the type then call F12,Does it right?

52coder
  • 179
  • 1
  • 2
  • 11
  • Does what right? – Jeremy Friesner Jan 10 '19 at 02:31
  • @JeremyFriesner copy the type such as DWORD to vs 2010 ,then use F12 to see what really the type is . – 52coder Jan 10 '19 at 03:18
  • Read the documentation: [Windows Data Types](https://learn.microsoft.com/en-us/windows/desktop/winprog/windows-data-types) – Remy Lebeau Jan 10 '19 at 05:48
  • `MAX_PATH` is Posix's `PATH_MAX` on Linux. I've seen hardcoded values up to 4096 on Unix & Linux like Solaris and OS X. Why don't you use it the way it is intended? [Where is PATH_MAX defined in Linux?](https://stackoverflow.com/q/9449241/608639) and [Is there an equivalent to WinAPI's MAX_PATH under linux/unix?](https://stackoverflow.com/q/833291/608639). This is stuff you could have found with a simple search. – jww Jan 10 '19 at 06:09
  • @jww thanks ,I will check and use it. – 52coder Jan 10 '19 at 09:30

1 Answers1

1

Porting Windows program to Linux is not easy as you think and requires some experience and time efforts. You cannot just change or adapt types definition. You'll need to investigate which API and libraries your program use. Than carefully replace them with Linux equivalent. Some libraries are cross-platform out of the box, some are not.

Sometimes it is not possible to port the program at all. In this case it's mush easier to develop Linux analog from scratch or even design a cross-platform solution.

chronoxor
  • 3,159
  • 3
  • 20
  • 31
  • thanks for your advice,I find it was hard to transfer code from windows to linux,I will try another day,otherwise I will rewrite it. – 52coder Jan 10 '19 at 03:19
  • @52coder Rather than rewriting everything, replace as much as possible with Standard library calls (`std::thread`, `filesystem`, etc...). Then build yourself a portability layer that abstracts away any other API differences between Windows and Linux and replace all the Windows-specific calls with calls to the portability layer. Make sure it works, then write the portability layer for Linux. – user4581301 Jan 10 '19 at 04:55