Wiley.Developing.Software.for.Symbian.OS.2nd.Edition.Dec.2007 (779887), страница 31
Текст из файла (страница 31)
You can specify anew name and location for this file by using the DEFNAME statementin the DLL’s MMP file.The keyword nostrictdef can also be usedin the MMP file to cause the U not to be added to the DEF file name.DLL INTERFACE FREEZING147There is an additional DEF file that is generated on each DLL build, andthis should not be confused with the DEF file discussed above.
This fileis an intermediate file, located in the project’s epoc32\build directory,and always reflects the current interface of the DLL. When interfacefreezing is disabled (EXPORTUNFROZEN in your MMP), the import libraryis generated from this intermediate DEF file.First build of a DLLA typical first set of commands to build a DLL without the EXPORTUNFROZEN statement is as follows:cd <your dll build directory>bldmake bldfilesabld build winscwabld freeze winscwabld build winscwDoesn’t it seem strange to run abld build winscw twice? Actually,what is happening is that the first abld build command will successfullybuild the DLL, but will not build an import library since the interfaceis not frozen.
Executing the abld freeze command will examine theinterface of the DLL just built and freeze it (by recording the interfacein a DEF file, as we will see). The next abld build command willsuccessfully generate the import library corresponding to the DLL.You could substitute abld library winscw in place of the last abldbuild winscw command.
This command builds the import library fromthe DEF file just created by the abld freeze winscw command. Theabld build command does this, but it also does a complete DLL build.Now the DLL can be updated as needed and rebuilt. This DLL will bebackward compatible with the last frozen interface and thus will workwith those older frozen import libraries.Sample DEF fileTo illustrate the concept of library freezing a bit further, let’s look at aquick example of a DLL and the .DEF file it generates when the library isfrozen. I used the GCCE native build target for this example.
The followingshows the source code for a sample DLL:// mydll.h#include <e32base.h>class CMyClass : public CBase{public:static CMyClass *NewL();IMPORT_C void FuncA();148IMPORT_CIMPORT_CIMPORT_CIMPORT_Cprotected:IMPORT_C};SYMBIAN OS BUILD ENVIRONMENTvoidvoidvoidvoidFuncB();FuncC();FuncD();FuncE();CMyClass(void);// mydll.cpp#include "mydll.h"EXPORT_C CMyClass *CMyClass::NewL(){return new(ELeave) CMyClass;}CMyClass::CMyClass(){// constructor code here }EXPORT_C void CMyClass::FuncA(){// FuncA code }EXPORT_C void CMyClass::FuncB(){// FuncB code }EXPORT_C void CMyClass::FuncC(){// FuncC code }EXPORT_C void CMyClass::FuncD(){// FuncD code }EXPORT_C void CMyClass::FuncE(){// FuncE code }The listing below shows a sample DEF file generated (by abld freezegcce) for this sample DLL:EXPORTS_ZN8CMyClass4NewLEv @ 1 NONAME_ZN8CMyClass5FuncAEv @ 2 NONAME_ZN8CMyClass5FuncBEv @ 3 NONAME_ZN8CMyClass5FuncCEv @ 4 NONAME_ZN8CMyClass5FuncDEv @ 5 NONAME_ZN8CMyClass5FuncEEv @ 6 NONAMEThe static MyClass::NewL() method is assigned ordinal 1, and functions FuncA() through FuncE() are assigned ordinals 2 through 6 (youcan ignore the characters surrounding the function name).Inserting a new functionIn the example just discussed, suppose you insert a new class method, sayFuncC1(), after FuncC().
If freezing were disabled, the ordinals couldchange in the next build (thus breaking compatibility for applicationsINSTALLING APPLICATIONS ON THE SMARTPHONE149using the older library); however, since the DLL is frozen, you can beassured that the ordinals for the existing functions will remain the sameand FuncC1() will receive the next-higher ordinal (7).
Note that thefrozen import libraries will not have access to this new function yet (youneed to refreeze and release a new import library to use it), but at leastthe other functions will still work correctly.Interface violationLet’s consider what would happen if you froze the example DLL, andthen removed one of the methods (FuncA(), for example). The next timeyou built the DLL, you’d see an error such as the following (again, usingGCCE, the error may differ with other build targets):elf2e32 : Error: E1036: Symbol _ZN8CMyClass7FuncAEv Missing from ELF FileThe reason is that backward compatibility would be broken, since existingapplications may depend on the function you deleted.
To delete thismethod you would need to unfreeze the DLL, and rebuild – and thenfreezing back again to create a new import library to correspond with thenew version of the DLL.Unfreezing a DLLIn some cases you will have frozen the DLL (without releasing it) and thenwant to rearrange things, by either renaming methods or deleting them.You will not be able to build, however, since it will violate the interfacesand you will get errors such as the one just discussed.
To reset, unfreezeyour interface by deleting your project’s DEF file. Then run abld build,abld freeze, abld build. This will create a new DEF with the newinterface.5.9 Installing Applications on the SmartphoneAn application is installed on a smartphone via an installation file that hasa .sis or .sisx extension.
This installation file, which is referred to asa SIS file, contains all the executables and data files for the application. Inaddition, it contains installation information, such as where to put eachexecutable/data file on the target device’s flash memory.You can install a SIS file in several ways:•Using PC suite on the PC.•You can simply click on the SIS file in File Explorer and it will installitself on the smartphone.150SYMBIAN OS BUILD ENVIRONMENT•Download SIS files from the web, WAP, or via email onto thesmartphone itself and install them.•Beam the SIS file to the phone using infrared or Bluetooth technology.The smartphone keeps track of all installed programs, and allowsthe user to uninstall them.
The information from the SIS file is used todetermine which files to delete.To create a SIS file for your program, Symbian provides a tool calledmakesis. The makesis tool takes a package definition file (known as aPKG file.) as input. This is simply a text file that specifies what files areincluded in the package (and their location on the PC) and where thesefiles go on the smartphone. Running makesis with the argument set tothe name of the PKG file will generate the SIS file – ready for installation.Figure 5.3 shows the operation of makesis.5.9.1 Where Do I Put My Files?Let’s look at the key directories on the smartphone device.
The directorystructures differ somewhat between phones, but the ones listed here areconsistent across all devices.Project executables and data filesPKG filemakesis commandSIS fileSIS file signingSmartphoneFigure 5.3makesis FlowINSTALLING APPLICATIONS ON THE SMARTPHONE151• \sys\binThis is where all executables on the phone reside (i.e., all EXE filesand shared libraries). An executable cannot be started if it is not inthis directory.Note that before Symbian OS v9, each application had its ownapplication subdirectory; this is no longer the case. Therefore, youneed to be sure your executable names are unique across all applications. For example, if you name an executable application.exeyou may have a conflict with some other application that has anexecutable with that name.
One way to ensure uniqueness is toappend the UID3 of your executable to its name. Carbide.c++ doesthis automatically when creating applications using its wizard.• \resource\appsThis is where all compiled application resource files are put.• \privateThe \private directory contains reserved, secure subdirectories forstoring data for applications. The subdirectory name is the SECUREIDspecified for the application (which defaults to the application UID),as described earlier in section 5.3.2.
See also section 7.4.8 for a fulldescription of this.• \private\10003a3f\import\appsThis is a special directory under private, where application registrationresources reside. We’ll discuss it later, in Chapter 12.5.9.2Format of the PKG FileTo create a SIS file you need to define a PKG file for your project, whichis used to specify the contents of your SIS file. First I will discuss the basicstatements in the package file using a simple illustrative example, then Iwill talk about some of the more advanced features.A minimum PKG file has two lines describing the application and thetarget smartphone device. These lines are followed by one or more linesthat specify what files on the development PC go in the package file, andwhere those files should be placed on the smartphone when the SIS fileis installed.
The following shows the PKG file from Chapter 2:; SimpleEx.pkg - S60;;Language - standard language definitions&EN; standard SIS file header#{"SimpleEx"},(0xE000027F),1,0,0152SYMBIAN OS BUILD ENVIRONMENT;Localised Vendor name%{"Vendor"};Supports S60 v 3.0[0x101F7961], 0, 0, 0, {"S60ProductID"};;Files to install"c:\Symbian\9.2\S60_3rd_FP1\epoc32\release\gcce\urel\SimpleEx.exe"-"!:\sys\bin\SimpleEx.exe""c:\Symbian\9.2\S60_3rd_FP1\epoc32\data\z\resource\apps\SimpleEx.rsc"-"!:\resource\apps\SimpleEx.rsc""c:\Symbian\9.2\S60_3rd_FP1\epoc32\data\z\private\10003a3f\apps\SimpleEx_reg.rsc" -"!:\private\10003a3f\import\apps\SimpleEx_reg.rsc"Package file commentsLines that begin with a semicolon and blank lines are ignored by makesis.Package headerThe package header contains information about the program that you areinstalling. The format is as follows:#{" program name"},{ProgramUID},Major_Version_#,Minor_Version_#,Build_#[,package options] [,Type=Package Type]In the previous example, the package header is:#{"SimpleEx"},(0xE000027F),1,0,0This indicates that the program’s name is SimpleEx, the UID is0xE000027F, and the version is 1.0.0.