I recently wrote an article about modifying the behavior of KernelIoControl when called by User Mode code. In that article, I stated that you need to clone the Public oemioctl code to your platform. Sounds so simple doesn’t it, and really it isn’t that difficult if you know what you are doing, but for the rest of you I thought that I would walk through the process of cloning code.
Many of us use the term “clone code” but what does it really mean? Cloning code means to copy the code to another build tree and modify the build environment to build the code under the new tree. In the old days of Windows CE development, that meant reverse engineering how Microsoft builds the code to apply your knowledge of the build system to it. Today we have sysgen_capture.bat to do most of the hard work for us.
Here is how I would clone oemioctl:
1.       Create a new folder in my platform to build oemoctl.dll, I will call mine OALIoctlDir. This folder will be a holding place for two new folders; one will build the lib that is built in Public\Common\OAK\oalioctl, and the other will link the lib to create the dll. You certainly can create the dll with one folder, but that is more involved that the discussion here.
2.       Copy the %_WINCEROOT%\Public\Common\OAK\OALIOCTLfolder and paste it as a new subfolder of OALIoctlDir. This is the folder that creates OALIoctl.lib.
3.       Create an new folder in OALIoctlDir named BuildDll; this is the folder that will do the linking to create OALIoctl.dll.
4.       Create a dirs file OALIoctlDir that contains

DIRS=oalioctl BuildDll
This tells build to go into OALIoctl first to build the lib, then go to BuildDll to link the dll.
5.       Add OEMIocltDir to its parent folder’s dirs file, which tells build to build our clone of OALIoctl.dll.
6.       Modify OALIoctlDir\OALIoctl\sources to:
             a.  Add RELEASETYPE=PLATFORM, this tells build to put the lib in the platform build tree
             b.  Change the TARGETNAME to oalioctl_lib
             c.  Remove WINCETARGETFILE0=$(_COMMONOAKROOT)\lib\$(_CPUINDPATH)\$(DEFFILE)
7.       Open a build window and change directories to OALIocltDir\BuildDll
8.       Run “sysgen_capture OALIoctl” which will create a file named sources.OALIoctl. This new file contains the information that Microsoft uses to link OALIoctl.lib to create OALIoctl.dll, we need that information to build.
9.       Rename souces.OALIoctl to sources, so that build.exe can use it.
10.   Modify OALIoctlDir\BuildDll\sources to
a.       change    $(_PUBLICROOT)\common\oak\lib\$(_CPUINDPATH)\OALIoctl.lib to    $(_TARGETPLATROOT)\lib\$(_CPUINDPATH)\OALIoctl_lib.lib
b.      Change the DEFFILE to DEFFILE=OALIoctl.def
11.   Copy OALIoctl.def from OALIoctlDir\oalioclt to OALIoctlDir\BuildDll, this is necessary so that when BuildDll is built it can find the def file. There are alternative solutions for this, but this one is easy.
12.   Copy a makefile from one another folder to BuildDll, this is necessary because build.exe needs the makefile when it calls nmake.
13.   Change directories to OALIocltDir and run build
14.   Now you have an OALIoctl.dll in your Platform’s Target folder. When you run buildrel, this OALIoctl.dll will overwrite the one created in the Public folder.
Now you have a clone of OALIoctl that you can modify to suit the needs of your platform.
Copyright © 2008 – Bruce Eitman
All Rights Reserved