2013年11月24日 星期日

WHQL

沒有通過認證的device driver似乎是不能使用

2013年11月18日 星期一

自己寫Driver Installer

1. 要先有Driver的inf, cat, sys檔案

2. 可以使用很多付費工具像是Advanced Installer, installshield, Wise Package Studio之類的
     或者可以使用Wix, Visual Studio等等

3. 大部分的人都喜歡使用Wix,而且有官方教學Wix Tutorial

4. 或者使用visual studio建立setup project產生msi檔案
再利用Orca去做修改Install usb device

但我自己是使用Visual Studio 2005寫一個安裝driver程式產生exe 设计驱动安装程序
最後再讓msi去執行

5. 很多人說可以使用Driver Install Frameworks (DIFx), Device Console (devcon), SetupAPI等等
但都是說說沒有例子

最後,
1)
我決定寫一個安裝driver的執行程式exe檔案

使用的是setupapi 但要注意 setupapi.h和setupapi.lib該如何使用

首先在程式裡面使用SetupCopyOEMInf,這個程式會安裝inf檔案到windows系統內

第二,需要安裝device,使用UpdateDriverForPlugAndPlayDevices

2)
解除安裝一樣要分inf與device

所以要先使用SetupUninstallOEMInf

再來使用SetupDiRemoveDevice去解除安裝device 可以參考如何自動移除驅動程式

另外,可以使用CM_Locate_DevNode, CM_Reenumerate_DevNode去掃描安裝完成的Driver

3)
使用visual studio建立setup project

建立custom action去執行exe檔
可參考
Custom Action in Visual Studio setup projects
Launching Your Application After Install using Visual Studio 2005

但我的執行程式再安裝的時候怎麼都執行不起來

所以我在msi安裝完成後才執行程式 可參考Run exe after msi installation

最後,我需要判斷我的電腦是64bit或32bit可參考Getting Processor architecture in x86 and x64 bit platform.









2013年11月4日 星期一

Windows Hardware Quality Lab - WHQL認證Driver

WHQL功能: 自己查

官方網站: http://msdn.microsoft.com/zh-TW/windows/hardware/

目的: 測手機的Driver通過WHQL

我的環境:

1. Android Phone

2. Server Computer: Windows Server 2008 R2

3. Test Computer: Windows 7 x64

首先,要知道我們要測什麼東西,需要什麼環境,可參考 Certification Kit Support Matrix

基本上沒有人在使用WLK1.6了,除非特殊情況,windows好像也要收起來了

所以一般來說都會使用Windows HCK

先去Windows Hardware Certification Kit (HCK) downloads 把WHCK download下來

然後按照Windows hardware certification: start here步驟走

基本上就沒問題了

以下是我自己的流程

1. 架環境 兩種情況


1)














 2)

以上這兩種是從WLK文件而來,安裝方法基本上更簡單

我是屬於第二種,所以我在server computer安裝HCK直接安裝studio+controller即可

另外test computer使用區域網路連到server computer在\\\HCKInstall\Client\Setup.exe.執行setup即可


2. 申請VeriSign certificate


其步驟
  1. Establish a company
  2. Get a VeriSign certificate
  3. Add a user or migrate an account
  4. Sign legal agreements
  5. Sign in to the hardware dashboard
基本上不用這麼複雜

你只要在官網的左上角進入DASHBOARD即可

你需要一個microsoft帳號,登入後就會出現 Establish a company ...

再來直接點連結purchase..... 去symentec 購買一個認證

需要注意的是,要在安裝HCK STUDIO的電腦申請,而且到申請完成之前都不可以重灌或換電腦,認證會辨別電腦。

照著步驟走
下載
  • Download the Winqual.exe file
download signtool 基本上就是安裝WDK Windows SDK for Windows 7

使用signtool sign winqual.exe再上傳

signtool可以參考signtool.exe

接下來可能需要一個測試認證,可以參考簽署裝置驅動程式套件的步驟

就完成了這個階段

3. 測試Driver


接下來就按照步驟走,就沒問題了 =)

需要注意的是,create project -> configure, create test machine pool, and check client computer is ready -> 接下來選擇測試的機器,可以在左邊直接選擇driver即可,不必整個system都去測試

測試完成之後

把結果跟driver一起打包

進入DASHBOARD

-> create hck submission 填好選項之後送出

大概幾個小時就會有結果

最後進入manager submission ->選擇你的submission之後右下角可以直接下載sign file

sign file 內容就是已經通過whql的driver!!

DONE~





















2013年10月3日 星期四

Youtube music channel

https://www.youtube.com/user/goldddiggaa


Android Tab View

[Android] 建立Tab View的三種方式(上)

第一種,將每個tab的內容寫在同個Activity

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:orientation="vertical" >

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >

            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
            </FrameLayout>
            
        </LinearLayout>
    </TabHost>

</LinearLayout>


public class MainActivity extends TabActivity implements TabContentFactory {


  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TabHost mTabHost = getTabHost();    
        mTabHost.clearAllTabs();

        mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("TAB1").setContent(this));

        mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("TAB2").setContent(this));
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    //getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }

  @Override
  public View createTabContent(String tag) {
    TextView textView = new TextView(this);
    textView.setText("I'm " + tag);
    return textView;

  }

}


第二種,不同tab的內容分別寫在不同的Activity
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("TAB2").setContent(this));
的setContent帶入參數intent即可!

行動是唯一答案

“You may never know what results come of your action, but if you do nothing there will be no result.”
– Mahatma Gandhi, Statesman
「你可能永遠不知道你的行為能帶來什麼結果,但沒有行動就不會有結果。」– 甘地 (政治家)

增加Android emulator速度

ADT中通过Android SDK Manager安装Intel Hardware Accelerated Execution Manager

1. Android SDK Manager安裝 Intel x86 Emulator Accelerator (HAXM)
  基本上 沒安裝的都把他裝一裝

2. 測試 打開CMD
輸入sc query intelhaxm 
如果是以下結果
[SC] EnumQueryServicesStatus:OpenService FAILED 1060:
The specified service does not exist as an installed service.

去對應的sdk\extras\intel\Hardware_Accelerated_Execution_Manager 路徑下
安裝...\sdk\extras\intel\Hardware_Accelerated_Execution_Manager\IntelHaxm.exe

3.打開CMD
輸入sc query intelhaxm 
如果出現
SERVICE_NAME: intelhaxm
        TYPE               : 1  KERNEL_DRIVER
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0

        WAIT_HINT          : 0x0

表示成功

4.打開Android Virtual Device Manager
去Edit你的Device
CPU/ABI選項可以選擇了

選一個CPU吧,我個人覺得效果不大 =)

2013年10月2日 星期三

2013年5月6日 星期一

亞健康

亞健康

亞健康現在還沒有明確的醫學指標來診斷,因此易被人們所忽視。一般來說,如果你沒有什麼明顯的病症,但又長時間處於以下的一種或幾種狀態中,注意亞健康已向你發出警報了:失眠乏力無食慾、易疲勞心悸抵抗力差、易激怒、經常性感冒口腔潰瘍便秘等等。處在高度緊張工作、學習狀態的人應當特別注意這些癥狀

2013年4月24日 星期三

BREW 3.1.5 OEM Font


The BREW System using IFont Interface to Draw Text/Chars internal. Actually, It is used by IDisplay_DrawText.
The important concept is, two type font: Logical Font & Physical Font.


1)The Logical Font is as :
// Logical font type
enum {
AEE_FONT_NORMAL=0x8000,
AEE_FONT_BOLD,
AEE_FONT_LARGE,
AEE_FONT_ITALIC,
AEE_FONT_BOLD_ITALIC,
AEE_FONT_LARGE_ITALIC,
AEE_FONT_NORMAL_SCH,
AEE_FONT_USER_1,
AEE_FONT_USER_2,
AEE_FONT_TOTAL
};



2)The Phisical Font is The detail implemented IFont Interface
For, IDisplay, It will associate one logical font type with one phisical font instance. And When you Call IDisplay_DrawText, passed the logical font type, IDisplay inside will using the associated IFont instance to draw chars, such as IFONT_DrawText.


Now, I give the basic flow for BREW Font management:
When BREW Init, BREW will create some system Font instance(physical Font) with such as 
AEECLSID_FONTSYSNORMAL,
AEECLSID_FONTSYSLARGE,
AEECLSID_FONTSYSBOLD, 
And Call IDISPLAY_SetFont to associate them with logical font type:
 AEE_FONT_NORMAL,
AEE_FONT_LARGE,
AEE_FONT_BOLD
Then, When App Call IDISPLAY_DrawText, and passed logical font type, BREW will using the related IFont instance to draw chars.
If App want to change the default physical font, Then, Developer can implement their own IFont Interface. Create this IFont instance in run-time, Then Call IDisplay_SetFont, Passed this IFont Instance and the logical font type which you want to associated, assume, AEE_FONT_BOLD . 
OK, from now on, When you using IDisplay_Drawtext with AEE_FONT_BOLD , BREW will use your own IFont instance to draw the text.


修改自己的FONT三種方法
1)使用BREW Font Extension
2)從底層OEM層修改AEECLSID_FONTSYSNORMAL, AEECLSID_FONTSYSLARGE, AEECLSID_FONTSYSBOLD
3)在程式內撰寫IDisplay_SetFont





2013年4月11日 星期四

BREW IDatabase IDBMgr IDBRecord


1. create a IDBMgr object
-->ISHELL_CreateInstance( .... AEECLSID_DBMGR ... )

2. open database
--> IDatabase IDBMGR_OpenDatabase(......)

once database is open, IDBMgr is not longer needed
-->IDBMGR_Release(....)

3. Create Record
init AEEDBField
--> set fType, fName, wDataLen, pBuffer
--> IDATABASE_CreateRecord( .... AEEDBField ....)

4. Record Reset, Update, Delete, Get


Simplifying Access to BREW Databases


以下是官方資料

The IDatabase Interface functions allow you to create and access records in databases created and opened with the IDBMgr Interface.

1.
To obtain an instance of the IDatabase Interface , you call IDBMGR_OpenDatabase() to open the desired database.

You then use the IDatabase Interface pointer returned by this function to access the database with the operations described below.

2.
You can also use functions in the IDBRecord Interface to access the fields of individual database records.

3.
When you have completed access to the database, you call IDATABASE_Release() to close it.

4.
The IDATABASE_CreateRecord() function creates a new record and adds it to your database (the function IDBRECORD_Remove() is used to remove a record from the database). Each record contains one or more fields.

5.

Each field is defined by the AEEDBField structure, which includes the following elements:
  • The field name is a descriptor of the field's contents, (name, phone number, email address, etc.) The AEEDBFieldName enumerated type contains constants for commonly used field names.
  • The field type gives the data type of the field (byte, word, double-word, character string, binary, phone number or bitmap).
  • The field buffer pointer is a pointer to the actual contents of the field.
  • The field length is the length in bytes of the field contents.  







2013年4月2日 星期二

BREW Using bitmap fonts, How to use AEE_FONT_USER_1/AEE_FONT_USER_2 ?

This example shows how an application uses bitmap fonts to display text.

How to use AEE_FONT_USER_1/AEE_FONT_USER_2 ?

簡單來說BREW DrawText Font不只有這些而已
AEEFont:
Description
This ENUM specifies the logical font type used in IDisplay text drawing operations.

enum {
   AEE_FONT_NORMAL=0x8000,
   AEE_FONT_BOLD,
   AEE_FONT_LARGE,
   AEE_FONT_ITALIC,
   AEE_FONT_BOLD_ITALIC,
   AEE_FONT_LARGE_ITALIC,
   AEE_FONT_USER_1,
   AEE_FONT_USER_2,
   AEE_FONT_TOTAL
};

可以利用
  • AEECLSID_FONT_STANDARD11
  • AEECLSID_FONT_STANDARD11B
  • AEECLSID_FONT_STANDARD15
  • AEECLSID_FONT_STANDARD15B
  • AEECLSID_FONT_STANDARD18
  • AEECLSID_FONT_STANDARD18B
  • AEECLSID_FONT_STANDARD23
  • AEECLSID_FONT_STANDARD23B
  • AEECLSID_FONT_STANDARD26
  • AEECLSID_FONT_STANDARD26B
  • AEECLSID_FONT_STANDARD36
  • 
    怎麼利用呢?How to use this?
    
    
    1.建立Instance
    
    ISHELL_CreateInstance(me->piShell, AEECLSID_FONT_STANDARD11, (void**)&piFontUser1); 
    
    
    2.在Drawtext之前setFont
    
    IDisplay_SetFont(me->piDisplay, AEE_FONT_USER_1, piFontUser1);  
    
    
    3.Draw
    
    IDISPLAY_DrawText(pMe -> a.m_pIDisplay,
                                       AEE_FONT_USER_1,
                                         hello, 
                                        -1 , 
                                          0 , 
                                        0 , 
                                        NULL, IDF_ALIGN_CENTER );
    
    
    
    
    大功告成
    
    
    :)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    2013年3月28日 星期四

    BREW tutorial

    QUALCOMM平台BUIW开发文档
    BREW SDK 3.1
        看這個就對了

    步入 BREW 开发

    第10章IMENUCTL

    实验5 IMenuCtl

    第八章 IMENUCTL

    http://haorui215.iteye.com

    引路蜂移動軟件

    第14章ITectCtl


    Brew 3.1.5環境設置(只適用於Simulator)

    1.安裝Visual Studio 2005 
    2.安裝BREWSDK315SP02.exe 
    BREWSDKTOOLS111SP02.exe 
    BREW_Device_Configurator315.exe 
    -->Mif Editor& Brew Resource Editor, BREW Simulator, BREW Device Configurator v3.1.5 
    3.Using BREW add-in toolbar buttons 
    -->see the BREWSDKToolsUserDocs 

    4.將C:\....\BREW SDK Tools 1.1.1 SP02\VSAddins\vs80 下的資料夾改名為紅色框框內的名字即可

    5.Click Tools -> Add-in Manager.




    Getting start on Brew 

    • New Brew Project 
    • Mif Editor& Brew Resource Editor 
    • BREW Device Configurator v3.1.5 
    • run on Simulator 


    Project name不要有大寫, 不然使用resource會有問題


    Mif Editor

    1.Open BREW MIF Editor
    2.Create class ID from local
    -->save the class_name.bid
    (放在專案資料夾底下)
    3.Compile(Build->Compile MIF Script)
    -->save the class_name.mif
    (與專案資料夾放在一起)


    Resource Editor

    1.Open Brew Resource Editor 
    2.New Resouce item
    -->設定內容
    3.Build->Compile
    -->save class_name.brx


    Device Configurator

    1.執行C:\....\BREW Device Configurator v3.1.5\bin底下的 BREW_DeviceConfig.exe
    2.File->open
    -->C:\....\BREW 3.1.5\sdk\devices\DevicePack4\DevicePack4.dpk
    3.Edit->Device Pack Properties
    設定Font,不然有時會出現亂碼


    Brew Simulator

    1.VS2005->Build->Build Solution
    2.Open Brew Simulator ->File->Load Device
    -->設定Applet Directory ->Apply
    3.按下Apply後模擬器會Load程式






















    2013年3月27日 星期三

    BREW ISHELL_LoadResImage ALWAYS NULL PROBLEM


    At BREW SDK v3.1.5 + Visual Studio 2005
    If your ISHELL_LoadResImage ALWAYS return NULL
    Because your project name, resource name... have a upper-case characters.
    So.....




    BREW Applet SDK

    BREW Applet框架

    BREW Applet框架 - 田海立的专栏 - CSDN博客




    BREW Applet框架收藏

    BREW Applet框架
    The Framework of BREW Applet

    2006-5-6

    摘要

    本文首先通过一个简单的Applet介绍BREW环境下Applet的运行环境,然后分析如何在一个Module中实现多个Applet的方法,以及BREW中分布在不同的Module中的各Applet之间的启动交互关系。


    摘要... 1
    1 BREW概览... 2
      
    1.1 BREW简介... 2
      
    1.2 BREW中的几个基本概念... 2
      
    1.3 BREW模拟开发环境... 3
    麻雀虽小,五脏俱全之HelloBREW.. 3
      
    2.1 文件组成... 3
      
    2.2 ModuleApplet的总体框架... 4
      
    2.3 实现HelloBREW.. 6
        
    2.3.1 类型定义... 6
        
    2.3.2 AEEClsCreateInstance()的实现... 6
        
    2.3.3 HandleEvent()的实现... 7
        
    2.3.4 加入事件处理代... 8
      
    2.4 HelloBREW的执行结果... 9
    多个Applet实现在同一个Module... 9
      
    3.1 文件组成... 9
      
    3.2 实现AppsInOneModule11
        
    3.2.1 类型定义... 11
        
    3.2.2 AEEClsCreateInstance() 函数的实现... 11
        
    3.2.3 Applet构造函数的实现... 12
        
    3.2.4 Applet事件处理... 12
      
    3.3 执行序列... 13
    4 Applet实现在不同的Module... 14
    总结... 16
    参考资料及进一步参考... 16
    关于作者... 17


    1 BREW概览

    1.1 BREW简介

    BREWBinary Runtime Environment for Wireless,即无线二进制运行环境)是QUALCOMM 公司的产品。它以组件(COM的组织形式封装了底层平台提供给应用开发的服务,屏蔽了底层的实现细节,而提供给应用层统一的API。它所提供的API描述的是Spec而非实现细节,不管今后QUALCOMM的平台技术如何发展,其实现的功能和实现该功能的API规范应该是确定并向后兼容的。
    BREW上接受的OEM或其他第三方软件厂商提供的最终软件实体Module的执行体——Win32模拟环境下是 *.dll,真实机器上是*.mod,这也体现了BREW中的Binary。另外,也可以在BREW运行时从网络上下载BREW所接受的实体,加入到BREW中来运行。

    1.2 BREW中的几个基本概念

    BREW中的有AppletExtensionApplet是一个独立运行(从应用开发角度看)的实体,有Applet Context,简记为ACONTEXTExtension过实现它所定义的接口提供服务给Applet或其它ExtensionExtension不是独立的运行实体,它运行在调用它的Applet(直接或间接地,当前Extension Ext1的某个服务Ext1::srv可能不是由Applet接调用,但是调用Ext1::srvExtension Ext2归根到底还是可以追溯到某个Applet)的ACONTEXT中。AppletExtension都是被包含在Module里面的,它们之间的关系如一所示。

     
    图一、BREW中几个概念之间的关系

           BREW最终接受的是Module,所以你所提供的AppletExtension必须在某个Module中;另一方面,一个Module里可以有0…nAppletExtension,也可以同时有AppletExtension还可以两者都没有,不过两者都没有的Module也没有实际意义Module的属性和它所包含的AppletExtension的信息,以及Dependency关系都描述在MIFModule Information File)文件里,BREW通过该描述文件检索它所需要的信息,并通过相应的Module二进制文件完成相应的操作。
           BREW加载AppletExtension时,首先检查包含它的Module是否已经被加载到内存里,如果还没在内存里,BREW要做的工作是先把该Module加载;接着BREW通过该ModuleIMODULE_CreateInstance() 来创建AppletExtension的一个实例,然后才完成AppletExtension的真正加载。

    1.3 BREW模拟开发环境

    本文所描述的BREW环境和概念都是基于BREW 3.0.1,采用的程序在下面软件环境中调试通过:
    BREW SDK 3.0.1,包含
                  API手册
                  BREW Simulator, MIF Editor, etc.
                  Header files & some src files
    Microsoft Visual studio,包含
                  Visual studio 6.0
                  Visual studio 6.0 Service Package 5
           Additions
                  BREW Application Wizard
                  BREW Addins for vs60

    麻雀虽小,五脏俱全之HelloBREW

    有了上面BREW的概念以及开发调试所需的软件环境,下面我们看一个简单的BREW Applet——HelloBREW

    2.1 文件组成

           ms vs60环境中通过BREW Application Wizard创建一个HelloBREW 工程。自动生成和关联的文件如图二所示。

     
    图二、HelloBREW中自动生成的文件

           AEEAppGen.cAEEModGen.cBREW SDK中自代的文件,分别是IAppletIModule的一个实现。HelloBREW.c是新生成的文件,利用了AEEApplet这一Applet实现模版来实现特定的Applet
    这些文件将连同BREW SDK提供库一块被编译并连接成一个dll文件——HelloBREW.dllWIN32环境中,Module的执行体)。但是,只是有这些还不行,还没有跟BREWModuleApplet关联起来,BREW Simulator也不会知道如何创建和加载它们。我们还必须创建一个MIF文件来描述这些信息。
           假定,我们创建的HelloBREW这个Applet包含在HelloBREW Module中。那么,我们用BREW MIF Editor创建一个HelloBREW.mif文件;然后在其中创建一个Applet HelloBREW,并把这个AppletAEECLSID述文件HelloBREW.bid保存;最后通过菜单Build Compile MIF Script来编译这个MIF脚本,保存退出。用BREW MIF Editor创建HelloBREW.mif的过程如图三所示。

     
    图三、编辑HelloBREW.MIF

           上面工作做完之后,vs60的工程就可被Build成一个BREWModule执行体,并可用BREW Simulator来装载执行。但是,现在这个ModuleApplet什么工作也没做,执行起来也没什么意义,笔者打算在分析Applet框架并加入一些处理代码之后,再来执行之。

    2.2 ModuleApplet的总体框架

    通过调试跟踪上述的HelloBREW 工程,得出图四所示的BREW ModuleApplet的执行序列。

     
    图四、BREWModuleApplet演示——HelloBREW

    AEEModGenAEEAppGenHelloBREW 一起被编译并连接为 HelloBREW.dll。如1.2节所述,BREW 刚启动时并不是加载所有的Module,只有在 Module 所包含的 Applet  Extension 需要被加载时,BREW才加载该Module。所以,当用户点击执行HelloBREW 这个Applet 时,BREW 通过调用 AEEMod_Load() 首先来加载这个 Module [序列1]AEEModGen 通过 AEEStaticMod_New() 完成IModule 创建和初始化的工作之后,Module的加载过程完成[序列2&3]
    Module被加载完成之后,BREW就通过 IMODULE_CreateInstance() 来创建AppletAEEModGen通过HelloBREWAEEClsCreateInstance(),把Applet的具体创建工作交给HelloBREW [序列4, 5 & 6];而AEEAppGen通过AEEApplet_New() 提供了IApplet创建和初始化的便利,HelloBREW过在AEEClsCreateInstance()中调用此函数,把具体的事件处理函数HelloBREW_HandleEvent() 和程序退出时的清理函数注册到BREW里。当完成上述工作并返回AEE_SUCCESS之后, Applet的创建也就完成了 [序列 4~8]
    如果Applet是因为要运行而被创建并成功创建之后,会马上收到一条EVT_APP_START的事件,此时你的Applet已经正常的加载运行了,并通过HandleEvent数来处理它所收到的各种事件。

    再把上述过程总结一下,AEEAppGenAEEModGen其实并不是独立的实体对象,只是由于它们是BREW SDK提供的,为了明确展现开发BREW Applet时,程序员自己所要做的工作的需要,才把它们单独列出来。要看程序员所需要做的工作,只需要从图四中HelloBREW的生命线(竖线)看过去,也就是只要实现AEEClsCreateInstance(),另外,HelloBREW调用AEEApplet_New() 时,把注册自己实现的事件处理函数和程序退出时的清理函数,而退出时的清理函数也可以不定义,所以最后,程序员所要实现的函数只有AEEClsCreateInstance()和事件处理函数。

    2.3 实现HelloBREW

    2.3.1 类型定义

    首先,定义一个结构体,里面可以存放用户关心的数据。

    typedef struct _HelloBREW {
        AEEApplet       a             // Must be AEEApplet
        AEEDeviceInfo  DeviceInfo;    // access to the HW device info
        IDisplay       *pIDisplay;    // access the Display interface
        IShell         *pIShell;      // access the Shell interface
    HelloBREW;
    代码片断一、HelloBREW类型的定义

    2.3.2 AEEClsCreateInstance()的实现


    int AEEClsCreateInstance(AEECLSID ClsIdIShell *pIShellIModule *povoid **ppObj) {
        *ppObj = NULL;
        if (ClsId == AEECLSID_HELLOBREW)     {
            // Create the applet and make room for the applet structure
            if (AEEApplet_New(sizeof(HelloBREW),                           ClsId,                           pIShell,                           po,                           (IApplet**)ppObj,                           (AEEHANDLER)HelloBREW_HandleEvent,                           (PFNFREEAPPDATA)HelloBREW_FreeAppData))         {
                if (HelloBREW_InitAppData((HelloBREW*)*ppObj))             {
                    // Data initialized successfully
                    return (AEE_SUCCESS);             }
                else
                {
                    IAPPLET_Release((IApplet*)*ppObj);                 return EFAILED;             }
            // end AEEApplet_New
        }
        return (EFAILED); }
    代码片断二、HelloBREW  AEEClsCreateInstance() 的实现

    这里定义了一个局部的初始化函数HelloBREW_InitAppData(),用来执行用户数据的初始化,比如,把初始化HelloBREW的下列成员DeviceInfo : AEEDeviceInfo; *pIDisplay: IDisplay; *pIShell: IShell

    2.3.3 HandleEvent()的实现

    最后看,HelloBREW的主体——事件处理函数HelloBREW_HandleEvent()
    原型为:
    boolean HelloBREW_HandleEvent(HelloBREW* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
    该函数通过eCode参数来决定消息的类型,然后做出相应的处理,所以它的主体是一个大的switch语句:

        switch (eCode)     {
            // App is told it is starting up
            case EVT_APP_START:             return (TRUE);
            // App is told it is exiting
            case EVT_APP_STOP:             return (TRUE);
            // App is being suspended 
            case EVT_APP_SUSPEND:             return (TRUE);
            // App is being resumed
            case EVT_APP_RESUME:             return (TRUE);
            case EVT_APP_MESSAGE:             return (TRUE);
            case EVT_KEY:             return (TRUE);
            // If nothing fits up to this point then we'll just break out
            default:             break;    }
       return FALSE;
    代码片断三、HelloBREW 中事件处理的主体实现

    如果事件被处理,该函数返回TRUE,否则返回FALSE

    2.3.4 加入事件处理代码

    为了简单起见,笔者就直接在HelloBREW刚被加载也就是在收到EVT_APP_START事件的时候加入一些处理。对这个事件的处理也只是显示“Hello BREW”。相应的代码如下:

        AECHAR szText[] = L"Hello BREW";
        switch (eCode)
        {
            // App is told it is starting up
            case EVT_APP_START: ...

    Things you can do from here: