DHCP Server: Flexible IP address ranges, GUI improvements

Welcome update in Alax.Info DHCP Server to provide flexibility in IP address allocation ranges and more features.

The application does not require that IP address block is a single range of addresses. While this is still cool for simplicity, some guys out there have really huge networks with specific requirements. From now on, an “advanced” links opens an additional opportunity to:

  • define multiple blocks of IP addresses to get from
  • opportunity to provide exclusion addresses, ranges and even wildcards

The syntax is straightforward:

  • one range per line, x.x.x.x-y.y.y.y
  • optional exclusion list following in brackets
    • excluded items are separated by comma
    • excluded item may be a single address x.x.x.x, range x.x.x.x-y.y.y.y or a wildcarded address/range x.x.*.x-y.y.*.y

Additionally, it is possible to include DNS Domain Name (option 15) with the DHCP responses:

The GUI makes it clear that it is possible to provide multiple addresses using comma separation. While this was possible before UI did not make it clear enough.

More to this,it is possible to export lease list into clipboard in comma-separated value (CSV) format and transfer data into, e.g. Microsoft Excel:

Updated Alax.Info DHCP Server is cooler and fancier at the same unbelievable price: free for personal use, commercial license for premium features, non-personal use and technical support.

Utility Clearance: Automatic Snapshots

Automatic Snapshots runs as a background application monitors clipboard. Should a new image be copied there, the utility automatically writes the image into a file. The process does not require any user interaction and is completely automatic so that – per Mike Westen‘s request – user could quickly and easily create snapshots of a multitude of windows (Alt+Print Screen) or full screen images (Print Screen) using standard hotkeys.

Features:

  • Automatic PNG compression (can be disabled via registry and enable BMP mode)
  • Reduction of color depth to create smaller PNG files
  • Asynchronous processing, the compression and file writes are on background thread to not slow foreground application
  • Application window flashes on application bar while busy and indicates the status via window caption
  • Application appends current foreground window caption to the image file name

A binary [Win32, x64] and Visual C++ .NET 2010 source code are available from SVN.

Your ATL service C++ project might need some extra care after upgrade to Visual Studio 2010

If you dare to convert your C++ ATL Service project created with an earlier version of Visual Studio to version 2010, as I recently did, you might find yourself surprised with why the hell the bloody thing does not work anymore as a regular executable.

After passing compiler/linker and SDK update issues, which you possibly might have too, the started executable will stumble on ATL error/exception with CO_E_NOTINITIALIZED (0x800401F0 “CoInitialize has not been called.”). Luckily the error code is good enough for quickly locating the problem and the reason is that the one you trusted, that is ATL, introduced an small improvement which is good for running as service but it not initializing COM anymore if you run your .EXE in application mode.

The bug is on MS Connect since August 3, 2010 closed as if it is going to be fixed some time in future when the fix is propagated to end developers. If you are in a rush and would like to write some code before the event, here are the details.

Previously, COM was initialized right in module constructor, in CAtlExeModuleT. CAtlServiceModuleT class just inherited from there. Later on, someone smart decided that it was not so cool and moved initialization to a later point into CAtlExeModuleT::WinMain. Well, this makes sense as you might (a) end up not needing COM at all, or (b) you want to do some important things before even initializing COM.

Unfortunately, the fact that CAtlServiceModuleT is inherited and relies on base class was not paid too much attention. CAtlServiceModuleT is not getting COM initialization from constructor any longer, CAtlServiceModuleT::WinMain is overridden in full and does not receive initialization from new location either. So well, it does not receive it at all unless run as service, which code execution branch looks still heatlhy here and exhibits another issue later soon.

To resolve the problem, the fragment in CAtlServiceModuleT::Start needs the correction as shown below (within #pragma region):

        if (::StartServiceCtrlDispatcher(st) == 0)
                m_status.dwWin32ExitCode = GetLastError();
            return m_status.dwWin32ExitCode;
        }

        // local server - call Run() directly, rather than
        // from ServiceMain()
        #pragma region Run wrapped by InitializeCom/UninitializeCom
        // FIX: See http://connect.microsoft.com/VisualStudio/feedback/details/582774/catlservicemodulet-winmain-coinitialize-not-called-800401f0
#ifndef _ATL_NO_COM_SUPPORT
        HRESULT hr = E_FAIL;
        hr = T::InitializeCom();
        if (FAILED(hr))
        {
            // Ignore RPC_E_CHANGED_MODE if CLR is loaded. Error is due to CLR initializing
            // COM and InitializeCOM trying to initialize COM with different flags.
            if (hr != RPC_E_CHANGED_MODE || GetModuleHandle(_T("Mscoree.dll")) == NULL)
                return hr;
        } else
            m_bComInitialized = true;
        m_status.dwWin32ExitCode = pT->Run(nShowCmd);
        if (m_bComInitialized)
            T::UninitializeCom();
#else
        m_status.dwWin32ExitCode = pT->Run(nShowCmd);
#endif
        #pragma endregion 

        return m_status.dwWin32ExitCode;
    }

Going further from there, the introduced optimization also removed COM initialization from main process thread module Run function. Provided there earlier too through module constructor it is not longer there. So if you are doing something in application’s run when the application is set to run as service and is executed in application (where you might want to start application as a sort of a helper, or otherwise in specific mode), you need COM initialization there too.

Continue reading →

If your application is looking for network adapters, it may be blind to see

A really long and annoying troubleshooting of a problem finally ended with a bug found in GetAdaptersInfo/GetAdaptersAddresses API.

It may unexpectedly fail under the following conditions:

  • 32-bit application
  • 64-bit operating system or /3GB feature enabled on 32-bit operating system
  • hosting process is linked with /LARGEADDRESSAWARE flag or has otherwise set it in binary header
  • over 2GB of RAM (in terms of Private Bytes/Virtual Size performance counters) consumed by the hosting process

The application might unexpectedly start getting ERROR_NO_DATA (232) or ERROR_NOACCESS (998) error codes instead of list of adapters. Supposedly, the responsible Microsoft component iplhlpapi.dll or one of the underlying components/APIs are incompatible with such environments (such as for example, treating 32-bit pointer with the most significant bit set as invalid or compares such pointers as signed values).

A test Visual C++ .NET 2010 application is available from SVN. More bug details on Microsoft Connect.

NOTE 1: You need to run “GetAdaptersAddressesTest /regserver” once to register the app before running it for the test.

NOTE 2: The problem does not seem to take place with 32-bit operating systems with /3GB tuning enabled.

Utility Clearance: Enumerate VCM Codecs

EnumerateVcmCodecs uses ICOpen API to enuerate available codecs and prints out information obtained from enumeration. 32-bit and 64-bit versions respectively enumerate codecs available for the platform (lists may vary because the codecs are actually provided by different DLLs, built for respective platform).

szName
  fccType: 0x63646976 (vidc), fccHandler 0x64697663 (cvid)
  dwFlags 0
  dwVersion 0x0, dwVersionICM 0x104
  szDescription ""
  szDriver "iccvid.dll"
szName
  fccType: 0x63646976 (vidc), fccHandler 0x30323469 (i420)
  dwFlags 0
  dwVersion 0x0, dwVersionICM 0x104
  szDescription ""
  szDriver "msh263.drv"
...

A binary [Win32, x64] and Visual C++ .NET 2010 source code are available from SVN.

See also:

Utility Clearance: Rasterize Font

RasterizeFont utility takes a font on the input (such as Windows .TTF – True-Type Font) and paints individual characters into bitmaps. Utility output includes separate bitmap (.BMP) files for requested characters and C++ source code of the bimap arrays (this was included into microcontroller project).

A configuration .INI file defines rasterizer parameters:

[General]
Width=48
Height=72
Horizontal Adjustment=1
Vertical Adjustment=0
Outline=1

[Font]
Face=Times New Roman
Height=48
Weight=1024

[Bitmaps]
PathTemplate=Character-%04x.bmp

And a list of characters of interest is passed as a command line argument.

const BYTE pnCharacter007a[] = // 0x007a z
{
    0x55, 0x55, 0x55,  // 01 01 01 01 01 01 01 01 01 01 01 01 
    0x55, 0x55, 0x55,  // 01 01 01 01 01 01 01 01 01 01 01 01 
    0x55, 0x55, 0x55,  // 01 01 01 01 01 01 01 01 01 01 01 01 
    0x54, 0x00, 0x05,  // 01 01 01 00 00 00 00 00 00 00 01 01 
    0x52, 0xaa, 0xa1,  // 01 01 00 10 10 10 10 10 10 10 00 01 
    0x52, 0x00, 0xa1,  // 01 01 00 10 00 00 00 00 10 10 00 01 
    0x54, 0x42, 0x85,  // 01 01 01 00 01 00 00 10 10 00 01 01 
    0x55, 0x2a, 0x15,  // 01 01 01 01 00 10 10 10 00 01 01 01 
    0x54, 0xa0, 0x45,  // 01 01 01 00 10 10 00 00 01 00 01 01 
    0x52, 0x80, 0x21,  // 01 01 00 10 10 00 00 00 00 10 00 01 
    0x52, 0xaa, 0xa1,  // 01 01 00 10 10 10 10 10 10 10 00 01 
    0x54, 0x00, 0x05,  // 01 01 01 00 00 00 00 00 00 00 01 01 
    0x55, 0x55, 0x55,  // 01 01 01 01 01 01 01 01 01 01 01 01 
    0x55, 0x55, 0x55,  // 01 01 01 01 01 01 01 01 01 01 01 01 
};

A binary [Win32] and Visual C++ .NET 2008 source code are available from SVN.

Utility Clearance: Export AVI Resources

ExportAviResources walks through AVI video clips attached as resources to a binary file and exports them into separate files.

Such clips can be used with Animation Controls for GUI animations. You might want to run the utility against SYSTEM32/SYSWOW64 folders to see if any of stock animations are good for you:

D:\>for %i in (C:\Windows\system32\*.dll) do "..\Utilities\ExportAviResources\x64\Release\ExportAviResources.exe" "%i"

A binary [Win32, x64] and Visual C++ .NET 2010 source code are available from SVN.