home *** CD-ROM | disk | FTP | other *** search
/ Microsoftware Monthly 19…2 Programming Power Tools / MASO9512.ISO / smart / sm_port2.inf (.txt) < prev    next >
Encoding:
OS/2 Help File  |  1995-05-10  |  17.8 KB  |  440 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Contents ΓòÉΓòÉΓòÉ
  3.  
  4.    The SMART Programming Guide
  5.      for Portability
  6.        Version 2.1B
  7.        May 1995
  8.  
  9.    (C) 1991, 1994, 1995 One Up Corporation
  10.      All Rights Reserved
  11.  
  12. Topics: 
  13.  
  14.  Introduction 
  15.  Portability Basics 
  16.  Factors Affecting Portability 
  17.  Designing code for Portability 
  18.  Windows Issues 
  19.  Windows Functionality Not Supported 
  20.  OS/2 Changes 
  21.  Summary 
  22.  
  23. CONTINUE 
  24.  
  25.  
  26. ΓòÉΓòÉΓòÉ 2. Introduction ΓòÉΓòÉΓòÉ
  27.  
  28. PROGRAMMING FOR PORTABILITY 
  29.  
  30. Programming applications for portability between platforms requires careful 
  31. planing and decision making before the application is started. 
  32.  
  33. The new GUI based platforms make it convenient to program by providing rich 
  34. interface API (Application Programming Interface) functions available to the 
  35. developer for performing many of the GUI calls, along with memory management, 
  36. I/O and other service functions. 
  37.  
  38. Unfortunately each platform has a different set of API functions to perform 
  39. similar functionality. With the platform specific API calls completely imbedded 
  40. and dispersed in the application code, porting to a different platform is time 
  41. consuming and very costly. 
  42.  
  43. Worse yet, numerous uses of functionality that may exist in one platform, yet 
  44. unsupported in another platform will require large portions of the application 
  45. to be rewritten. Exploiting the powerful features of one platform may lead to a 
  46. non-portable application. 
  47.  
  48. The ultimate case of non-portability is in the extensive use of third party 
  49. libraries in object or executable code which does not support multiple 
  50. platforms. 
  51.  
  52. The following sections will outline the steps to more portable programming for 
  53. applications. Specific suggestions will be made regarding the functionality and 
  54. issues that will cause difficulty in porting Windows applications to OS/2. 
  55.  
  56. By using the programming suggestions offered in this document you will be able 
  57. to create programs that are more portable to new operating platforms. 
  58.  
  59. CONTINUE - Portability Basics 
  60. BACK - Contents 
  61. CONTENTS 
  62.  
  63.  
  64. ΓòÉΓòÉΓòÉ 3. Portability Basics ΓòÉΓòÉΓòÉ
  65.  
  66. BASIC RULES FOR PORTABILITY 
  67.  
  68. The rules for new application development which provide portability are 
  69. straight forward. 
  70.  
  71.    Isolate as much of the platform dependent functions as possible.  Although 
  72. you may introduce an additional layer of code, you will find a great deal more 
  73. portability in creating your own functional layer to isolate the platform. 
  74.  
  75.    Understand that exploitive features in one platform may not be portable to 
  76. another. Plan around this reality if you need the portability. 
  77.  
  78.    Be careful in the use of third party libraries if you do not have access to 
  79. the source code.  You simply cannot port someone else's object files. 
  80.  
  81.    Choose a programming language that is supported with tools and compilers on 
  82. the platforms that you wish to serve. 
  83.  
  84.    Research programming tools and code generators that support multiple 
  85. platforms. In many cases these products can effectively generate the code for 
  86. the platforms that you are targeting. 
  87.  
  88.    Develop a set of development and coding standards that can be used by the 
  89. programming members of your project.  This will help prevent any one of the 
  90. developers writing platform dependent code. 
  91.  
  92.    Plan and make use of macros, ifdefined preprocessor code blocks and other 
  93. coding techniques that may enable you to integrate multiple platform 
  94. dependencies within the same source code files. 
  95.  
  96.    Stick to basics, where possible.  Tricky solutions may depend upon platform 
  97. dependent functionality and subtle side effects that may require thorough 
  98. knowledege to port. 
  99.  
  100.    Make liberal use of coding comments so that the code can be changed to meet 
  101. the requirements of another platform.  Quite often the original programmer is 
  102. not the one to modify the code for porting to a new platform. 
  103.  
  104. CONTINUE - Factors Affecting Portability 
  105. BACK - Introduction 
  106. CONTENTS 
  107.  
  108.  
  109. ΓòÉΓòÉΓòÉ 4. Factors Affecting Portability ΓòÉΓòÉΓòÉ
  110.  
  111. FACTORS AFFECTING PORTABILITY 
  112.  
  113. There are many factors that affect the difficulty of porting code from any 
  114. platform to OS/2. The factors include: 
  115.  
  116.    complexity of the code 
  117.  
  118.    "cleanliness" of the code 
  119.  
  120.    exploited functionality in the source platform 
  121.  
  122.    use of third-party libraries 
  123.  
  124.    abstractness of the design 
  125.  
  126.    tools being used 
  127.  
  128.    experience level of the programmers porting the code. 
  129.  
  130. Most applications have evolved over several years and have been worked on by 
  131. programmers of various levels of experience. The result is usually an 
  132. application with many blocks of code which have similar functionality but use a 
  133. completely different set of API calls. While programming standards may be in 
  134. place now the standards most likely have changed over the years and the 
  135. strictness to which programmers stick to those standards is questionable at 
  136. times. 
  137.  
  138. Many Windows applications also get away with using memory and object handles 
  139. after they have been released.  This will cause a problem when the code is 
  140. ported to the protected memory environment of OS/2.  A good guide for helping 
  141. to identify such a problem is to run your application using the debug version 
  142. of Windows. 
  143.  
  144. The use of third-party libraries in an application makes it extremely difficult 
  145. to port your application to OS/2 or any other platform.  The future portability 
  146. of the application is dependent upon the owner of the library providing a 
  147. version for each platform.  If there was one item which is recommended when 
  148. designing an application it would be to try to use abstract design techniques. 
  149.  
  150. Whenever a system level, third-party library, or operating system dependent 
  151. function is required it should be given a functional name and placed into 
  152. either a separate source file or library. 
  153.  
  154. For example, instead of calling GlobalAlloc every time that memory is allocated 
  155. create a function called AllocateMemory.  This will centralize the porting 
  156. activity to the single function and will enable the main logic of the 
  157. application to remain mostly intact during the porting process. 
  158.  
  159. CONTINUE - Designing code for Portability 
  160. BACK - Basics 
  161. CONTENTS 
  162.  
  163.  
  164. ΓòÉΓòÉΓòÉ 5. Designing Code for Portability ΓòÉΓòÉΓòÉ
  165.  
  166. DESIGNING CODE FOR PORTABILITY 
  167.  
  168. Most applications are designed with a single operating system platform in mind. 
  169. Designing applications which can be ported to run on multiple  platforms 
  170. requires a little more forethought and understanding of the target platforms. 
  171. The key to designing an application for portability lies in abstracting the 
  172. various platform functionality that is required by the application. 
  173.  
  174. For example, memory management functions differ from one platform to another. 
  175. However, the basic functionality of allocating and freeing memory is the same. 
  176.  
  177. By abstracting this type of functionality into individual modules or components 
  178. the process of porting simplifies to replacing these abstract modules. The core 
  179. functionality of your application remains the same. 
  180.  
  181. There will certainly be some functionality of a platform that you will want to 
  182. exploit in your application. Multiple threads or long filenames may be 
  183. something that you want to take advantage of in OS/2. Since this kind of 
  184. functionality may not exist on another platform it is recommended that you 
  185. place any exploitive functionality into a separate module. 
  186.  
  187. You will want to provide a function which checks the platform and indicates 
  188. which of the exploitive features are supported on the current platform.  That 
  189. way the application can provide an alternate path of execution if the support 
  190. is not available. 
  191.  
  192. The operating system services provide the necessary functionality to make your 
  193. application work on a specific platform. By separating the core logic from the 
  194. operating system services the changes are reduced to the modules which 
  195. implement the abstracted functionality. 
  196.  
  197. Remember that the proprietary logic in your application is what differentiates 
  198. your application from other applications. 
  199.  
  200. The following list identifies several items which should be abstracted in your 
  201. application design to make platform portability easier. Keep in mind that all 
  202. of these recommendations are for the purpose of minimizing the  number of 
  203. changes required to port your application to another platform. 
  204.  
  205.  1. Eliminate datatype dependencies. 
  206.  
  207.     Wherever possible define macros for declaring datatypes and for accessing 
  208.     portions of the datatype. If a variable is to contain more than one piece 
  209.     of data (e.g., packing two words into a double-word variable) define macros 
  210.     which pack and unpack the data. 
  211.  
  212.     Use the "sizeof" directive to determine size and offset of datatypes. 
  213.  
  214.  2. Use "message crackers" for accessing message parameters. 
  215.  
  216.     Define macros which return the message parameter value that is being 
  217.     referenced. The format of messages differs between platforms.  Using macros 
  218.     to return the requested message parameter value allows you to modify the 
  219.     macro for the ported platform and affect the change throughout the code. 
  220.  
  221.  3. Use "message forwarding" macros for sending and posting messages. 
  222.  
  223.     Define macros which format and send or post messages to a window. The 
  224.     format and identity messages differs between platforms. Using macros to 
  225.     format parameter values allows you to modify the macro for the ported 
  226.     platform and affect the change throughout the code. 
  227.  
  228.  4. Abstract the memory-management functions into a separate module. 
  229.  
  230.     Define a set of functions for allocating, reallocating, locking, unlocking, 
  231.     freeing, and querying memory. 
  232.  
  233.  5. Abstract the file input/output functions into a separate module. 
  234.  
  235.     Define a set of functions for opening, reading, writing, closing, and 
  236.     querying files and directories. Include functions for searching, moving, 
  237.     renaming, deleting, and copying files.  Also include file name parsing 
  238.     functions in the module. 
  239.  
  240.  6. Abstract the setting of graphics attributes into a separate module. 
  241.  
  242.     Define a set of functions for setting and querying line, fill, bitmap, and 
  243.     font attributes. This includes color, style, and pattern attributes.  Also 
  244.     abstract the creation, retrieving, and deletion of drawing areas (i.e., 
  245.     device-context or presentation space). 
  246.  
  247.  7. Abstract coordinate calculations functions into macros or functions. 
  248.  
  249.     Coordinate systems can differ across platforms. Define a set of macros or 
  250.     functions for calculating vertical coordinates for graphics primitives. 
  251.     For example, define a function called "MoveDown" for calculating a 
  252.     y-coordinate which is positioned a specified distance below another 
  253.     coordinate. 
  254.  
  255.  8. Abstract graphic primitive functions into a separate module. 
  256.  
  257.     Define a set of functions for performing the graphic drawing capabilities 
  258.     required for your application.  For example, define functions called 
  259.     "DrawFilledRect" and "DrawPie" to draw a rectangle which is filled with a 
  260.     brush or pattern and to draw a closed arc. 
  261.  
  262. CONTINUE - Windows Issues 
  263. BACK - Factors Affecting Portability 
  264. CONTENTS 
  265.  
  266.  
  267. ΓòÉΓòÉΓòÉ 6. Windows Issues ΓòÉΓòÉΓòÉ
  268.  
  269. WINDOWS TO OS/2 IMPLEMENTATION ISSUES 
  270.  
  271. There are approximately 4700 points of difference between Windows (3.1) and 
  272. OS/2 and this doesn't even cover the changes required for conversion from 
  273. 16-bit to 32-bit code or the use of third-party libraries. It is even more 
  274. amazing to realize that there are over 14,000 points of difference between 
  275. Win32 and OS/2 2.1. 
  276.  
  277. It is not appropriate to list all of these items here. However, there are a 
  278. number of functional areas found in common with most applications which cause 
  279. the most amount of difficulty and effort in the porting process. While many of 
  280. the areas have what appear to be simple solutions the practical aspect of it is 
  281. that they can cause either a lot of rework or redesign to integrate properly 
  282. into the ported code. 
  283.  
  284.    Resource files must be converted from Windows to OS/2 format. 
  285.  
  286.    Dialog units in Windows are calculated based on the font used in the dialog 
  287. while dialog units in OS/2 are calculated based on default system proportional 
  288. font. 
  289.  
  290.    Font names and selections must be converted to those available in OS/2. 
  291.  
  292.    Menus for dialogs must be defined at run-time and not in the resource file. 
  293.  
  294.    Icons, cursors, and bitmaps must be converted to an OS/2 recognized format. 
  295.  
  296.    Multiple Document Interface (MDI) must be implemented in the application. 
  297.  
  298.    The frame window, frame control windows, and client windows are all 
  299. separate windows in OS/2. Subclassing must be performed in OS/2 to monitor and 
  300. process non-client window activity. 
  301.  
  302.    Windows brushes and pens must be converted to area and line bundle 
  303. attributes. Different OS/2 functions are used for drawing filled and non-filled 
  304. objects as well as drawing a nominal width line versus a wide line. 
  305.  
  306.    APIs for drawing an arc, chord, pie, etc. require several function calls in 
  307. OS/2. 
  308.  
  309.    The OS/2 coordinate system is lower-left origin versus Windows upper-left 
  310. origin. All coordinate calculations for positioning windows and drawing must be 
  311. converted to be relative to the lower-left corner. If window positions are to 
  312. remain relative to the upper-left corner when a parent window is re-sized code 
  313. must be added to reposition child windows. 
  314.  
  315.    The CS_CLASSDC class style is not supported in OS/2. 
  316.  
  317.    Regions are bottom-right exclusive in Windows and top-right exclusive in 
  318. OS/2. 
  319.  
  320.    The bits for monochrome bitmaps in OS/2 are reverse from those of Windows. 
  321.  
  322.    Windows metafiles must be converted to OS/2 metafiles. Metafile enumeration 
  323. is not directly supported in OS/2. 
  324.  
  325.    Applications have less direct control over printing properties in OS/2. 
  326. Applications should use the job properties dialog to allow users to modify the 
  327. printing characteristics. 
  328.  
  329.    Support of tabstops in a listbox is not available in OS/2. Columns are 
  330. supported in OS/2 by using the container class. 
  331.  
  332.    Cursors are not registered with a window class in OS/2. The setting of the 
  333. pointer in OS/2 is performed during the WM_CONTROLPTR or WM_MOUSEMOVE message. 
  334.  
  335.    Background brushes are not registered with a window class in OS/2. A 
  336. background fill color can be set by setting a presentation parameter for the 
  337. window. 
  338.  
  339.    Control activity messages are received in a WM_CONTROL message instead of 
  340. the WM_COMMAND message. 
  341.  
  342.    Processes must explicitly gain access to shared memory and all processes 
  343. having access to shared memory must free it before the memory is freed. This 
  344. differs from Windows where the shared memory is freed when the creator of the 
  345. memory frees it. 
  346.  
  347.    Memory and window classes allocated and registered by a DLL are not 
  348. available to other processes. In Windows the ownership of window classes and 
  349. memory objects is based on the code-segment which registered the class or 
  350. allocated the memory. In OS/2 all resources, classes, and memory objects are 
  351. owned by the process that allocated or registered them. 
  352.  
  353.    OLE is not supported in OS/2. 
  354.  
  355.    There is not a Color or Print common dialog in OS/2. The options available 
  356. for the font and file common dialog differ from Windows. 
  357.  
  358. CONTINUE - Windows Functionality Not Supported 
  359. BACK - Designing code for Portability 
  360. CONTENTS 
  361.  
  362.  
  363. ΓòÉΓòÉΓòÉ 7. Windows Functionality Not Supported ΓòÉΓòÉΓòÉ
  364.  
  365. WINDOWS 3.1 FUNCTIONALITY NOT SUPPORTED IN OS/2 2.1 
  366.  
  367. The following categories of APIs or functionality are not directly supported in 
  368. OS/2. These items require that you either rework the application to implement 
  369. an alternative strategy or remove the functionality from the application to 
  370. successfully port to OS/2. 
  371.  
  372.   OLE - Not available 
  373.   DDEML - Not available 
  374.   MDI - Use MDI library (see SMARTAUX\SMARTMDI\MDI.DOC) 
  375.   DIB driver interface (DIB.DRV) - Not available 
  376.   Direct printer driver interface - Not available 
  377.   Selector-based memory manipulation - Conversion required 
  378.   TrueType Support - Not available 
  379.   Tabs in a listbox - Convert to ownerdraw listboxes 
  380.   Common color dialog - Not available 
  381.   Common find/replace dialog - Not available 
  382.   Window Property APIs - Not available 
  383.   Metafile enumeration APIs - Not available 
  384.   VersionInfo API - Not available 
  385.   LZ Compression API - Not available 
  386.  
  387. CONTINUE - OS/2 Changes 
  388. BACK - Windows Issues 
  389. CONTENTS 
  390.  
  391.  
  392. ΓòÉΓòÉΓòÉ 8. OS/2 Changes ΓòÉΓòÉΓòÉ
  393.  
  394. OS/2 1.3 FUNCTIONALITY SIGNIFICANTLY CHANGED IN OS/2 2.1 
  395.  
  396. The following categories of APIs or functionality have changed significantly 
  397. from 16 bit OS/2 to 32 bit OS/2.  Most of the APIs listed are not available in 
  398. the 32-bit version of OS/2. The semaphore functions have changed in name and 
  399. definition, however the same capabilities are available.  They do require 
  400. changes to any existing semaphores being used. 
  401.  
  402.   Semaphore API conversions - Conversion required 
  403.   DosFindNotifyFirst - Not available 
  404.   DosFindNotifyNext - Not available 
  405.   DosFindNotifyClose - Not available 
  406.   WinMsgSemWait - Not available 
  407.   WinMsgMuxSemWait - Not available 
  408.   WinAvailMem - Not available 
  409.   WinLockHeap - Not available 
  410.   WinCatch  - Not available 
  411.   WinThrow - Not available 
  412.   GpiRealizeColorTable - Not available 
  413.   GpiUnrealizeColorTable - Not available 
  414.   WinInstStartApp - Not available 
  415.   DosPrintJobGetId - Not available 
  416.   DosGetPPID - Not available 
  417.   DosGetPrty - Not available 
  418.   DosReadAsync - Not available 
  419.   DosWriteAsync - Not available 
  420.   WinRegisterWindowDestroy - Not available 
  421.  
  422. CONTINUE - Summary 
  423. BACK - Windows Functionality Not Supported 
  424. CONTENTS 
  425.  
  426.  
  427. ΓòÉΓòÉΓòÉ 9. Summary ΓòÉΓòÉΓòÉ
  428.  
  429. IN SUMMARY 
  430.  
  431. Developing applications that are portable between platforms requires planning 
  432. and development adherence to techniques of functional encapsulation and 
  433. isolation. Knowledge of the platform dependence of the source and targeted 
  434. platforms helps to identify the functions that are best isolated into 
  435. convenient, modifiable modules. 
  436.  
  437. RESTART 
  438. BACK - OS/2 Changes 
  439. CONTENTS 
  440.