source: trunk/doc/Porting.txt@ 3921

Last change on this file since 3921 was 3811, checked in by phaller, 25 years ago

.

File size: 7.8 KB
Line 
1/* $Id: Porting.txt,v 1.1 2000-07-09 22:27:54 phaller 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.
87
88In the skeleton dll entrypoint we also call ctordtorInit/Term to create/destroy
89and static C++ objects.
90If you don't link with odincrt.lib for the runtime C/C++ functions, you must
91also call CRT_init/CRT_term (before _ctordtorInit, after ctordtorTerm).
92
93After RegisterLXExe/Dll has finished it's job in kernel32, it will
94call the exe/dll entrypoint.
95
962.4 Win32 source code changes
97-----------------------------
98Usually you shouldn't have to make many changes to the existing win32
99source code.
100However, there might be a few differences between the MS SDK and Odin
101headers. If you find such problems, please correct them and notify
102the Odin developers.
103
104Complex applications might be hard to port to OS/2 for several reasons:
105- Compiler differences (i.e. VAC 3.08 doesn't support unnamed unions)
106 VAC 3.6.5 should be a better choice for compiling win32 sources, but
107 it has it's own share of problems (bugs).
108- TLS (thread local storage) data; VAC has no facilities to support this,
109 so this could require a major rewrite.
110 Other compilers (Watcom) may have better support for this.
111 You can recognize this type of data by the __declspec(thread) keyword.
112 Using the TLS apis (i.e. TlsAlloc) is no problem.
113- OLE/COM objects. Wine headers aren't exactly built with C++ in mind,
114 so you'll most likely run into a lot of problems if the app uses
115 these win32 features.
116
1172.5 Exception handling
118----------------------
119
120RegisterLXExe/RegisterLXDll in kernel32 registers an exception handler
121for Odin. This handler is used to support file mappings.
122You must make sure that your code doesn't remove this handler from
123the chain of exception handlers.
124To create a thread, use CreateThread; not _beginthread or DosCreateThread.
125CreateThread takes care of setting up an exception handler, creates TLS
126structures and calls dll entrypoints.
127
1282.6 Sample makefile
129-------------------
130This makefile is used to compile the MS SDK generic sample in OS/2:
131
132PDWIN32_INCLUDE = k:\source\odin32\include
133PDWIN32_LIB = k:\source\odin32\lib
134PDWIN32_BIN = k:\source\odin32\bin
135
136!include $(PDWIN32_INCLUDE)/pdwin32.mk
137
138PROJ = GENERIC
139
140all: $(PROJ).exe
141
142RC = wrc
143RCFLAGS = -s -I. -I$(CPPMAIN)\include -I$(PDWIN32_INCLUDE) -I$(PDWIN32_INCLUDE)\win
144
145# Define project specific macros
146PROJ_OBJS = generic.obj
147BASE_OBJS = resource.obj odinexe.obj
148EXTRA_LIBS = $(PDWIN32_LIB)\version.lib
149GLOBAL_DEP = generic.h resource.h
150RC_DEP = resource.h
151
152
153CFLAGS = -Q -Si -Ti -Tm+ -Ge- -Ss+ -W3 -Gm+ /Gn+ -I$(PDWIN32_INCLUDE)\Win -D__WIN32OS2__ -DDEBUG -D__i386__
154CXXFLAGS = -Q -Si -Ti -Tm+ -Ge- -Ss+ -W3 -Gm+ /Gn+ -I$(PDWIN32_INCLUDE)\Win -D__WIN32OS2__ -DDEBUG -D__i386__
155
156CFLAGS = $(CFLAGS) /Ge+ -I$(PDWIN32_INCLUDE)
157CXXFLAGS = $(CXXFLAGS) /Ge+ -I$(PDWIN32_INCLUDE)
158LDFLAGSEXE = $(LDFLAGS) /Ge+ /B"/pmtype:pm /stack:0x30000 /NOBASE /Map" \
159 $(EXTRA_LIBS) $(PDWIN32_LIB)\kernel32.lib $(PDWIN32_LIB)\user32.lib \
160 $(PDWIN32_LIB)\gdi32.lib os2386.lib $(PDWIN32_LIB)\odincrt.lib $(RTLLIB_O)
161
162resource.obj: resource.asm
163
164# Build rule for resource file
165resource.asm: $(PROJ).rc $(RC_DEP)
166 $(RC) $(RCFLAGS) -o resource.asm $(PROJ).rc
167
168# Build rule for EXE
169$(PROJ).EXE: $(BASE_OBJS) $(PROJ_OBJS) resource.asm
170 $(LD) $(LDFLAGSEXE) -Fe$@ $(PROJ_OBJS) $(BASE_OBJS)
171
172# Build rule for help file
173#$(PROJ).hlp: $(PROJ).rtf $(PROJ).hpj
174# $(hc) generic.hpj
175
176
177# Rules for cleaning out those old files
178clean:
179 del *.bak *.pdb *.obj *.res *.exp *.map *.sbr *.bsc
180
181
1823.0 Project participation
183-------------------------
184
185As ODIN became an open source project, everybody is kindly invited to
186contribute his/her share to the progress of the project. May it be
187active coding, fixing bugs or just providing detailed information about
188examined problems.
189
190We suggest you subscribe to win32os2-wai and the corresponsing mailing lists
191on http://www.egroups.com.
192In case you are interested in participating, every member of the project will
193be happy to give you direction to the right places and to give a personal
194introduction to further development of the particular modules.
195
Note: See TracBrowser for help on using the repository browser.