Monday, April 28, 2008

Starting Brew from Scratch from Visual Studio 2005 Express Edition

Contents:
=========
        1. Install Brew SDK
        2. Generate MIF
        3. Create a skeleton project
        4. Important Notes

1. Install Brew SDK
===================
        a. Download an Install the Brew SDK, preferably 2.1.0. For Documentation reference 3.x SDK could be used.
        b. To keep all the project file, mfx files machine independent, create an Environment Variable BREWSDK210EN pointing to the BREW SDK Directory. Please use DOS File formats in Environment variable. ( For 3.1.2 SDK use BREWSDK312EN, for a 2.0.1 Japanese SDK use BREWSDK201JP)
                eg: Assuming the BREW SDK is installed in "F:\Program Files\BREW SDK v2.1.0" to get the DOS format use DIR /X /AD command.
************************************
F:\>dir /x /ad
Volume in drive C has no label.
Volume Serial Number is 8CC3-3122
04/14/2008 04:11 PM <DIR> PROGRA~1 Program Files
04/17/2008 10:57 AM <DIR> WINDOWS
************************************
The DOS file format of Program Files is PROGRA~1

************************************
F:\Program Files>dir /x /ad
Volume in drive C has no label.
04/17/2007 08:22 PM <DIR> BREW31~1.2 BREW 3.1.2
04/19/2007 05:57 PM <DIR> BREW31~1.3 BREW 3.1.3
04/19/2007 06:28 PM <DIR> BREW31~1.4 BREW 3.1.4
10/29/2007 04:43 PM <DIR> BREW31~1.5 BREW 3.1.5
07/24/2007 04:13 PM <DIR> BREWBR~1.0 BREW Browser v2.0.0
04/17/2007 08:43 PM <DIR> BREWSD~1.1 BREW SDK Tools 1.0.1
08/09/2007 03:25 PM <DIR> BREWSD~3.1 BREW SDK Tools 1.1.1
10/04/2007 01:04 AM <DIR> BREWSD~1.1SP BREW SDK Tools 1.1.1 SP01
01/21/2008 01:22 PM <DIR> BREWSD~2.1 BREW SDK v2.0.1
04/27/2007 02:48 PM <DIR> BREWSD~1.0 BREW SDK v2.1.0
04/19/2007 05:40 PM <DIR> BREWSD~1.3 BREW SDK v2.1.3
07/26/2007 12:33 AM <DIR> BREWUI~1 BREW UI Widgets
*******************************
The DOS file format for BREW SDK v2.1.0 is BREWSD~1.0 (**Note: This is system dependent**)

So the path to the BREW SDK is F:\PROGRA~1\BREWSD~1.0\

To add Environment Variable
        1. Right-Click "My Computer"
        2. Properties->Advanced->Environment Variable
        3. Click "New" under the "System Variable" Section
        4. Add Variable Name as BREWSDK210EN
        5. Add Variable Value as F:\PROGRA~1\BREWSD~1.0\

2. Generate MIF
===============
        a. Open MIF Editor, listed under BREW SDK Tools
        b. In the BREW MIF Editor window, click the Applets tab.
        c. Create a new applet, by clicking the New Button in the List of Applets defined in this Module. The "Specify BREW Class ID" Windows pops.
        d. Select the Locally Radio Button.
        e. Add a unique Class ID (say "0x12345678", ( you should create new class id's every time you create a new project ).
        f. Also put the put the Class Name (say "FIRSTHELLOWORLD")
        g. Click Ok, you will be prompted to generate file. Save the BID file in the Project Directory. ( FIRSTHELLOWORLD.bid )
        h. For 2.1.0, add the Images from the "images" Directory
                * Large                ->        BrewImage-1.bmp
                * Medium        ->        BrewIcon-1.bmp
                * Small                ->        Games16x16-1.bmp
        i. Now Save the file in the project directory. ( firsthelloworld.mfx )
        j. To make the MFX machine independent use relative path.
                * I have created a copy of firsthelloworld.mfx created in Step 2.i as
                firsthelloworld.mfx.start
                * Now edit the firsthelloworld.mfx in Notepad (any Text
                Editor), find the below
**************
        <Object Id="21" Name="IDI_OBJECT_21">
                <File>F:\temp\firsthelloworld\images\BrewIcon-1.bmp</File>
        </Object>
        <Object Id="22" Name="IDI_OBJECT_22">
                <File>F:\temp\CVS_Work\firsthelloworld\images\BrewImage-1.bmp</File>
        </Object>
        <Object Id="23" Name="IDI_OBJECT_23">
                <File>F:\temp\CVS_Work\firsthelloworld\images\Games16x16-1.bmp</File>
        </Object>
*************
When MFX is compiled in another system, the project directory could be anything but E:\Work\CVS_Work\firsthelloworld, so use relative path ".". Dot (.) stands for Current Directory.
**************
        <Object Id="21" Name="IDI_OBJECT_21">
                <File>.\images\BrewIcon-1.bmp</File>
        </Object>
        <Object Id="22" Name="IDI_OBJECT_22">
                <File>.\images\BrewImage-1.bmp</File>
        </Object>
        <Object Id="23" Name="IDI_OBJECT_23">
                <File>.\images\Games16x16-1.bmp</File>
        </Object>
*************

Now open this edited MFX file and Compile. ( Output firsthelloworld.mif ).

One inconveneice with MIF Editor is any time you edit the MFX file, it will replace the Relative Path with Actual Path, so everytime you "save" the file, edit with with a notepad after saving.

3. Creating a Skeleton Project
==============================
3.1 New Project
---------------
        a. Open Visual Studio 2005 Express Edition
        b. Create a New Project
        c. Choose Project Type as Win32
        d. Choose Template as Windows Console Application
        e. Name: firsthelloworld
        f. Location: As your preference
        g. Unselect "Create directory for solution"
        h. OK -> Next
        i. Select "Empty Project"
        j. Unselect "Precompiled header"
        k. Finished

Now the Solution Explorer Pane Contains:
        firsthelloworld
                * Header Files
                * Resource Files
                * Source Files

3.2 Adding Files
----------------
        a. Right-Click on firsthelloworld project, Add -> Existing Items
        b. Add AeeAppGen.c and AeeModGen.c in the src folder of BREWSDK directory.

3.3 Setting Up a Brew Application
        a. Right-Click on firsthelloworld project, Properties
        b. Make sure the Configuration Name is Active(Debug)
        c. On the Left Pane, Configuration Properties -> General
                * Set Configuration Type = Dynamic Library (.dll)
        d. Configuration Properties -> Linker -> General
                * Set OutputFile = $(OutDir)\$(ProjectName).dll
        e. Configuration Properties -> C/C++ -> Preprocessor
                * Preprocessor = WIN32;_DEBUG;_WINDOWS;_USRDLL;AEE_SIMULATOR
        f. Configuration Properties -> C/C++ -> General
                Additional Include Directories ->"E:\Program Files\BREW SDK v2.1.0\inc"
(Note: Please quotes around the directory name, the the directory name contains space ).
        g. Now Apply, and Build the project.

You should get the following Errors:
**********************************
------ Build started: Project: firsthelloworld, Configuration: Debug Win32 ------
Compiling...
AEEModGen.c
AEEAppGen.c
Generating Code...
Compiling manifest to resources...
Linking...
Creating library f:\temp\firsthelloworld\Debug\firsthelloworld.lib and object f:\temp\firsthelloworld\Debug\firsthelloworld.exp
AEEModGen.obj : error LNK2019: unresolved external symbol _AEEClsCreateInstance referenced in function _AEEMod_CreateInstance
f:\temp\firsthelloworld\Debug\firsthelloworld.dll : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://f:\temp\firsthelloworld\Debug\BuildLog.htm"
firsthelloworld - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
*********************************

3.4 Building the DLL
--------------------
        a. Now copy helloworld.c from the BREWSDK Examples to the project directory
        b. Add the File to the Project.
                * Right Click on firsthelloworld
                * Add -> Existing Items -> Select the helloworld.c
        c. Change #include "helloworld.bid" to #include "firsthelloworld.bid"
        d. Compile the project. (This should build successfully)
There should be a dll file in Debug Directory

With this you won't be able to run the dll.

3.5 Running the Application
---------------------------
Let us start from scratch. Delete the BREW_Emu.dat in the bin directory of the BREW SDK. This file contains the basic settings.
        a. Create a Directory known a BrewAppRepository or something similar
        b. Create an Environment variable named BREWAPP pointing to the BrewAppRepository. (Refer above document on how to create Envirnment Variables).
        c. Make a directory inside BrewAppRepository as firsthelloworld.
        d. Copy the firsthelloworld.dll from the Debug Directory into the newly created folder.
        e. Copy the firsthelloworld.mif into BrewAppRepository
        f. Now Start->Program Files->BREW SDK xxx->Brew Simulator/Emulator
        g. A Settings Dialog is displayed
        h. Choose the Device as the Initial Device from the Devices Directory of the BREW SDK
        i. Choose BrewAppRepository as the Applet Directory.
        j. Click OK
You should see the able to see the FIRSTHELLOWORLD Application icon. On clicking it, "Hello World" will be displayed.

Now, this requires you manual copy the dll every time you build the dll. And you need to run the emulator from Start->Program files. There many ways to avoid this problem.
        1. Post Build Script
        2. Setting Output Directory
With the above solution, you need to set as to how you want to run the dll.
        * Go to Project properties ( Right Click on firsthelloworld -> Properties )
        * Configuration Properties -> Debugging
                Command = <Select the BREW_Emulator.exe in the bin directory on the Brew SDK> ( In 3.x and greater it is known as BREW_Simulator.exe )
                This is a User Based Setting, that means on every time you copy the project into a different User Space or System, you need to do this setting.
        * Now Press F5 or Debug -> Start Debugging

3.5.1 Post Build Script
        Simple Shell Scripts which will copy the dll to the Brew Applet directory.
        a. Go to Project properties ( Right Click on firsthelloworld -> Properties )
        b. Configuration Properties -> Build Events -> Post-Build Events
                Command Line = copy Debug\firsthelloworld.dll $(BREWAPP)\firsthelloworld\
(Note: I am using Environment Variable)
********************** After every build
Performing Post-Build Event...
1 file(s) copied.
**********************

3.5.2 Setting Output Directory
        a. Go to Project properties
        b. Configuration Properties -> Linker
                Output Directory = $(BREWAPP)\$(ProjectName)\$(ProjectName).dll

3.6 Adding Debug Information
----------------------------
        I have made a copy of the Project File before I started adding Debug Information. ( firsthelloworld.vcproj.withoutDebug )
        a. Go to Project Properties
        b. Configuration Properties -> C/C++ -> General
                * Debug Information Format = Program Database for Edit & Continue
                * Warning Level = Level 4
                * Detect 64-bit Portability Issues = No
        c. Configuration Properties -> C/C++ -> Browse Information
                * Enable Browse Information = Include All Browse Information
        d. Configuration Properties -> Linker -> Debugging
                * Generate Debug Info = YES

3.7 Making it System Independent
--------------------------------
        I have made a copy of the Project File before I make it system Independent
( firsthelloworld.vcproj.systemDependent )
        a. Close VS 2005 Express
        b. Edit the firsthelloworld.vcproj wit a Text Edit ( Notepad, Vi )
        c. Replace all instance of the BREW SDK Directory (say E:\Program Files\BREW SDK v2.1.0) with $(BREWSDK210EN).
        d. Save and exit

4. Important Notes
==================
        a. Always restart the VS 2005 Express after adding a new Environment.
        b. Always close all instance of VS 2005 Express, when you edit the vcproj file using Text Editor
        

This document is licensed under the Creative Commons Attribution 3.0 Unported License ( http://creativecommons.org/licenses/by/3.0/ )

Friday, June 01, 2007

Saving Electricity - Inspired by Blackle

For those who are inspired by Blackle and want to invert ( change ) the color of the entire system to black - what are you waiting for!!!

1. Goto Control Panel.
2. Select Display -> Click the Apperance Tab.
3. Choose High Contrast #1 or #2 ( Greeniee Foreground ) in the Color Scheme.
4. Apply and wait for the changes to happen.

Once this is done, you can access Google instead of Blackle.

Sometimes the browser may not use the system default color scheme, for that to happen:
1. Open Browser ( Firefox )
2. Tools menu -> Options
3. Content Tab -> Colors
4. Mark the Use System Color Option
5. Click Ok.

Trickles of Water in the high mountains, together form a mighty river - which joins the great Ocean.