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.

eturn KErrNone;<br />

}<br />

Important<br />

You must code the prototype of NewApplication() exactly as<br />

shown, otherwise the C++ name mangling will be different from that<br />

expected by the build tools' first ordinal export specification, and your<br />

application won't link correctly.<br />

My NewApplication() function returns my own application class, after first-phase<br />

construction. In the rather unlikely event that there isn't enough memory to allocate and C++construct<br />

a CHelloGuiApplication object, NewApplication() will return a null pointer<br />

and the application architecture loader will handle cleanup.<br />

Note in passing that all Symbian OS DLLs must also code an E32Dll()function that ought<br />

to do nothing, as mine does above.<br />

Note<br />

If it exists to do nothing, why is the function there and why does it take a<br />

parameter? In Windows terminology, this function is the DLL entry point, and<br />

it's called when the DLL is attached to or detached from a process or thread<br />

– at least, that's the theory, and we thought that would be useful for<br />

allocating DLL-specific data in the early days of Symbian OS development.<br />

The application<br />

In practice, however, it isn't called symmetrically in Windows, so it doesn't<br />

work under the emulator, and therefore, is pretty useless for Symbian OS<br />

development. Furthermore, different versions of Symbian OS call E32Dll() a<br />

differing number of times and in slightly different circumstances, which are<br />

further reasons not to use this function to do any real work in your<br />

application. Calls to this function are likely to be withdrawn in future versions<br />

of Symbian OS.<br />

If you need to allocate DLL-specific memory, use the thread- local storage<br />

functions Dll::Tls() and Dll::SetTls(): call them from your main<br />

class' C++ constructor and destructor, and point to your class rather than<br />

some other ad hoc global variable structure. See <strong>Chapter</strong> 8 and<br />

\release\generic\app-framework\cone\src\coemain.cpp (along with<br />

\release\ generic\app-framework\cone\src\coetls.h) in the SDK for<br />

an example.<br />

Assuming that NewApplication() returned an application, the architecture then calls<br />

AppDllUid() to provide another check on the identity of the application DLL. That's all it<br />

needs to know about the application. It then calls CreateDocumentL(), which the<br />

application uses to create a default document. Both of these are virtual functions that I<br />

implement in my derived application class.<br />

The definition of CHelloGuiApplication in HelloGui_Application.h is as follows:<br />

class CHelloGuiApplication : public CQikApplication<br />

{<br />

private: // Inherited from class CApaApplication<br />

CApaDocument* CreateDocumentL();<br />

TUid AppDllUid() const;<br />

};

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

Saved successfully!

Ooh no, something went wrong!