source: trunk/doc/Porting.txt@ 8045

Last change on this file since 8045 was 3990, checked in by sandervl, 25 years ago

doc update

File size: 7.9 KB
Line 
1/* $Id: Porting.txt,v 1.2 2000-08-11 10:54:06 sandervl Exp $ */
2
3 Porting Win32 applications to OS/2 using Odin - 991212
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
61.0 Introduction
7----------------
8
9Although Odin's primary goal is to run win32 applications in OS/2 without
10requiring a recompile, it is possible to port Win95/98/NT apps to OS/2
11with minimal effort.
12This is the first draft of this porting guide. If anything is unclear or
13not mentioned, please contact the author (sandervl@xs4all.nl)
14
151.1 Odin32
16-----------
17
18Odin32 is the win32 compatible API provided with the Odin alpha (or daily builds).
19It's consists of hundreds of win32 APIs in several dlls (kernel32, user32, gdi32 etc).
20Keep in mind that Odin is still alpha software, so don't expect all apis to
21work exactly like those in Windows NT.
22If you find bugs, please contact the developers or send an email to the
23Odin programmers mailinglist (win32os2-wai@egroups.com).
24
251.2 Required tools for porting win32 apps to OS/2
26-------------------------------------------------
27- IBM VisualAge C++ 3.08
28- OS/2 Warp 4 Toolkit (project apparently doesn't compile with
29 VAC's OS/2 headers)
30 Might also work with EMX headers. (haven't tried this)
31- ALP 4.0 (IBM Assembly Language Processor)
32 Download the tools zipfile from http://service.boulder.ibm.com/ddk/
33 (you need to register, but it's free)
34
35It should also be possible to use Watcom or EMX to do the job, but you might
36need to make some changes to our headers to make this work.
37
382.0 Porting Win32 applications to OS/2
39--------------------------------------
40In order to port win32 apps a few things have to be done:
41- Change all the makefiles for VAC (or any other OS/2 compiler)
42- Use Wine RC (wrc.exe) to compile the resources
43- Add the Odin executable and/or dll wrapper files to the project
44- Change the source code in case of compile problems
45
462.1 Changing the makefile(s)
47----------------------------
48This will probably be the most time consuming (and boring) part of the port.
49You have to make sure all compiler options are correct for the project and
50make some changes for compiling the resource script. (see 2.2)
51
52To build the ported application, you must link with the necessary Odin libraries
53in your makefile. These libraries (i.e. kernel32.lib, user32.lib etc) are
54built when compiling Odin itself.
55
56Paragraph 2.6 contains a skeleton makefile.
57
582.2 Wine's resource compiler (wrc)
59----------------------------------
60Wrc must be used to compile the resources of the win32 project.
61Unfortunately wrc isn't completely compatible with Microsoft's rc.exe.
62You might need to make some changes to the resource script in order to
63make wrc happy.
64
65Wrc produces an assembly file with the a resource tree and binary resources.
66This resembles the resource section in win32 (PE) executables/dlls.
67This assembly file should be added to the list of objects files in the makefile.
68
692.3 Odin's entrypoint wrappers
70------------------------------
71Kernel32 keeps track of all loaded executables and dlls. The PE loader makes
72sure image objects are created when loading a win32 executable.
73A ported win32 app must do this manually by calling certain kernel32 exports.
74
75In the src\Odin32API directory of the Odin CVS tree, you'll find two wrappers:
76- odinexe.cpp: Executable entrypoint (main)
77- odindll.cpp: Dll entrypoint (_DLL_InitTerm)
78
79The executable wrapper calls RegisterLXExe (exported api in kernel32) to create
80an executable object and tell kernel32 where to find it's win32 entrypoint
81(usually WinMain) and resources.
82The dll version does the same thing. It calls RegisterLXDll to create the dll
83object during a dll load and UnregisterLXDll when the dll is unloaded.
84It's parameters are the dll module handle, the win32 dll entrypoint (LibMain)
85and, again, a pointer to the resource object. (as produced by wrc)
86The resource pointer can be NULL.
87The handle returned by RegisterLxDll must be used when calling UnregisterLxDll.
88
89In the skeleton dll entrypoint we also call ctordtorInit/Term to create/destroy
90and static C++ objects.
91If you don't link with odincrt.lib for the runtime C/C++ functions, you must
92also call CRT_init/CRT_term (before _ctordtorInit, after ctordtorTerm).
93
94After RegisterLXExe/Dll has finished it's job in kernel32, it will
95call the exe/dll entrypoint.
96
972.4 Win32 source code changes
98-----------------------------
99Usually you shouldn't have to make many changes to the existing win32
100source code.
101However, there might be a few differences between the MS SDK and Odin
102headers. If you find such problems, please correct them and notify
103the Odin developers.
104
105Complex applications might be hard to port to OS/2 for several reasons:
106- Compiler differences (i.e. VAC 3.08 doesn't support unnamed unions)
107 VAC 3.6.5 should be a better choice for compiling win32 sources, but
108 it has it's own share of problems (bugs).
109- TLS (thread local storage) data; VAC has no facilities to support this,
110 so this could require a major rewrite.
111 Other compilers (Watcom) may have better support for this.
112 You can recognize this type of data by the __declspec(thread) keyword.
113 Using the TLS apis (i.e. TlsAlloc) is no problem.
114- OLE/COM objects. Wine headers aren't exactly built with C++ in mind,
115 so you'll most likely run into a lot of problems if the app uses
116 these win32 features.
117
1182.5 Exception handling
119----------------------
120
121RegisterLXExe/RegisterLXDll in kernel32 registers an exception handler
122for Odin. This handler is used to support file mappings.
123You must make sure that your code doesn't remove this handler from
124the chain of exception handlers.
125To create a thread, use CreateThread; not _beginthread or DosCreateThread.
126CreateThread takes care of setting up an exception handler, creates TLS
127structures and calls dll entrypoints.
128
1292.6 Sample makefile
130-------------------
131This makefile is used to compile the MS SDK generic sample in OS/2:
132
133PDWIN32_INCLUDE = k:\source\odin32\include
134PDWIN32_LIB = k:\source\odin32\lib
135PDWIN32_BIN = k:\source\odin32\bin
136
137!include $(PDWIN32_INCLUDE)/pdwin32.mk
138
139PROJ = GENERIC
140
141all: $(PROJ).exe
142
143RC = wrc
144RCFLAGS = -s -I. -I$(CPPMAIN)\include -I$(PDWIN32_INCLUDE) -I$(PDWIN32_INCLUDE)\win
145
146# Define project specific macros
147PROJ_OBJS = generic.obj
148BASE_OBJS = resource.obj odinexe.obj
149EXTRA_LIBS = $(PDWIN32_LIB)\version.lib
150GLOBAL_DEP = generic.h resource.h
151RC_DEP = resource.h
152
153
154CFLAGS = -Q -Si -Ti -Tm+ -Ge- -Ss+ -W3 -Gm+ /Gn+ -I$(PDWIN32_INCLUDE)\Win -D__WIN32OS2__ -DDEBUG -D__i386__
155CXXFLAGS = -Q -Si -Ti -Tm+ -Ge- -Ss+ -W3 -Gm+ /Gn+ -I$(PDWIN32_INCLUDE)\Win -D__WIN32OS2__ -DDEBUG -D__i386__
156
157CFLAGS = $(CFLAGS) /Ge+ -I$(PDWIN32_INCLUDE)
158CXXFLAGS = $(CXXFLAGS) /Ge+ -I$(PDWIN32_INCLUDE)
159LDFLAGSEXE = $(LDFLAGS) /Ge+ /B"/pmtype:pm /stack:0x30000 /NOBASE /Map" \
160 $(EXTRA_LIBS) $(PDWIN32_LIB)\kernel32.lib $(PDWIN32_LIB)\user32.lib \
161 $(PDWIN32_LIB)\gdi32.lib os2386.lib $(PDWIN32_LIB)\odincrt.lib $(RTLLIB_O)
162
163resource.obj: resource.asm
164
165# Build rule for resource file
166resource.asm: $(PROJ).rc $(RC_DEP)
167 $(RC) $(RCFLAGS) -o resource.asm $(PROJ).rc
168
169# Build rule for EXE
170$(PROJ).EXE: $(BASE_OBJS) $(PROJ_OBJS) resource.asm
171 $(LD) $(LDFLAGSEXE) -Fe$@ $(PROJ_OBJS) $(BASE_OBJS)
172
173# Build rule for help file
174#$(PROJ).hlp: $(PROJ).rtf $(PROJ).hpj
175# $(hc) generic.hpj
176
177
178# Rules for cleaning out those old files
179clean:
180 del *.bak *.pdb *.obj *.res *.exp *.map *.sbr *.bsc
181
182
1833.0 Project participation
184-------------------------
185
186As ODIN became an open source project, everybody is kindly invited to
187contribute his/her share to the progress of the project. May it be
188active coding, fixing bugs or just providing detailed information about
189examined problems.
190
191We suggest you subscribe to win32os2-wai and the corresponsing mailing lists
192on http://www.egroups.com.
193In case you are interested in participating, every member of the project will
194be happy to give you direction to the right places and to give a personal
195introduction to further development of the particular modules.
196
Note: See TracBrowser for help on using the repository browser.