Sadagopan's blog

  • MFC 3.0 to WM 5.0 - Runtime

    In my previous post, I was talking about the feasibility of developing MFC 3.0 applications for deploying on WM 5.0. Though the Win CE operating system (and therefore the Windows Mobile 5.0 operating system) guarantees binary level compatibility, in reality, there will be breaking changes in the operating system especially for security issues which could cause applications to break. We will be exploring issues that could cause MFC 3.0 applications or upgraded MFC 8.0 applications not to work as expected and I want to focus on the operating system changes as well.

    Dialog based MFC 3.0 applications with DS_MODALFRAME set do not work on WM 5.0.

    There has been a security fix in the Windows CE operating system memory protection routines. The MFC 3.0 libraries assumed that this API would work fine for all conditions – changing a memory mapped page’s access protection from READ to READ_WRITE, but the fix in the operating system for WM 5.0 invalidates this assumption. This particular API is used when the dialog resources are loaded. The API is not used as part of the MFC 8.0 sources and dialog based applications work fine on WM 5.0.

    You can see the code in dlgcore.cpp (as part of the MFC sources). Please note that this particular issue will only affect dialogs which have the DS_MODALFRAME bit set. You can take a look at the dialog definition in the resource file to verify that you are not getting affected by this issue. When you deploy the application you will see an access violation when the lpTemplate is accessed to change its state (the last line in the snippet below).

    else if (mbiMemory.Protect == PAGE_READONLY)

    {

    // Mark the dialog template as read-write.

    VirtualProtect(lpTemplate, sizeof(DLGTEMPLATE), PAGE_READWRITE, &dwResult);

    lpTemplate->style &= ~DS_MODALFRAME;

    }

    You could remove the DS_MODALFRAME definition from the resource file and rebuild the binary.

    If, for some reason, rebuilding the binary is not possible, you can use  

    editbin.exe /section:.rsrc,rw <resource binary>

    editbin.exe is a tool in VS 2005 which you can use from the VS 2005 Command Prompt. I had a lot of help from the support group and the Win CE team in getting to the root of the problem and the work-around.

    That will make the problem go away. This could be used as a post-build step in eVC 4.0 or a pre-build step in the dummy VS 2005 application.  

  • MFC 3.0 to WM 5.0

    I am going to take a detour and talk about something closer to home. As I stated before, I am now in the VSD team and we have shipped a set of tools and libraries in VS 2005 to make the life of device developers easier. However, this is turning out to be easier said than done. While we have shipped a really good development tool, the amount of support in the development environment to people with existing applications built on legacy tools is not perfect. I think that as a product team, we made the right decisions and achieved a fair degree of balance in this space to bring more power to the device developer to build really useful and powerful applications with new features in addition to helping people move over to the newer toolset as well. But, there is more that we can do to help people upgrade and that is the purpose of this blog and succeeding ones.

    When I started going through the community posts, as expected, we had a series of questions on upgrading from eVC 4.0 to VS 2005. The upgrade wizard that is shipped with VS2005 is not the most visible feature though it really takes a major load off the upgrade scenario for mundane things like setting project flags and other things that you as a developer should not really be worrying about. The interesting (okay not so perfect) issue with this tool is that it does not automatically enable VS 2005 to recognize eVC 4.0 projects as something that can be upgraded making it a little harder to discover. Double-clicking on the vcw project file through the File Explorer does not do anything (or if you have eVC 4.0, it brings it up instead). You need to open the vcw file through VS 2005 for the upgrade wizard to kick in and do the appropriate conversion. It is also not very tolerant of changes to configuration strings in the eVC generated project file as can be seen from the following forum post.

    The project consists entirely of configurations that require supp...

    All said and done, this utility will help a lot in reducing the pain in upgrading to VS 2005 and is really useful.

    eVCUpgrade

    While the project settings are upgraded in a manner consistent with the newer tools (like the compilers and libraries) in VS 2005, there are some differences which could block you from successfully building and deploying your applications in Whidbey. A couple of the most common differences which are a little hard to trace are listed in the blog posts below.

    Error LNK2019 / error LNK2001: unresolved external symbol Linker errors for Device projects that use MFC and ATL libraries

    Error LNK2019: unresolved external symbol

    The other widespread question we as a team were asked was about the feasibility of MFC 3.0 applications on WM 5.0. 

    There are two aspects to the questions – if I am continuing to develop the application, what is my choice of the development environment?

    Well, you have two choices depending on the application itself.

    1)    Upgrade to Visual Studio 2005. You use the entire MFC 8.0 libraries shipped with Whidbey. This upgrade will use the latest compilers, debugger, the WM 5.0 emulator and also the latest 8.0 libraries. VS 2005 supports development on WM 5.0 with this tool set completely and therefore is the best choice in the long run.

    2)    The second choice, which in my opinion is short-term is to use eVC 4.0 as the development environment whereas use VS 2005 to debug the application on WM 5.0. There are reasons why this might make sense in the immediate term. WM 5.0 has been around for a while now and the first round of devices is already appearing on the market soon. MFC 8.0 released just now and upgrading to MFC 8.0 from MFC 3.0 may take some time due to either dropped support for certain classes or compatibility issues between MFC 3.0 and MFC 8.0. Compatibility has been really important for our product team and we have tried hard to maintain it, but realistically speaking there will be a few issues – wish we could be perfect here though. While moving to the latest tools should be the long-term strategy, there might be reasons why there might be an immediate need to deploy on WM 5.0.  

    Here are the steps to debug MFC 3.0 applications on WM 5.0 using Visual Studio 2005.

    1)    Install eVC 4.0 SP4 and Visual Studio 2005 on the same machine.

    2)    Build the eVC 4.0 MFC project and copy the executable to the appropriate location on the device using Remote File Viewer from Visual Studio 2005.

    3)    Create a dummy project on Visual Studio 2005 (this must be an executable project) for the correct WM 5.0 platform.

    4)    In VS 2005, open the project properties page and navigate to the Debugging page. Set the Remote Executable to the eVC 4.0 application using the macros to specify the target directory.

    ProjectDebuggingProps 

    5)    F5 and things should just work.

    There are other variations of this approach that will also work, but this should essentially enable you to continue development on the MFC 3.0 applications and target WM 5.0.

    That brings us to the second aspect of the upgrade. Will the MFC 3.0 application work as expected on WM 5.0 with no recompilation or upgrade to the newer tools? Will the upgraded MFC 8.0 application work exactly like the MFC 3.0 application on WM 5.0? From an official point of view, MFC 3.0 on WM 5.0 is not a recommended scenario and we strongly recommend upgrading to the newer MFC 8.0. However, as I stated above, there might be considerations because of which you might want to continue with the MFC 3.0 application. The WIN CE operating system strives to achieve application compatibility at the binary level and things should work as expected. In reality though, there will be breaking changes which could cause your application and the libraries to not work making our task harder. We have also tried to make sure that the MFC 8.0 API is as close to the MFC 3.0 set while at the same time trying to unify the programming model between the desktop and the device. These considerations are often at the opposite ends of the spectrum and while we have achieved a sembalance of balance, it is likely that some applications are more painful to upgrade than others.

    In the next blog, I will be talking about runtime issues of MFC 3.0 on WM 5.0 which will need to be understood to get the application working as expected. Hopefully, you should be able to upgrade and build your application with MFC 8.0 on Visual Studio 2005 and if you have any issues, you can use the Smart Devices Forum (http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=35) to post your queries and get going.  

  • Developer Tools - My history

    I am Sadagopan, a development lead in the Visual Studio for Devices team owning among other things the Native and Managed IDE story for devices. I was in the Visual J# team previously and you can say that development tools and programming paradigms including the Drag-n-Drop RAD VB methodology are something I am deeply interested in. I will be talking about most of these areas in the coming few months/years.

    When I started off programming (a little over 12 years ago in school for my under-graduation), my IDE was comprised off 3 disparate pieces, Emacs as an editor, a command line compiler gcc and finally a set of printf statements for debugging my application (okay, those were pretty small applications that did nothing really useful, but...). As I graduated, I learnt to use gdb integrated into emacs and that was better though the command line interface into the debugger was not very user-friendly. But, there was no nice way of writing programs easily and debugging was hell - you were lucky if it worked right the first time else you can forget the nice long weekend or sneak off for a movie before the assignments were due.

    Grad school was a little different - you had to get a little savvy if you wanted to debug your implementation of XINU on DEC stations. I learnt to use the debugger more effectively and other debugging techniques like asserting in the programs and good logging. It was then my research work took me into the world of Java programming and I can say it was pretty boring and too easy. I still used the good old emacs editor with syntax coloring which was pretty neat.But as far as I was concerned that was just "syntactic sugar" to my editor.

    I joined MS in 1999 as a developer in the Windows Base OS group. And the first tool that I was introduced to was kdb - the mother of all debuggers. It teaches you Zen like patience and in addition also lets you peek into the bowels of the NT kernel - not very appetizing before dinner, I assure you (Windbg has kernel mode extensions and is somewhat more user-friendly though). This was the time I also got introduced to Visual Studio to write C++ MFC based applications. In two days, I was hooked (and finished with the skeleton of my application as well). After trying out various macho(istic) tools, I was finally at home. The syntax coloring and the intellisense support with F1 help was pure manna from heaven. It was then that I realized what "IDE" stood for!!!

    Well, to cut a long story short, I moved to the J# team in the middle of 2000 and was with them till as recently as April 2005. I worked on the libraries that we shipped with J#, then with the compiler, then with the IDE team essentially covering all angles of development with J#. It was here that I learnt the value of engineering processes in development and the importance that tools played in them. In addition to cordbg and the mixed mode debugging of Visual Studio, there were a suite of tools that improved the product quality. The complexity (and in some ways the flexibility) of C++ gave way to a more structured approach to programming in C#, VB .NET and J#. The C++ compiler accomodated static analysis through PREFAST and FxCop did the same for managed code.

    One might wonder if all I did at Microsoft and earlier was debugging (with all the stories about the number of bugs in MS products floating around, I really dont want to add to the fire :-), but that was one tool that really affected my productivity. When I moved into the IDE team for J#, I really started to see the entire IDE space and the amount of effect that it has on the entire software lifecycle of an application.

    Microsoft development process in the developer division group are medium-large scale (compared to the mammoth Windows platform environment for example, it is rather puny :-). There was a development process followed here where code was organized into a structure and individual products in Visual Studio were kept seperate by the simple mode of using different directories. Everything was command-line driven to help with automation including our test harnesses which guaranteed minimum quality of the daily build. That worked well since all processes were end-end driven from the command line. If I look at Visual Studio Team System today, it brings some of the power that we have with our internal development environment in a more usable intuitive way for all the roles and phases in the Software development cycle.

    Software engineering has become much more complex than it was a few years ago. Development has grown beyond the space of just writing good code for a product. The issues faced by development teams are extremely diverse depending on the role of the individual in the team and the phase of the product in question. Marketing needs to gather customer requirements and put them in a form from which technical feature specifications can be written. Once the feature specifications are written, architects need to design the architecture of the system and then individual feature teams carry out the implementation and sign off on the feature followed by integration testing before deploying into the customer hands. The product is then maintained and customer requests are integrated back into the product. As you can see, I am simplifying the process involved and looking at only the high-lights of the entire software life-cycle. But, even here one can easily begin to appreciate the complexities involved. It requires an extremely integrated framework to pull all these pieces together so that there can be the required amount of interaction and feedback between the various phases but at the same time respects the differences between them.

    Visual Studio in my opinion tries (remember that the keyword is 'tries' - we have made significant inroads but there is tons left to do in the future) to address these issues in a completely integrated fashion. There is a plethora of tools in the box (not in the Toolbox window though :-) that help development teams to stay connected and improve their productivity depending on the role that they are in. If you are a software architect, there are tools like the Class Designer that help you look at the high level of the system. As a developer, there is the familiar Visual Studio environment with a larger assorted bag of tricks like the static analysis tools and the enhanced editor features like Smart Tags and better Intellisense (just does not have the sense to shut up when I want it to though - telepathy would help :-). The unit testing framework ensures that features that are checked in meet the required quality bar. Integrated also is the source control system Hatteras and the Currituck Issues Database for manegerial types like myself to keep track of the status of the project and do precious little else :-) Team Build deserves a special mention for integrating all these together to provide an easy build system for product teams to automate their build process. Product packaging in the form of Click once and the deployment project system help in building that package around your product easily.

    Well, that sounded like an advertisement for Visual Studio Team Suite, didn't it? But, as I stated earlier, I am really excited to be part of this space and I can go on talking about this forever. After all, what could be better than to be part of a group whose customers include myself. What VSTS envisages is stupendous and mind-blowing and we have not even scratched the surface with what is in VS 2005.

    The product itself is huge comprising of a number of different teams working towards a common integrated development environment. In some sense that itself is an engineering marvel - pulling together teams with different customers, different goals and priorities for their individual customers into one release. I know and accept that things can be better in terms of bringing this innovation to the market faster and in a more sustained way, but a larger ship does take a little longer to turn and we will turn. There are lots of people like me who recognize this problem and are actively working towards a solution and when we do, I think we will be able to even incorporate some of the lessons that we learnt back into our tools creating a stronger eco-system around our platforms. While, it will not be possible for me to cover all the areas, I am going to pick one area at a time that I personally think is changing the way we think about development and talk about how VS addresses this and what can be done further in the future.

This Blog

Syndication

Tags

No tags have been created or used yet.

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker