marți, 13 decembrie 2011

The refactoring could not be performed due to build errors

There is a quirk in Visual Studio 2005 which prevents refactoring when a warning CS1699 is issued. More specifically, ine of the projects in my solution was issuing warning CS1699 :
Use command line option '/keyfile' or appropriate project settings instead of 'AssemblyKeyFile'
and it was not until I solved this error by commenting the AssemblyKeyFile line in the AssemblyInfo.cs file that the refactoring ( encapsulating a field ) started to work once again. You can see more details about this warning here:
The error is confusing since it says that one of the projects in the solution does not currently build, which is false since this is solely a warning.

duminică, 6 noiembrie 2011

Can you see with your tongue?

Can You See With Your Tongue?
Seeing with your tongue may indeed happen to a certain level because of a property of the brain called "plasticity" which is in fact the ability of a brain region to interpret sensors from different sources and adapting itself to them such that for instance it is possible to "see" using our auditory cortex.
This plasticity of the brain may allow humans to enhance their senses in a way that may be a little scary to imagine right now and would be more or less associated to science-fiction. However, this is a road in defining what and who we are and understanding how the sensory, cognitive and emotional interleave.
The more answers we have, the more of this behavior we can replicate in machines. This is a long and open matter of discussion, which I think will represent the challenge of this century. Having thinking machines will mean a great shift in how we see society in the present days and it's hard to grasp at this point.
Meanwhile, noteworthy discoveries in how the brain works are the foundation bricks to an uncertain building.
So, can you see with your tongue?

sâmbătă, 17 septembrie 2011

Res2Res Error Adding Resources

Upon compiling a new OS design for the Device Emulator, the following error may occur during Sysgen:

ERROR: Res2Res: Res2Res:  ERROR: Line: 267  File: c:\ce1\tools\ostools\wincetools\rescommon\checksum.cpp
ERROR: Res2Res: Res2Res:  ERROR: Line: 267  File: c:\ce1\tools\ostools\wincetools\rescommon\checksum.cpp
Res2Res: Error adding resources (-1)
NMAKE : fatal error U1077: 'res2res' : return code '0xffffffff'
NMAKE : fatal error U1077: 'C:\WINCE600\sdk\bin\i386\nmake.exe' : return code '0x2'


The same issue may provide the following error code: Res2Res: Error adding resources (110) NMAKE : fatal error U1077: 'res2res' : return code '0x6e' Stop. NMAKE : fatal error U1077: 'C:\WINCE600\sdk\bin\i386\nmake.exe' : return code '0x2' Stop.

To solve the res2res related error, I have opened the project property pages and chose not to localize the build. I have also cleared all locales and only selected the English(United States) locale.

atls.lib Error when Building Device Emulator OS

When building a Device Emulator OS design project, it is common to receive an error in the build process that refers to atls.lib. Visual Studio simply writes BLDEMO: There was an error in the build process. The true cause of the error is found in the build.log file, typically located in C:\WINCE600.
At the end of the build.log file, the following lines point to the error cause:
NMAKE : fatal error U1073: don't know how to make 'C:\WINCE600\OSDesigns\OSDesign1\OSDesign1\Wince600\DeviceEmulator_ARMV4I\cesysgen\oak\lib\ARMV4I\retail\atls.lib'
NMAKE : fatal error U1077: 'C:\WINCE600\sdk\bin\i386\nmake.exe' : return code '0x2'
To solve the build error, the Active Template Library needs to be included in OS using the  Catalog view. Just type ATL in the Catalog view search bar and check the "Active Template Library(ATL)" entry.
After adding the reference to ATL, run the Sysgen build command to generate the OS image.

joi, 15 septembrie 2011

Debug Windows CE Applications Via TCP/IP

It is sometimes required to debug application on Windows CE devices without an ActiveSync connection, but over TCP/IP. In order to enable debugging using Visual Studio 2005, a few setup steps are required.
1. Create a OS image or copy the files listed below in the \Windows folder. It is more convenient to create a OS image in the case that Windows CE is loaded in RAM and the copied files would be deleted upon a subsequent restart. These files can be typically found in C:\Program Files\Common Files\Microsoft Shared\CoreCon\1.0\Target\wce400\<Target CPU>, where target CPU can be for instance armv4i. There you will need to find these files:
- clientshutdown.exe
- ConmanClient2.exe
- eDbgTL.dll
- TcpConnectionA.dll

2. In Visual Studio, navigate to Tools|Options|Device Tools|Devices. Select the "Windows CE 5.0 Device" from the list of devices and click Properties.
3. In the Properties window, select TCP Connect Transport under Transport and then click Configure.
4. Under Configure TCP/IP Transport, select the IP address of the device. In my case this is Click OK to close this window and the other windows and return to Visual Studio.
5. On the device side, open the command prompt, change the directory to \Windows were you have already copied the files specified on step 1 and execute ConmanClient2.exe. After that, execute CMAccept.exe. Alternatively, you can open the Windows folder using Explorer and double click on these files in the specified order.
6. Within three minutes of performing these steps, connect to the device using Visual Studio - that is, start debugging your application against the Windows CE environment.

That's it, you are ready to go!

miercuri, 7 septembrie 2011

Activate and Configure RNDIS for Windows CE Based Devices

To activate RNDIS and communicate over TCP/IP with the Windows CE based device from Windows 7, I had to follow these steps:
1.      Modify the key [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\DefaultClientDriver] to RNDIS.

2.      Save the registry modifications and restart the module.

3.      In Windows, ActiveSync will no longer work and a generic RNDIS device will be listed in Device Manager,under Unknown Devices.

4.      Right click the generic device and select to install a driver.

5.      In the next window, select “Browse my computer for driver software”:

6.      In the next window, select “Let me pick from a list of device drivers on my computer”:

7.      In the next window, select Network Adapters from the Common Hardware Types list and click Next.

8.      In the Select Network Adapter window, select Microsoft Corporation and from the list on the right, Remote NDIS Compliant Device. Click Next.

9.      You will get a warning message; you need to ignore it and install the new driver. After installation the RNDIS device will be listed under Network Adapters in Device Manager.

10.      On the PC side, in Network Connections, right click on the new adapter and assign it a new IP address, typically: with mask Leave the other fields blank.

11.      In Windows CE, open Settings->Network and Dial-Up Connections and double click on the RNDIS adapter. Assign a new IP address, typically with mask Leave the other fields blank.

12.      Now test communication between the PC and the Windows CE device by pinging the device’s address.

            Important Note: In this setup, Active Sync will no longer work. It can only be restored by modyfing the [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\DefaultClientDriver] back to its original value (Serial_Class).

marți, 6 septembrie 2011

Exception messages in .NET Compact Framework

The .NET Compact Framework team decided not to include libraries that contain error message strings by default since these would occupy more space and are in most cases not meant for the end users.
As developers, we need to these messages for debugging purposes, specially when we are not using Visual Studio. Whenever an exception occurs, the log entry for it would look like this: "An error message cannot be displayed because an optional resource assembly containing it cannot be found". This post of the .NET Compact Framework team explains what we need to do in order to enable descriptive exception messages on our Windows Mobile/ CE based device.
Basically what you need to do is copy the System_SR_[Language].CAB  file from your computer to the device and then double click it to install the .cab. If your language of choice is English, you need to copy the, installed by default in C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\Diagnostics.
After installing this .cab file on the mobile device, you will start seeing descriptive exception messages, that are far more helpful.

Learn more on overall Compact Framework development in C# from Programming .NET Compact Framework 3.5 (2nd Edition) by Paul Yao and David Durant.

sâmbătă, 13 august 2011

joi, 4 august 2011

Ignore Enter Key Press for .NET Button

According to the documentation found on MSDN, "A Button can be clicked by using the mouse, ENTER key, or SPACEBAR if the button has focus."
It took a while until I have found how to disable the Enter and Spacebar keys to produce the Click event for a form button that has focus. The solution is to override the ProcessCmdKey method in a derived class and catch the Enter key press in that method and return before it gets to be processed by the method in the Button base class. Here is the basic class I used to accomplish this.

/// <summary>
/// A class that inherits the System.Windows.Forms.Button class and ignores
/// the ENTER key press that also triggers the click event.
/// </summary>
internal class ButtonNoEnter : System.Windows.Forms.Button
    protected override bool ProcessCmdKey( ref Message msg, Keys keyData )
       if( keyData == Keys.Enter || keyData == Keys.Space )
            return true;
      return base.ProcessCmdKey( ref msg, keyData );

vineri, 27 mai 2011

Word 2007 Registry Policy Settings

Having to open older versions of Microsoft Word files is prevented by default in Microsoft Windows 2007 by means of registry settings. There is a support article published by Microsoft that describes how to disable this limitation. ( ). The purpose is to add a new registry key with the name FileOpenBlock and then create a new entry under this key, named FilesBeforeVersion and assign it the value 0.

I wanted to fix the solution myself and tried to locate the registry key specified in the article, but was unable to locate it. Here is where they claim it would be:
and here is where I actually found it:
Other than the minor error in the article, I was able of fixing the issue and of opening older file versions.
I am using Windows 7 Professional 32 bit.

duminică, 8 mai 2011

Accept this license agreement

Upon installing Visual Studio 2005 I was politely presented a license agreement, partly English, partly something else !?

joi, 14 aprilie 2011

Subversion: Get the modified files between two revisions

There is a simple command to get the modified files between two revisions in subversion. All you have to know are the two revision numbers and the path to the repository folder:

svn diff -r revision1:revision2 --summarize URL

or if you want to list the files modified between an older revision and the head revision, type:

svn diff -r revison:HEAD -- summarize URL

If you do not type summarize you will also get to the console output all the differences between the two revisions.
Example: I need to see which files have been modified since revision 3880:

svn diff -r 3880:HEAD --sumarize svn://mysvnserver/repository/somefolder
The svn diff command is more complex, so you can get more details here:

joi, 31 martie 2011

Serialize an array to XML in .NET Framework

Well, this is not too much of a big deal since with a little knowledge about Serialization you will be able to figure this out quite rapidly. I only thought of posting this here since I had in mind the issue of converting an array of (string) values into an XML format and then have it deserialized at a later time when I would have need the array again. For this purpose I used the XmlSerializer class and the MemoryStream class.
The example code I give below shows how to convert a string array to XML and then how to deserialize it from the XML format into a new array.

public static void SerializeDeserializeArray( )
    string[ ] strArr = new string[ ] {
        "C:\\Program Files\\myFile1.txt",
        "C:\\Program Files\\myFile2.txt",
        "C:\\Program Files\\myFile3.txt"

    MemoryStream memStream = new MemoryStream( );
    StreamWriter sw = new StreamWriter( memStream );

    XmlSerializer ser = new XmlSerializer( typeof( string[ ] ) );
    ser.Serialize( sw, strArr );

    StreamReader sr = new StreamReader( memStream );

    memStream.Position = 0;
    string str = sr.ReadToEnd( );

    memStream.Position = 0;
    string[ ] deserArr = (string[ ] )ser.Deserialize( memStream );

    if( deserArr != null )
        foreach( string s in deserArr )
            Console.WriteLine( s );

    Console.WriteLine( );

miercuri, 16 martie 2011

Error C2872 ambiguous symbol

I was trying to compile one of my C++ projects and ran into this error:

Error 1 error C2872: 'IServiceProvider' : ambiguous symbol C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\ocidl.h 8005

Among other files in the project, I had a header file which started like this:

using namespace System;
#include "MyHeader1.h"
#include "MyHeader2.h"

After a little research I have found the cause of this error. I turned on the /showIncludes option of the compiler and saw that one of my headers was actually including the "ocidl.h" file. The Build output will show, among others:
2>Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcomcli.h
2>Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\olectl.h
2>Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\pshpack8.h
2>Note: including file: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\ocidl.h

In order to fix this compile time error, I moved the using below the #include as below and it all started working again:
#include "MyHeader1.h"
#include "MyHeader2.h"

using namespace System;

joi, 17 februarie 2011

Passing an array to a function in C++

In C++ you if you want to modify an array inside a function, you should not return a pointer to it from within the function as this pointer will be out of scope when the function execution ends. You need to make sure that you allocate the array before passing it as a parameter:

int* buffer = new int[ BUFFER_SIZE];

arrayProcessing( buffer, BUFFER_SIZE );
#ifdef _DEBUG
DisplayBuffer( );

where arrayProcessing is defined like this:

int arrayProcessing( int* buffer, int size )
// TODO: modify elements of buffer.

miercuri, 12 ianuarie 2011

How to open a .pdf or .txt file in C#

This is a simple question, with a very simple answer. I've been asking it myself and seeing other people ask it. A solution is to use the System.Diagnostics.Process.Start( ) method.
According to MSDN, using this method is very similar to typing the file's name in the Run dialog box of the Windows start menu.
For instance, if you have a .pdf file that you want to open, just use:
System.Diagnostics.Process.Start( "myfile.pdf" );
You can follow this link for more information:

For a text file, you can use the above method, or if you want to specifically open it with notepad you have to use:
System.Diagnostics.Process.Start( "notepad.exe", "myfile.txt" );