Porting MFC/Win32 applications to MAC OS X
This document discusses on porting Visual Studio MFC/Win32 based applications to Mac OS X. It also gives an introduction to various technics available to develop a rich UI applications in Mac OS X.
Introduction to MAC OS X
Mac OS X supports multiple development technologies like Cocoa object-oriented framework, to compensate J2SE 1.3 and 1.4.2 implementations, of common UNIX tools and scripting languages. Apple provides an advanced XCode Tools, is a software development environment. We have VC++, VB, Javascript and VB script in Visual studio in Windows, similarly XCode in MAC.
All the information about the installed applications are stored in a configuration files, like the registry information in Windows. Mac uses CUPS (Common Unix Printing System) as a default Printer driver.
Darwin Kernel environment, BSD libraries and BSD command environment which performs the operations of Kernel, similar to User and GDI in Windows OS. Quartz in Mac OS X is like GDI and GDI+ in Windows which is used for graphics and windowing environment. The OpenGL framework (OpenGL framework) in Mac OS X includes a highly optimized implementation of the OpenGL libraries that provides high-quality graphics which is also available in Windows.
MAC OS X Architecture
Mac OS X Runtime Architecture
A runtime environment is a set of conventions that determines how code and data are loaded into memory and managed. Like MSVCRT,Libc in windows.
Mac OS X supports two modern runtime environments: dyld (dynamic loader) and CFM (Code Fragment Manager).Windows provide dll's,Library(Static & Dynamic) etc., which performs the similar operations.
Dyld Runtime Environment
The dyld runtime environment is the preferred environment for any development because it is the native environment used by all Mac OS X system libraries. To support this environment, we should build our code modules using the Mach-O executable file format. The dyld library manager is the program responsible for loading your Mach-O code modules, resolving library dependencies and beginning the execution of our code.
CFM Runtime Environment
The CFMruntime environment is the legacy environment inherited from Mac OS 9. The CFM runtime environment expects code modules to be built using the Preferred Executable Format (PEF).
In Windows we can achieve these things using single threading,multiple threading,COM,ATL,dll's etc.,
Development Environment
XCode
XCode is the engine that powers Apple's integrated development environment (IDE) for Mac OS X as Visual studio in Windows. XCode provides a flexible tree listing, a code editor with syntax highlighting and Microsoft-like IntelliSense to automatically insert method definitions for easy coding. XCode doesn't have tabbed window like visual studio instead it should be opened in new window.
Using XCode we can build projects containing source code written in C, C++, Objective-C, Objective-C++, and Java. It generates executables of all supported types on Mac OS X, including command-line tool's, frameworks, plug-ins, kernel extensions, bundles, and applications. As we have Visual studio in Windows for developing Win32, MFC, ATL, C++ and other applications.
CARBON
Carbon application environment contains set of C APIs used to create full-featured applications for all types of users. The Carbon environment includes support for all the standard Aqua user interface elements such as Windows, controls, and menus, which we can design using Interface Builder. It also provides an extensive infrastructure for handling events, managing data, and using system resources. Like MFC (Microsoft Foundation Classes) in Windows environment.
The Carbon application environment comprises of several key frameworks, Carbonframework (Carbon.Framework), CoreServicesframework (CoreServices.framework), ApplicationServices framework (ApplicationServices. framework). Three types of projects can be created using carbon they are Carbon Application,Carbon C++ Application,Carbon C++ Standard Application and Carbon Dynamic Library.
General Carbon API's and its Equivalent Win32 or MFC API's
Rendering API's in Carbon
MFC equivalent API's
View
Parameters
inOptions - Options for our scroll view. You must specify either a horizontal or a vertical scroll bar. If neither is passed, an error is returned. For possible values, see " Scroll View Constants ".
outView - The new scroll view.
Return Value
An operating system result code.
Other Related Scroll View Functions
Rendering Images
Parameters
- context - The graphics context in which to draw the image
- rect - The location and dimensions in user space of the bounding box in which to draw the image
- Image - The image to draw
Alpha Blending (Colorizing an Image)
One way that you can use the color blend mode is to colorize an image. Draw the image you want to colorize. Then set the blend mode by passing the constant kCGBlendModeColor to the function CGContextSetBlendMode. Draw and fill a rectangle (or other shape) using the color you want to use for colorizing the image. The code in Listing draws a fully opaque red rectangle over the image of the jumper, to achieve the result shown on the right side of the figure. Note that the entire image of the jumper is not colorized because the red rectangle is smaller than the image.
The Following code will render the image with blending option.
Similar Alpha Blending in Visual C++
This sample will show the first page after Alpha Blending in windows and next page with normal display.
Function for Alpha Blending is available in CImage::AlphaBlend which is present in Windows GDI platform SDK used in vc++ application on windows environment. The BLENDFUNCTION structure controls blending by specifying the blending functions for source and destination bitmaps.
Saving and Restoring the Current Graphics State
VC++ equivalent Function
Converting Between Device Space and User Space
Other Related Rendering Functions
Functions related with Setting Color, Color Space, and Shadow Values
Equivalent MFC functions
Example
ToolBar Functions in VC++
Menu Creation Functions in VC++
Similar function for creating Menu in Carbon
Windows Functions in vc
MAC equivalent Window Function
File Operation in Macintosh
C equivalent functions
Datatypes in MAC
Equivalent Datatype in VC++
FileHandling functions can be used commonly both vc++ and in carbon if it is based on C language as given
COCOA
Cocoa is an advanced object-oriented development platform in Mac OS X. Cocoa is a set of frameworks used for the development of full-featured applications in the Objective-C language. It is based on the integration of OpenStep, Apple technologies, and Java. Cocoa consists of two faces, Runtime Aspect and Development Aspect. The Cocoa application environment consists of two object-oriented frameworks:
- Foundation Framework Classes :Implements data management, file access, process notification, memory management,network communication, and other low-level features.
- Application Kit framework Clases : Implements the user interface layer of an application, including windows, dialogs, controls, menus, and event handling.
- Cocoa framework : Imports both Foundation and the Application Kit. If we are writing a Cocoa program that does not have a graphical user interface (a background server, for example), we can link the program with the Foundation framework.
Using Cocoa we can create different types of applications like Cocoa Application, Cocoa Document-based Application, Cocoa-Java Application and Cocoa-Java Document-based Application like win32 application, Dialog based application, Document-view Application in VC++ & MFC.
Objective C
An object-oriented programming language based on standard C and a runtime system that implements the dynamic functions of the language. Objective-C is extension to the C language which is based on Smalltalk, one of the first object-oriented programming languages. Objective-C is available in the Cocoa application environment. The Objective-C language is a superset of ANSI C with special syntax and run-time extensions that make object-oriented programming possible.
Creating an Executable in MAC
In Windows the Executable files are .Exe file and for Mac there is a bundling mechanism called .app. In Mac .app is a folder which contains a specific layout for binary executable file and all other applications resources (image files, nib files, etc...). XCode creates these bundles when compiling the application.
For creating setup we are using Install shield in Windows. For Mac .DMG can be used to create Disk Copy, burnt to CD or mounted as a normal volume. Or we can use "Package Maker" free apple supplied Installer. In general Mac applications do not need installers. The preferred mechanism is to place the .app bundle onto a disk image (DMG) and allow the user to drag the app from the disk image. User can uninstall the app by simply dragging the .app bundle to the trash.
Steps to Create DMG File in MAC
- Step 1 : Create a New Folder in MAC and place the files that should be created in disk image into this new folder.
- Step 2 : Right click (or CTRL-Click) the folder and select "Get Info" and note the size of it's contents.
- Step 3 : Open Disk Utility (Applications > Utilities > Disk Utility)
- Step 4 : Click the "New Image" icon to create a new disk image. Enter a name for the Image, and select a size adequate for the size of your folder you created in Step 2. Set the encryption to "none" and Format to "read/write disk image".
- Step 5 : Place the contents of the folder from Step 2 into the newly mounted disk image
- Step 6 : Unmount the Disk Image.
Conclusion
There is no direct porting facility between this operating systems. For example C, C++ developers will like to work on Carbon, Java programers or Visual Basic developers in Java or Cocoa, Unix based programmers in BSD or X11 and Applescript for scripting language.Though they are using one common developing environment called Xcode.

