Talk about porting
I started to use wince, and try to understand the difference between win32 pc platform and the wince mobile platform. In this article I begin to introduce how to refactor your codes in order to make them more reusable and easy porting; first, introduce the general concept and principle; second, I try to take an example to introduce how to porting the win32 pc program into wince (I use Windows Mobile 5 Pocket PC Emulator) program.
The Main concept and principle should be: analyze the code architecture; try split the platform dependent and platform independent code, which contains the “Divide and conquer” philosophy. Try to abstract the platform dependent code into the general INTERFACEs, so that when porting to different platform, you just concern about these INTERFACEs, we just need to implement these INTERFACEs, who can ensure our program work. Note that the platform dependent code could be appeared in the following modules:
a) Graphic rendering mechanism. If it is a tool, or a utility, and which has GUI, then you need to know which UI framework or library to take, if neither, you maybe manage your GUI module with your own code.
b) Sound rendering mechanism, maybe you need encapsulate a module especially for sound rendering, I have known about one portable-audio library called portable cross-platform Audio API, currently its latest version is V19, you can reference this link: http://www.portaudio.com
c) Interactive things, such as key, mouse event, etc
d) Assembly code rewrite if platform’s CPU instruction set is un-compatible
e) Task/Thread related Interface should be taken care if you want to move you code to a different platform. Task or thread is tightly related with the OS of the platform, but if you want to make the program more reusable to other platform, you could pay more attention to this area, or simply, you can write an OS-Independent Wrapper, maybe you know RTP (Real-time Transport Protocol), and there is a good RTP implementation (Compatible with RFC 3550) called jrtplib, the author is Jori Liesenborgs, who encapsulates the Win32 thread mode and Linux/Unix’s pThread mode into the JThread, which is just a wrapper, simple but effective, anyway, almost erveryone like simple things.
(To be cont...)