2007-11-24

Windows Time Sync

Sometimes you need to know if your computer has the correct time, what do you do to ensure that?

On Windows XP you double click on the clock in the right corner of your screen select "Internet Time" and click "Update Now". All the times I did this I got an error. Windows has only two entries in that combobox, and both return errors, why?!

Today I have gone a step further I googled for more Internet Time Servers, on this page I've found plenty. For example Germany has 214 servers in a time server pool (de.pool.ntp.org).

It was about time ;-)

2007-11-10

New Updates to MFC in Visual Studio 2008

Here is an half an hour interview with Pat Brenner on the topic "New Updates to MFC in Visual Studio 2008".

A very informative movie, my favorite quote is "we kinda moved out from the '90s"!

And a quick summary:

What's new for MFC developers:
  • Ribbon

  • Customisable Menubar / Toolbar

  • Visual Studio 2005 like Docking

  • Tabbed MDI

  • New status bar

  • and many more



  • You can get a full visual tour on what's new on the Visual C blog entry.

    Here is a screenshot of MFC demo made by the Wizard:




    All this functionality is available now from 3rd party vendors, but this will be backed by Microsoft. Impressive!

    Edit MFC Update powered by BCGSoft as you can read here.

    Y!M 9.0 Without Ads

    One way to disable the ads from the main window of Yahoo Messenger 9.0 is to cut access to one specific file. With this version it doesn't work any more the trick of clearing the file and making it read only.

    If you have installed Y!M on a NTFS file system you are lucky, you can remove the Read security attribute and the ads are gone (at least until they fix this too).

    Here is the code to remove the access to the file from the command line, or batch file:
    cacls "%PROGRAMFILES%\Yahoo!\Messenger\Cache\urls.xml"  /E /P %USERNAME%:N


    If you want to bring the ads back because they were adding color to your contact list here is the command line to do just that:
    cacls "%PROGRAMFILES%\Yahoo!\Messenger\Cache\urls.xml"  /E /P %USERNAME%:F


    I hope they won't read this blog and fix the hole until the final version 9.0 gets out next year ;-)

    Edit: by upgrading to version 9.0.0.907 I found out that removing reading rights from the file was not enough, you need to fiddle with the Windows Registry e bit. Here is a batch file that does it for you:

    @ECHO OFF
    TITLE Remove ads from Yahoo Messenger 9

    > %TEMP%.\noYMads.reg ECHO REGEDIT4
    >>%TEMP%.\noYMads.reg ECHO.
    >>%TEMP%.\noYMads.reg ECHO [HKEY_CURRENT_USER\Software\Yahoo\Pager\YUrl]
    >>%TEMP%.\noYMads.reg ECHO "First Login Beacon"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Change Room Banner"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Finance Disclaimer"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Messenger Ad"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Chat Adurl"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Calendar Alert Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Conf Adurl"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Mail Alert Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "News Alert Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Personals Alert Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Stock Alert Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Webcam Viewer Ad Medium"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Webcam Viewer Ad Big"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Webcam Viewer Ad"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Webcam Upload Ad"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Chat Transition Ad"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "N2Phone Adurl"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Webcam Viewer Ad Bid"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "IMVironment Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Auction Alert Ad URL"="noads.html"
    >>%TEMP%.\noYMads.reg ECHO "Login Mobile Ad"="noads.html"
    REGEDIT /S %TEMP%.\noYMads.reg
    DEL %TEMP%.\noYMads.reg

    cacls "%PROGRAMFILES%\Yahoo!\Messenger\Cache\urls.xml" /E /P %USERNAME%:N

    2007-11-09

    Yahoo Keyboard Patch!

    Yahoo! Messenger had a very annoying problem, text selection with Ctrl-A was done when it shouldn't be done.

    For example Windows maps AltGr key to Ctrl-Alt keys combination, which is default behaviour. Yahoo! Messenger treats AltGr-A as Ctrl-Alt-A but then it gets the Ctrl-A part, whole text selection, and afterwards it goes to normal keyboard handling, which with a certain Romanian keyboard layout generates the character "ă", but because the text was selected before, "ă" was the only character left in the sentence you wrote.

    This was very annoying, but then by using the wonderful Microsoft technology called Detours I was able to intercept certain WIN32 API Messages and prevent the text selection from happening. Yahoo! keyboard patch was created.

    Cristian Secară was very nice to host this patch on his webserver, also he made some very good suggestions which improved whole the quality of the software.

    The patch is available at this location (Romanian language only).

    Note: this patch also works with other keyboard layouts, for example the Hungarian default keyboard layout can be used to generate the character "ä" now.

    2007-10-29

    To C or Not to C

    Today I was a bit puzzled by this code (test.c):

    #include <stdio.h>

    int main()
    {
        int i = ceil(2.9f);
        printf("i is: %d\n", i);
    }

    I had compiled the code using the command cl test.c, clean compile no warnings, no messages, after running the program the result was: i is: 1024. WTF?!

    The proper compile command cl /W4 test.c returned this:

    test.c(5) : warning C4013: 'ceil' undefined; assuming extern returning int

    C assumes a bit too much.

    Next time I want to try a code snippet I won't use the .c extension, I'll use .cc, one character makes a big difference:

    test.cc(5) : error C3861: 'ceil': identifier not found


    D'oh, I forgot to #include <math.h>!

    2007-07-13

    Pidgin gems

    Pidgin keyboard shortcuts cannot be edited by using a configuration dialog, but they can be edited "by hand".

    I wanted two actions to remap: closing the conversation dialog with Escape key and show/hide offline buddies with Control-H.

    This can be achieved by editing the ".purple/accels" file, which is located in your home directory on Linux and in "{drive letter}:\Documents and Settings\{user name}\Application Data" on Windows, and inserting the following lines:


    (gtk_accel_path "<PurpleMain>/Buddies/Show Offline Buddies" "<Control>h")
    (gtk_accel_path "<main>/Conversation/Close" "Escape")

    2007-03-29

    CMake support for SciTE

    I have added support for CMake in SciTE text editor. It should be available in the upcoming 1.73 release.

    Here is a picture of a rather small CMake script file:

    2007-02-02

    Eclipse C++ Programming with MinGW

    MinGW brings the powerful (free) GNU C++ compiler to the Windows world. The only drawback is that you get only command line tools, no GUI interface. While this is OK only for small programs, it becomes an issue when you need a debugger and / or the project contains more than one source file.

    That's where Eclipse kicks in. With the CDT plug-in you can edit, compile and debug your C++ programs.

    These are the required downloads (compiler, debugger and editor):
    • MinGW and GDB installers from here (I've downloaded MinGW-5.1.3.exe from MinGW->Current section) and from here for the latter (I've downloaded gdb-6.3-2.exe from Snapshot section)
    • EasyEclipse for C and C++ from here (I've downloaded release 1.2.1.1).

    After creating a C++ project in Eclipse you will notice that there is warning complaining that cygpath is not found, it's a benign warning since we're not using Cygwin to build programs.

    Eclipse expects that g++, make and gdb executables to be in PATH, since I don't like to pollute the global PATH environment variable with MinGW executables I've created a "launcher" for Eclipse that adds MinGW to PATH before running Eclipse.

    Here is the code (eclipse.js):
    var program = "eclipse.exe";

    // Add the arguments
    for (var i = 0; i < WScript.Arguments.length; ++i)
    {
        program += " " + WScript.Arguments.Item(i);
    }

    var shell = new ActiveXObject("WScript.Shell");

    // Add mingw to path
    var env = shell.Environment("PROCESS");
    var path = "c:\\mingw\\bin;";
    path += env("PATH");
    env("PATH") = path;

    // Execute the program and don't wait for completion
    shell.Exec(program);


    Copy the "launcher" to Eclipse directory (c:\Program Files\EasyEclipse for C and C++ 1.2.1.1) and use it from now on to start Eclipse.

    We need one more step to get everything to work, change the C/C++ build command from make to mingw32-make (or rename mingw32-make it to make in c:\mingw\bin, if you want the eclipse project to be crossplatform) like in the picture bellow:


    That was all. Now we have a full C++ IDE. Now we can develop console applications or Win32 C GUI applications. For C++ GUI applications we can use the free (GPL) Trolltech Qt library.

    2007-01-15

    It's not a bug, it's a feature

    In my previous post I've said that I found a C# bug, now I've found out that it's not a bug, that behavior is by design.

    It's written in the C# standard, around page 88 (110 real page):

    [Note: As specified above, the declaration space of a block cannot share names with the declaration spaces of any nested blocks. Thus, in the following example, the F and G methods result in a compile-time error because the name i is declared in the outer block and cannot be redeclared in the inner block. However, the H and I methods are valid since the two i’s are declared in separate non-nested blocks.

    class A
    {
        void F() {
            int i = 0;
            if (true) {
                int i = 1;
            }
        }
        void G() {
            if (true) {
                int i = 0;
            }
            int i = 1;
        }
        void H() {
            if (true) {
                int i = 0;
            }
            if (true) {
                int i = 1;
            }
        }
        void I() {
            for (int i = 0; i < 10; i++)             H();         for (int i = 0; i < 10; i++)             H();     } }

    end note]


    I hate compilers that impose stupid constrains.

    2007-01-10

    My first C# bug

    Consider this piece of code:
    class Foo
    {
        public static void Bar()
        {
            if (true)
            {
                int i = 0;
            }
            int i = 1; // CS0136
        }
        
        public static void Main()
        {
        }
    }


    Any C (C++, Java) coder will say that there is nothing wrong with that code.
    I thought that was the same in C# language, I was wrong.
    Here is the output from Visual Studio .NET 2003:
    test.cs(9,13): error CS0136: A local variable named 'i' cannot be declared in this scope because it would give a different meaning to 'i', which is already used in a 'child' scope to denote something else

    test.cs(9,13): error CS0103: The name 'i' does not exist in the class or namespace 'Foo'

    Here is the output from Visual Studio 2005:
    test.cs(9,13): error CS0136: A local variable named 'i' cannot be declared in this scope because it would give a different meaning to 'i', which is already used in a 'child' scope to denote something else


    While VS2005 got better than VS2003, but it's still in error.

    Here is what MSDN has to say about error CS0136

    Compiler Error CS0136A local variable named 'var' cannot be declared in this scope because it would give a different meaning to 'var', which is already used in a 'parent or current' scope to denote something else
    A variable declaration hides another declaration that would otherwise be in scope. Rename the variable that is declared on the line that generated CS0136.
    The following sample generates CS0136:

    // CS0136.cs
    namespace x
    {
       public class a
       {
          public static void Main()
          {
             int i = 0;
             {
                char i = 'a';   // CS0136, hides int i
             }
             i++;
          }
       }
    }



    Well, in our case i variable was declared after the if block and not before it. It doesn't make any sense to say that the second i is in the if's i scope.

    I know it's a bad practice to reuse the same name for more variables in a function, but I don't expect that to be an error, just a warning at the highest warning level.

    What's sad is that the alternative C# implementation, naming Mono, has the same behaviour. Here is the output:
    test.cs(9,7): error CS0136: A local variable named `i' cannot be declared in this scope because it would give a different meaning to `i', which is already used in a `child' scope to denote something else
    test.cs(7,8): (Location of the symbol related to previous error)


    They've copied Microsoft's implementation bug by bug (for compatibility :). The sad part is that this bug was reported to Mono in 2003 but they've closed it saying it's not a bug. Here is the link to that bug

    By the way I've posted a comment there, just to complain about it :)

    It seems that this is not a bug, but a feature, read more about it here