Debugging Resolution Aware .NET CF Pocket PC Apps


To mark a Pocket PC app as being resolution aware, you have to compile a native resource file into it.  VS.NET doesn't have a way of doing this so we published a tool called RES2EXE which allows you to push a res file into a compiled .NET CF exe file.  Using it is pretty straightforward (see the Second Edition managed code whitepaper for details) but the debugging story is pretty painful. To debug a resolution aware app you have to:



  1. Build your project from VS.NET
  2. Open up a command line and run the RES2EXE tool on your compiled output

    • Note: you must run the tool on the version of your output in the Obj directory - not Bin.

  3. Switch back to VS.NET and launch the debugger

With Whidbey life will be easier, but until then you can either get used to the steps above or take advantage of VS.NET macro engine to automate the process.  Below is the macro I'm using for this.  After creating the macro, you can place a button for it on a toolbar or even bind a keyboard shortcut to it (I use Ctrl-Shift-Alt-F5).  So now I can forget about switching back and forth to the command line and be happy once again.  Enjoy!



Public Sub DebugAsHighRes()


    ' Path for 2nd Edition Resources. You may need to change this to match your setup.
   
Dim SecondEditionResources As String = "C:\Program Files\Developer Resources for Windows Mobile 2003 Second Edition\tools\"
    Dim ActiveProject As Project = DTE.ActiveWindow.Project
    Dim Solution As SolutionBuild = DTE.Solution.SolutionBuild


    ' Create the command line for marking the output file as resolution aware
   
Dim ResFile As String = """" + SecondEditionResources + "\hidpi.res"""
    Dim Params As String = " -r -c "
    Dim Res2Exe As String = """" + SecondEditionResources + "\res2exe.exe"""
    Dim OutputFile As String = """" + ActiveProject.Properties.Item("LocalPath").Value + "\obj\Debug\" + ActiveProject.Properties.Item("OutputFileName").Value + """"
    Dim Command As String = Res2Exe + Params + ResFile + " " + OutputFile


    ' Build, mark has resolution aware, and then launch the debugger
   
Solution.BuildProject("Debug", ActiveProject.UniqueName, True)
    Shell(Command, AppWinStyle.Hide, True)
    DTE.Debugger.Go(False)


End Sub


[Author: Robert Levy]


Comments (9)

  1. Marco Loprete says:

    Hallo Robert

    Isn’t there any possibility of integrating the hidpi information directly into your project?

    The problem is that the icon information of your application is lost after you use res2exe.

    There are also problems if you generate a CAB file directly out of visual studio. The information which res2exe has embedded is then gone again!

    Thanks for information

    Marco Loprete

  2. Robert Levy says:

    Unfortunately not. This is something we’re looking at improving for VS 2005.

  3. Marco Loprete says:

    Do you know any workaround that allows to bring the icons back into the application?

  4. Chris Hodder says:

    In case anyone’s still interested, the way I’ve worked around the icon issue is this:

    Make a copy of the hidpi.res file.

    Open it in VS.NET (or your favourite resource editor)

    Import the icon from the project’s .ico file, and set the ID of the icon resource to 32512

    Add any other resources to the project if you so wish, like VERSIONINFO etc, as these will also disappear.

    Important, it appears you then need to remove the name of the icon from the project properties, otherwise it will not go hires

    Save the modified hidpi.res file in your project’s path and alter a line in the macro. Change

    Dim ResFile As String = """" + SecondEditionResources + "hidpi.res"""

    to

    Dim ResFile As String = """" + ActiveProject.Properties.Item("LocalPath").Value + "hidpi.res"""

    Also, as per http://groups.google.com/group/microsoft.public.dotnet.framework.compactframework/browse_thread/thread/f91a56bb638bf00f/dbf6a3edf7bf8332

    Change the line

    Dim ActiveProject As Project = DTE.ActiveWindow.Project

    to

    Dim ActiveProject As Project = DTE.Solution.Projects.Item(DTE.Solution.SolutionBuild.StartupProjects(0))

    Then it won’t fail with an error if a project window isn’t in focus.

    I also made one other change, as I found if I didn’t save the project first then it sometimes didn’t build hi-res aware, so I added the line:

    ActiveProject.Save()

    after the "Dim Solution …" line

    I haven’t got around to deploying the exe yet, so haven’t bothered trying to get it to work with the cabinet builder, but will post here when I do!

    Hope this helps 🙂

  5. scippy says:

    Res2exe strips out program icon

    I’ve found two solution around this problem:

    ***************** FIRST SOLUTION *************************************

    Make a copy of the hidpi.res file into your project folder.

    Open it in VS.NET (or your favourite resource editor)

    Click with right mouse button on hidpi.res for adding a resources, import the .ico file and set the ID of the icon resource

    to 32512

    Add any other resources to the project if you so wish, like VERSIONINFO etc, as these will also disappear.

    Important, it appears you then need to remove the name of the icon from the project properties, otherwise it will not go

    hires

    Save the modified hidpi.res file in your project’s path and alter two lines in the hires macro.

    Change:

    Dim ResFile As String = """" + SecondEditionResources + "hidpi.res"""

    to

    Dim ResFile As String = """" + ActiveProject.Properties.Item("LocalPath").Value + "hidpi.res"""

    Change the line

    Dim ActiveProject As Project = DTE.ActiveWindow.Project

    to

    Dim ActiveProject As Project = DTE.Solution.Projects.Item(DTE.Solution.SolutionBuild.StartupProjects(0))

    Then it won’t fail with an error if a project window isn’t in focus.

    I also made one other change, as I found if I didn’t save the project first then it sometimes didn’t build hi-res aware, so I

    added the line:

    ActiveProject.Save()

    after the "Dim Solution …" line

    I haven try to get it to work with the cabinet builder, and It work all OK!

    You can see the new debug and release macro for hires projects below:

    ================== The modify MACRO HIRES ================================

    Imports EnvDTE

    Imports System.Diagnostics

    Public Module hires

    Sub hires_dbg()

    ‘ Path for 2nd Edition Resources. You may need to change this to match your setup.

    Dim SecondEditionResources As String = "C:Program FilesDeveloper Resources for Windows Mobile 2003 Second

    Editiontools"

    Dim ActiveProject As Project = DTE.Solution.Projects.Item(DTE.Solution.SolutionBuild.StartupProjects(0))

    Dim Solution As SolutionBuild = DTE.Solution.SolutionBuild

    ActiveProject.Save()

    ‘ Create the command line for marking the output file as resolution aware

    Dim ResFile As String = """" + ActiveProject.Properties.Item("LocalPath").Value + "hidpi.res"""

    Dim Params As String = " -r -c "

    Dim Res2Exe As String = """" + SecondEditionResources + "res2exe.exe"""

    Dim OutputFile As String = """" + ActiveProject.Properties.Item("LocalPath").Value + "objDebug" +

    ActiveProject.Properties.Item("OutputFileName").Value + """"

    Dim Command As String = Res2Exe + Params + ResFile + " " + OutputFile

    ‘ Build, mark has resolution aware, and then launch the debugger

    Solution.BuildProject("Debug", ActiveProject.UniqueName, True)

    Shell(Command, AppWinStyle.Hide, True)

    DTE.Debugger.Go(True)

    End Sub

    Sub hires_rls()

    ‘ Path for 2nd Edition Resources. You may need to change this to match your setup.

    Dim SecondEditionResources As String = "C:Program FilesDeveloper Resources for Windows Mobile 2003 Second

    Editiontools"

    Dim ActiveProject As Project = DTE.Solution.Projects.Item(DTE.Solution.SolutionBuild.StartupProjects(0))

    Dim Solution As SolutionBuild = DTE.Solution.SolutionBuild

    ActiveProject.Save()

    ‘ Create the command line for marking the output file as resolution aware

    Dim ResFile As String = """" + ActiveProject.Properties.Item("LocalPath").Value + "hidpi.res"""

    Dim Params As String = " -r -c "

    Dim Res2Exe As String = """" + SecondEditionResources + "res2exe.exe"""

    Dim OutputFile As String = """" + ActiveProject.Properties.Item("LocalPath").Value + "objRelease" +

    ActiveProject.Properties.Item("OutputFileName").Value + """"

    Dim Command As String = Res2Exe + Params + ResFile + " " + OutputFile

    ‘ Build, mark has resolution aware, and then launch the debugger

    Solution.BuildProject("Release", ActiveProject.UniqueName, True)

    Shell(Command, AppWinStyle.Hide, True)

    DTE.Debugger.Go(False)

    End Sub

    End Module

    [Original Author: Robert Levy]

    ***************** SECOND SOLUTION *************************************

    The second solution is very simply!

    You must remove from your original hires macro the option -r

    Change the line

    Dim Params As String = " -r -c "

    to

    Dim Params As String = " -c "

    In this way the icon information of your application is no lost after you use res2exe, but you must remember to rebuild zone

    of your application everytime before you lunch the hires macro!

    Hope this helps :)…

    scippy@tin.it

Skip to main content