What's with "#ifdef _MAC" in Windows header files?
Asked Answered
E

5

20

I was browsing through Windows's Platform SDK header files (what a life, right?), and I noticed many places contained references to the preprocessor symbol _MAC. For example:

// WinUser.h line 1568
/*
 * Message structure
 */
typedef struct tagMSG {
    HWND        hwnd;
    UINT        message;
    WPARAM      wParam;
    LPARAM      lParam;
    DWORD       time;
    POINT       pt;
#ifdef _MAC
    DWORD       lPrivate;
#endif
} MSG, *PMSG, NEAR *NPMSG, FAR *LPMSG;

Does this mean "Macintosh", as it appears? Was there a time where Windows or a subset of Windows could be compiled for the Macintosh?

Endurable answered 4/3, 2010 at 2:18 Comment(0)
S
21

At one time Microsoft was the largest developer of Macintosh software in the world. Excel and Word dominated their respective markets on the Macintosh, and later so did Office. So it's not that surprising that the applications division at MS would want a subset of the Windows header files that worked on the MAC - to make their cross platform software easier to maintain.

But there was never any version of the Windows OS that ran on the Macintosh.

In any case, this fragment is from objidl.h, seems to indicate that _MAC does indeed mean Macintosh in the header files though...

//FSSpec is Macintosh only, defined in macos\files.h
#ifdef _MAC
    typedef struct tagSTATSTG
    {                      
        LPOLESTR pwcsName;
            FSSpec *pspec;
        DWORD type;
        ULARGE_INTEGER cbSize;
...
    } STATSTG;
#else //_MAC
Sardinia answered 4/3, 2010 at 2:33 Comment(0)
W
14

As others have noted, Microsoft apps were ported to the Mac, and they probably found it easier to turn the underlying APIs/frameworks into a portable abstraction layer, rather than rewrite the apps themselves... just as the QuickTime team reportedly did when porting in the opposite direction (from Mac to Windows -- there are similar #if WIN32 conditionals in the Mac's Carbon headers). E.g., rather than riffle though your entire Win32 app's code base looking for CreateFile() and replacing or conditionalizing each reference with #ifdefs, just create a Mac version of CreateFile() and be done with it. Repeat for each Win32 API call.

The surprising bit of historical trivia is this: the end result of Microsoft's porting effort was available to third parties in the form of "Microsoft Visual C++ Cross-Development Edition for Macintosh". So anyone could take their Win32 app and port it to Mac using this abstraction layer.

Quote from my trusty MSDN October 1996 CD:

"Microsoft Visual C++ version 4.0 Cross-Development Edition for Macintosh facilitates the transfer of programs for the Microsoft Windows operating environment to the Apple 680x0 Macintosh or Power Macintosh environment. Designed to provide a complete program development environment, Visual C++ for Macintosh supports C, the standard C run-time library, C++, most of the Microsoft Win32 API including OLE and ODBC, and the Microsoft Foundation Class Library."

So it even included MFC. My guess is that any "#ifdef _MAC" is an artifact of the MSVC++ Cross-Development Edition for Macintosh (R.I.P.).

Weaver answered 9/12, 2010 at 0:22 Comment(0)
A
5

I assume it is/was used for compiling Microsoft software (Office, IE, Windows Media Player) for MacOS. I know that IE and WMP for Solaris included a subset of Windows itself (e.g. libwinnt.so, libkernel32.so) as a direct replacement for the corresponding Windows DLLs.

Aussie answered 4/3, 2010 at 2:24 Comment(3)
Kind of similar to how when looking at iTunes for Windows, you see a bunch of .plist files and something called Foundation.framework or similar, IIRC.Clement
@asveikau: Sure. Many Apple products for Windows even bring the MacOS look & feel with them (just as the Microsoft products for Solaris did), so I guess they do it the other way around and provide MacOS like APIs as a wrapper around Windows.Aussie
@Aussie Actually, for these ObjC libraries this predates Mac OS X substantially. IIRC, NeXT had Foundation/AppKit running under NT in the 90s.Clement
D
2

Lots of MS code has references to MAC as they develop for mac as well - for example office. Probably this bit of the header file came from those teams.

Dacron answered 4/3, 2010 at 2:25 Comment(0)
P
2

As you can see in Windows.h header file, macro _MAC is defined as follows:

#if defined(_68K_) || defined(_MPPC_)
#define _MAC
#endif
#endif

So, yes, it is defined only for old macOS environment (before it started to use intel processors)

Prothorax answered 22/10, 2019 at 10:51 Comment(1)
What do 68K and MPPC refer to?Sunset

© 2022 - 2024 — McMap. All rights reserved.