03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

public: IMPORT_C TInt CreateLocal();<br />

IMPORT_C void Cancel();<br />

IMPORT_C void After(TRequestStatus& aStatus,<br />

TTimeIntervalMicroSeconds32 anInterval);<br />

IMPORT_C void At(TRequestStatus& aStatus,<br />

const TTime& aTime);<br />

IMPORT_C void Lock(TRequestStatus& aStatus,<br />

TTimerLockSpec aLock);<br />

};<br />

The IMPORT_C macro says that the function must be imported from a DLL by the user of<br />

that API. In the corresponding implementation, the function will be marked EXPORT_C, which<br />

means that it will be exported from the DLL. A function without IMPORT_C is not exported<br />

from its DLL and cannot, therefore, be part of the public API.<br />

These macros are defined in e32def.h. Their implementations are compiler-dependent and<br />

differ between CodeWarrior and GCC.<br />

Virtual and inline functions don't need to be exported – they form a part of the API, even<br />

without IMPORT_C in the header file.<br />

If you're writing an API to be delivered in a DLL for use by other DLLs, you'll need to mark<br />

your IMPORT_Cs and EXPORT_Cs carefully.<br />

If you're not writing APIs – or you're not encapsulating them in DLLs for export – then you<br />

needn't worry about how to use IMPORT_C and EXPORT_C. It's enough to understand what<br />

they mean in Symbian OS SDK headers.<br />

3.4.4 Virtual Functions and APIs<br />

C++ isn't well designed for API delivery. There is no way to prevent further override of a<br />

specific virtual function, and there is no way to guarantee that a function is not virtual without<br />

looking down all the base classes to check for the virtual keyword. You can simulate<br />

Java's final at the class level though, by making the constructor private.<br />

C++'s access control specifiers aren't good for API delivery either. The meaning of public<br />

is clear enough, but protected makes a distinction between derived classes and other<br />

classes that doesn't put the boundary in the right place, since derivation is by no means the<br />

most important vehicle for code reuse in OO. private is not private when it comes to virtual<br />

functions: you can override private virtual functions whether or not this was intended by the<br />

designer of an intermediate class (derived from a base class).<br />

C++ has no language support for packaging APIs except classes and header files. So<br />

Symbian had to invent its own rules for DLLs.<br />

These design issues are most awkward when it comes to virtual functions. Best practice in<br />

Symbian OS C++ includes the following guidelines:<br />

� Declare a function virtual in the base class and in any derived class from which it is<br />

intended to further derive and override (or implement) this function.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!