Datatypes-Porting Win32 Code to Linux? 10
Dionysus asks: "We have some internal utilities running on Windows NT (using Visual C++) that we would like to port to Linux. The problem is, Microsoft, in its infinite wisdom has extended the language and introduced new types (like CHAR, WCHAR, TCHAR), and new functions (like MultiByteToWideChar()), which makes it impossible to do a straight compile. Note, we are not using WIN32 specific stuff (like MFC, COM etc). Are there any libraries out there that would make the porting easier?"
Winelib (Score:1)
Xemacs (Score:1)
It deals a little with the issues of windows treatment of TCHAR, WCHAR.
win32 types (Score:1)
typedef WCHAR wchar_t;
#else
# ifdef u_int32_t
typedef WCHAR u_int32_t;
# else
typedef WCHAR unsigned int;
# endif
#endif
typedef CHAR char;
#ifdef UNICODE
typedef TCHAR WCHAR;
#else
typedef TCHAR char;
#endif
#ifdef u_int32_t
typedef DWORD u_int32_t;
typedef WORD u_int16_t;
#else
/*
* these are less portable because
* it assumes 'short' is 16 bit
* and 'int' is 32 bit
*/
typedef DWORD unsigned int;
typedef WORD unsigned short;
#endif
Re:win32 types (Score:1)
Trivially... (Score:1)
for the preprocessor macros, run CL -P from the command line or from VC++: this stops it after the preprocessor step.
for the typedef'd stuff, steal the type definitions found in winnt.h (i.e. #include "cutdownwinnt.h" somewhere in your source)
for the Win32 stuff (and yes, calls like ::MultiByteToWideChar() are API functions: this particular one converts ASCII and DBCS strings into Unicode ones), you're going to have to decide whether the functionality's necessary and if so whether any of the GCC libs or add on libs have that functionality or if you're going to have to roll your own. To find out all about those closed secret APIs, look here [microsoft.com].
HTH
--
Cheers
Re:Mainsoft (Re: Porting Win32 Code to Linux?) (Score:1)
Mainwin, at least, as of 6 months ago, was completely useless. Yes, it did successfully emulate the Win32 APIs. Unfortunately, it had about 10 times as many bugs as running natively on these APIs; Many of these bugs could either not be worked around, or were very difficult to work around. The company I was working for was porting their software from Windows to Unix using Mainwin, and eventually got tired of waiting for Yet Another Mainwin Patch to fix these critical bugs that prevented us from shipping. Perhaps Mainwin on Linux is better than Mainwin on Solaris, but... For the price we were paying them, we expected much more than we got. (Part of the price problem, however, is that their code includes parts of the NT source, and as such, they are required to license according to Microsoft terms -- i.e. you have to pay a per-seat runtime license for your software. For every copy of your software that sells, part of that goes to Mainsoft, and in turn, part of that goes to Microsoft.)
As far as the issue of types goes...
The only real issue with MS types on non-MS compilers are the random MS extensions, which include 'uuid' attributes (for COM integration, basically), and unnamed structs, which many compilers don't support -- i.e. like:
In the above example, i and a are both located at offset 0 from the start of the struct, and b is located at offset sizeof(char) from the start of the struct. Normally, you would have to use:
and access a and b as foo.a and foo.b.
Not that it's a simple matter to handle the weird MS types, but it's a surmountable issue if you are willing to get into typedefs and some preprocessor ugliness.
Here's a file I use (Score:1)
Here are my typedefs:
typedef long int COLORREF;
typedef long int DWORD;
typedef long int LONG;
typedef long int LPARAM;
typedef int* LPINT;
typedef char* LPSTR;
typedef char* LPTSTR;
typedef const char* LPCSTR;
typedef const char* LPCTSTR;
typedef long int LRESULT;
typedef long int POSITION;
typedef char TCHAR;
typedef unsigned int UINT;
typedef void VOID;
typedef long int WPARAM;
regexes (Score:1)
I've done this a couple times -- it's a little unnerving, but it definitely works quickly. (If you really want to get hard-core, like a having to convert some text in ~10k lines of Perl, try tying directly into the interpreter, to identify scope, quoting, context, fxn calls, etc).
have fun!
Mainsoft (Re: Porting Win32 Code to Linux?) (Score:1)
It's not free as Wine but it's the real product.
http://www.mainsoft.com/
http://www.mainsoft.com/products/linux/linux_wh
or you can just copy the WTYPES.H header (Score:2)