bambooflow Note

doExampleL

最終更新:

bambooflow

- view
メンバー限定 登録/ログイン

doExampleL


勉強は、まずはコンソールアプリから始めればよさそう。
CommonFramwork.hを使えば簡単みたい。

使用するときはeuser.libライブラリが必要。

  • .mmpファイル参照(抜粋)
SYSTEMINCLUDE   \epoc32\include
 ・・・
LIBRARY euser.lib


  • HelloWorld.cpp

  1. #include "CommonFramework.h"
  2.  
  3. // do the example
  4. LOCAL_C void doExampleL()
  5. {
  6. _LIT(KHelloWorldText,"Hello world!\n");
  7. console->Printf(KHelloWorldText);
  8. }
  9.  

  • CommonFramework.h

  1. #ifndef __CommonFramework_H
  2. #define __CommonFramework_H
  3.  
  4. #include <e32base.h>
  5. #include <e32cons.h>
  6.  
  7. _LIT(KTxtEPOC32EX,"EXAMPLES");
  8. _LIT(KTxtExampleCode,"Symbian OS Example Code");
  9. _LIT(KFormatFailed,"failed: leave code=%d");
  10. _LIT(KTxtOK,"ok");
  11. _LIT(KTxtPressAnyKey," [press any key]");
  12.  
  13. // public
  14. LOCAL_D CConsoleBase* console; // write all your messages to this
  15. LOCAL_C void doExampleL(); // code this function for the real example
  16.  
  17. // private
  18. LOCAL_C void callExampleL(); // initialize with cleanup stack, then do example
  19.  
  20. GLDEF_C TInt E32Main() // main function called by E32
  21. {
  22. __UHEAP_MARK;
  23. CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
  24. TRAPD(error,callExampleL()); // more initialization, then do example
  25. __ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error));
  26. delete cleanup; // destroy clean-up stack
  27. __UHEAP_MARKEND;
  28. return 0; // and return
  29. }
  30.  
  31. LOCAL_C void callExampleL() // initialize and call example code under cleanup stack
  32. {
  33. console=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen));
  34. CleanupStack::PushL(console);
  35. TRAPD(error,doExampleL()); // perform example function
  36. if (error)
  37. console->Printf(KFormatFailed, error);
  38. else
  39. console->Printf(KTxtOK);
  40. console->Printf(KTxtPressAnyKey);
  41. console->Getch(); // get and ignore character
  42. CleanupStack::PopAndDestroy(); // close console
  43. }
  44.  
  45. #endif
  46.  



説明


  • E32Main
エントリポイント。
Cでいうところのmain関数にあたる。
プログラムはここから実行が開始される。


  • __UHEAP_MARK & __UHEAP_MARKENDマクロ
__UHEAP_MARK マクロで始まるコードのセクション内で割り当てられたヒープ領域が、__UHEAP_MARKEND マクロに到達したときに、すべて削除されているかどうかをテストする。
未削除の割り当てがあると__UHEAP_MARKENDでエラーメッセージが出てパニックとなる。
マクロはネストすることも可能。
__UHEAP_CHECKALL、やコード内マーク部分では__UHEAP_CHECKで値を指定したヒープメモリのテストもできる。
デバッグビルド時のみ定義が有効。

  • CTrapCleanup::New()
クリーンナップスタックを生成する。

  • __ASSERT_ALWAYSマクロ
__ASSERT_ALWAYS (c, p) (void)((c)||(p,0))
アサート。すべてのビルドで有効。
__ASSERT_DEBUGはデバッグ時のみ有効。

  • TRAPD (_r, _s)マクロ
トラップハーネスの下で指定したステートメントを実行する。
_rにあるUser::Leave() の結果を_rが受け取る。
トラップハーネス内で本体処理が行われている。

参考

以下を参考にして、

タグ:

s60 e32
記事メニュー
ウィキ募集バナー