Thursday, February 28, 2008

It is sometimes said that the reason Soviet Union has produced so many outstanding scientists is that a lot of attention was being paid to introducing kids to science early and in a way that kept them interested. Indeed, a large amount of popular science books has been printed over the years as well as translations made of the best ones offered in the rest of the world. Martin Gardner and Richard Feinman, absolutely fascinating Robert Wood biography, Smullyan, Soviet authors Perelman and Makovetsky - all of those made me fall in love with physics, mathematics, mechanics, chemistry as a kid. And of course these books were fairly accurate as they were either authored or reviewed by respected professionals.

Times change and these days people find that you cannot blindly trust books you buy. Quite recently a very lively discussion took place in one of the LiveJournal communities (very popular in Russia). It was about a book recently printed in Moscow called "Unabridged Encyclopedia of Astronomy". The book that contains 25000 articles, has many entries that make even a casual student of science do a doubletake (some of it could be explained by the fact that the entire author team somehow did not have a single specialist in astronomy or even general physics among them).

Here are some gems (translated from original Russian as closely as possible)

"Gravitational waves - are emitted by electrical charge oscillating in space"

"Barnard star - a stationary star with visual magnitude of 9.5m... Known for being fast-moving..."

"Visible radiation - radiation that is not only visible to the naked eye, but to the special astronomical equipment and devices..."

"Visible light - light being radiated by a heated body..."

"Escape velocity - [is] defined as speed required for a man-made satellite to reach the Earth orbit. Equals 12km/s"

"Galactic Cannibalism (Extragalactic Astronomy) - a part of Astronomy dealing with celestial bodies (stars, galaxies, quasars etc) that exist outside our Galaxy"

"Ultraviolet radiation - radiation emitted by the Sun and stars"

"Interference - wave oscillation produced by the light source generates so called spherical wave fronts"

"Polar Star - the main star L of Ursa Minor constellation and the brightest star of the northern hemisphere"

"Rigel - the brightest star in the constellation of Orion and in the entire sky"

"Lynx - one of the constellations of the southern hemisphere"

"Triton - a constellation discovered by Lassell in 1846. It's mass is calculated at 2.14x10^22 kg"

The next one is tricky. It makes no sense at all in Russian, so be prepared for the same in English translation.

"Phase angle - an angle situated at a distance from the Sun to the Moon as well as from the Moon to the Earth"

"Fundamental Astronomy - modern physical-mathematical discipline growing interdependent with advances in science and technology"

Fortunately, some astute readers (one of them employed by Moscow planetarium - must know her astronomy, eh?) were able to spot it and raise some ruckus. As they were not able to get any response from the publisher, someone suggested to make a formal complaint to the russian authorities, invoking Consumer Protection Act. We'll see how it goes.

Life | Rant | Science
2/28/2008 3:22:35 AM (Pacific Standard Time, UTC-08:00)  #    Comments [3]  | 
 Tuesday, February 26, 2008

Raffaele Rialdi pointed out that attempting to run RTF Host from Compact Framework 3.5 Power Toys on an emulator produces the following error:

This is caused by RTF getting confused because the default CoreCon transport on the emulator is DMA (DeviceDMA.dll). Here are the steps to add emulator as a manual Tcp connection. Not that many will need it, but it is useful for a demo

1. Start Emulator using Device Emulator Manager.
2. Configure Network and Storage card folder
3. Copy to storage card folder the following file: "C:\Program Files\Common
Files\microsoft shared\CoreCon\1.0\Target\wce400\armv4i\TCPConnectionA.dll"
4. In File ExplorerNavigate to \Windows\Corecon1.1. If you don't see it
there, connect to the emulator from Studio
5. Launch ClientShutdown (you should see a guid-named folder to appear)
6. Copy \Storage Card\TcpConnectionA.dll to \Windows
7. Go to \Windows and delete DeviceDMA.dll (if you can't, you forgot to
launch ClientShutdown)
8. Go back to \Windows\Corecon1.1 and launch ConmanClient.exe
9. Launch RTF Host. Enjoy

2/26/2008 6:46:07 AM (Pacific Standard Time, UTC-08:00)  #    Comments [1]  | 
 Saturday, December 29, 2007

Cyberlink was kind enough to let me evaluate the latest version of their PowerDVD Ultra product - about a year ago. Yet I procrastinated. Now, a year later I found myself in posession of a brand-new Media Center machine (does the phrase "Dude, you are getting a Dell" sound familiar?), which is connected to a brand new 1080P Samsung LCD TV. I've slightly upgraded it with an LG GGC-H20L Blu-Ray/HD-DVD Reader and realized, how close I to being finally able to watch HD DVDs on a Media Center machine (instead of Xbox 360). This is where I remembered about Cyberlink generous offer.

After a painless 100MB download (you can buy all of the Cyberlink products electronically, directly on their web site, and depending on the speed of your connection, you will get to install it in 5-10 min), I ran the setup and was shortly rewarded with the activation dialog. I am not big fan of software activation (Windows or any other), but as far as the activation experiences go, this one was seamless and easy.

PowerDVD comes with a companion application called BluRay Advisor (there is also nearly identical HD DVD Advisor). This application checks your system for being ready to play HD content. The last time I ran it a year ago, I got a message saying that my display card was underpowered, my CPU - barely sufficient (P IV 3.6GHz) and my TV entirely unsuitable due to the lack of HDCP support. This time I had a green light on every item, except the video driver - the Advisor did not recognize the driver version and indicated the status as unknown.

My TV uses so called 10' setup, meaning that normally there is no keyboard or mouse connected to it (well, there is a Media Center keyboard, just in case, but I rarely use it). Earlier versions of PowerDVD did not fare well with the Media Center remote, but the current one does not seem to have any problems. I was able to control it perfectly well, except of going into settings and such. For day-to-day needs, such as watching DVD MCE Remote gives you all control you need.

PowerDVD fully supports HD DVD menu system. My experience with it did not differ from Xbox 360 one.

There are few minor annoyances - nothing critical, but I have to mention them:
 - when starting playback, Vista pops a message saying that the application is not compatible with Windows Aero and that Windows will switch into basic mode.
 - I was not able to figure out how to select the disk to play. The machine has a regular DVD drive, an HD DVD drive and a DVD changer. By default the player picks the first of them. I'm sure there is a setting somewhere, but I wish it were more accessible. As it is I have to open Computer window and select the disc I want to play
- The status overlay that's shown in the upper right corner when you are controlling volume, is way too small. From the couch it is nearly impossible to read.

I want to emphasize, that the above list is of really minor issues. The application is very good in every way and does the job of playing DVDs and HD DVDs nearly perfectly. The picture quality is superb, there are no artifacts or playback delays, missed frames and other unpleasant occurences that might mire your viewing experience.

In conclusion I wanted to mention the auto update feature. It is not something new - Microsoft, Adobe, Intel and quite a few others have it. Nevertheless it is gratifying to know that you don't have to check the web site for updates constantly (and who doesn't love updates) - it's done for you.

12/29/2007 4:17:35 PM (Pacific Standard Time, UTC-08:00)  #    Comments [1]  | 
 Wednesday, December 26, 2007

This one has been actually gleaned through a usenet post, but needs a wider coverage

Trying to use dwAlphaConst member of DDOVERLAYFX structure to specify overall overlay transparency results in E_INVALIDARG error

As explained here, there is a clever bug in the parameter checking logic that results in the API soundly rejecting any combination of dwAlphaConst and dwAlphaConstBitDepth, unless dwAlphaConst == 1 << dwAlphaConstBitDepth. This is not fixed as of WM 6 AKU4. Interestingly enough the actual value of dwAlphaConstBitDepth seems to be ... ignored, once the parameter check is done. The bit depth used is always 8 bit.

  • The net result of this bug is that the allowed values for the dwAlphaConstBitDepth/dwAlphaConst and the resulting opacity are
    1/2 - 0.78%
    2/4 - 1.6%
    3/8 - 3.1%
    4/16 - 6.2%
    5/32 - 12.5%
    6/64 - 25%
    7/128 - 50%

Not using DDOVER_ALPHACONSTOVERRIDE gives you of course 100% (opaque overlay). In my experience anything under 5 (12.5%) is too small to be useful, but YMMV. Here is the code snippet:

if ( fUseAlpha )
{
    if ( dwAlpha > 8 ) // Bug in ddraw
        dwAlpha = 8;
    if ( dwAlpha < 8 )
    {
        dwUpdateFlags |= DDOVER_ALPHACONSTOVERRIDE;
        ovfx.dwAlphaConst = 1 << dwAlpha;
        ovfx.dwAlphaConstBitDepth = dwAlpha;
    }
}

12/26/2007 1:50:12 AM (Pacific Standard Time, UTC-08:00)  #    Comments [1]  | 
Call to IDirectDrawSurface::Blt returns E_INVALIDARG

While possible causes for this error are numerous, I wanted to point out a specific one that is not mentioned anywhere: either source or destination rectangle is empty ( zero width or height )

12/26/2007 1:25:03 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 

It's been a while. Things were a bit hectic. Nevertheless I am back.

These days I am working on a rather interesting project involving DirectDraw on Windows Mobile 6. Without going into the project details, I wanted to share some experiences. So far, a number of time I would run into an issue, and of course not it would not be explained/documented/covered anywhere where the Google search takes you. It struck me that I must be not the first one to hit these issues, and if I list them here, chances are that Google search will be more productive for the next poor sod to plow through underdocumented (to put it mildly), convoluted (again, to put it mildly) and unforgiving API such as DirectDraw. I am going to have multiple posts with keywords facilitating search. If a month from now you will find out that I produced all of one post (this one seems to be on track so far. Chances for it not making it are slim), don't judge me too hard. I am away from home for the 3rd week in a row, having missed Christmas, but should be back for the New Year. Ok, here goes.


Call to IDirectDrawSurface::Blt returns DDERR_SURFACEBUSY

The documentation says to check for other threads accessing your surface at the same time. The group search suggests to search for mismatching Lock/Unlock calls. The actual cause turned to be a missed call to IDirectDrawSurface::ReleaseDC (after a successfull call to IDirectDrawSurface::GetDC). If you think about it, internally these calls must be using Lock/Unlock, so cudos to Group search and boo to MSDN documentation

 

12/26/2007 1:20:39 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
 Friday, June 01, 2007

I was quite surprised to learn that apparently I have missed an important new feature of Windows Mobile 6 (Professional)- inking and ink serialization support. Gone are the days when a developer had to tinker with oh-so-temperamental InkX control. Now everyone and his brother can take advantage not only of high-quality precision ink support with smoothing and serialization, but also of handwriting recognition built into Windows Mobile 6 Professional. To quote the documentation - "It provides a rich inking experience, through high quality curve–fitted ink with anti-aliasing, transparent ink, and highlighter ink. It provides an API for Ink collection, data management, rendering, and recognition. It also provides Ink controls to support the note–taking scenario."

Another important feature is interoperability and serialized data format compatibility with ink support on Tablet PC.

While all of this is nice, there is slight bit of bad news - using this rich set of goodies requires C++. There are 2 ways to use ink in Windows Mobile 6 - InkCanvas control and an COM automation library. InkCanvas control offers the ability to use a regular Win32 control (similar to InkX) to write, highlight, collect ink etc via a set of Windows messages. COM automation library on the other hand allows accessing the entire set of features offered by WISP. And there is no managed wrapper for the time being.

As a public service, we at OpenNETCF.com are proud to offer WISPLite managed wrapper. The wrapper offers the entire WISPLite functionality (although not every method of every interface has been tested). There is InkControl class, which wraps InkCanvas, and a OpenNETCF.WindowsMobile.Ink namespace that contains imported COM interfaces. Some of the interfaces do not wrap cleanly, so a bit of coding is needed.

Here is what the demo app looks like (warning, before running it, change line 132 in Form1.cs to be

inkControl1.SetPenStyle((float)trackBar1.Value, penColor, penType); )

Saving ink data to a file:

using (SaveFileDialog fd = new SaveFileDialog())
{
  fd.Filter =
"Ink files (*.isf)|*.isf|All files (*.*)|*.*";
 
if (fd.ShowDialog() == DialogResult.OK)
  {
   
byte[] data = (byte[])inkControl1.GetInkData(IC_INKENCODING.BINARY);
    FileStream stm = File.OpenWrite(fd.FileName);
    stm.Write(data, 0, data.Length);
    stm.Close();
  }
}

Getting ink as bitmap and retrieving recongnition result:

pbPreview.Image = inkControl1.GetInkDataAsBitmap();
lblReco.Text = inkControl1.RecognizedText;

In conclusion I'd like to ask to report problems with this wrapper to this blog's comments.

6/1/2007 2:20:22 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [3]  | 
 Tuesday, April 17, 2007

Sometimes when trying to connect Visual Studio t a device, especially to a custom CE platform, it is helpful to see if there are any problems reported by the CoreCon components on the device side. CoreCon components (ConmanClient, trasnport DLLs, edbgtl.dll and edm.exe) all have an integrated logging facility, which can be used by a developer for troubleshooting.

To enable Corecon debug log you can set the following under HKLM\Software\Microsoft\VSD\Logging

VSD_LogEnabled: DWORD:1,0

VSD_LogToDebugger: DWORD:1,0

VSD_LogToConsole: DWORD: 1,0

VSD_LogToFile: DWORD:1,0

VSD_LogLevel: DWORD - set to at least 4, up to 9

VSD_LogFile: REG_SZ (default VSDLogFile.txt)

Keep in mind that the ConMan log can be quite chatty, so enable it sparingly and only when needed

4/17/2007 12:12:44 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]  | 
 Friday, April 13, 2007

XML-based device configuration is a powerful mechanism of configuring Windows Mobile 2003 and newer devices. There are four ways to provision your device with new settings:

  1. Call DMProcessConfigXML on device. It can be done from native or managed code.
  2. Build a CAB file containing _setup.xml with provisioning XML and run it on the device
  3. Send the xml configuration via WAP push
  4. Use RapiConfig tool shipped with WIndows Mobile SDK (under Tools)

But what if you wanted to perform configuration from your own, PC-based installer? Granted, you could use method 2 and copy the cab over to the device, then invoke wceload etc. Or you could write your own RAPI dll and use CeRapiInvoke. Or perhaps even launch RapiConfig to do this for you. Fortunately there is an easier way. As one could suspect, RapiConfig does not use a complex approach. Rather it benefits from an undocumented but handy RAPI call that is the desktop version of DMProcessConfigXML. It is exported by ordinal (25) and has the same signature as DMProcessConfigXML. Unlike DMProcessConfigXML, the pointer returned by it in the 3rd parameter needs to be freed using CeRapiFreeBuffer.

#pragma comment(lib, "rapi")

STDAPI CeRapiInit();
STDAPI CeRapiUninit();
STDAPI CeRapiFreeBuffer(LPVOID);
typedef HRESULT (__stdcall *CeProcessConfigType)(LPCWSTR pszConfig, DWORD dwFlags, LPCWSTR* ppszConfigOut);

int _tmain(int argc, _TCHAR* argv[])
{
 if ( argc != 3 )
 {
  _tprintf(_T("Usage: rapiconfig <config file> <out file>\n"));
  return 1;
 }

 CeRapiInit();
 
 CeProcessConfigType CeProcessConfig =
   (CeProcessConfigType)GetProcAddress(GetModuleHandle(_T("rapi.dll")), (LPCSTR)25);

 HANDLE hFile = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
 if ( hFile == INVALID_HANDLE_VALUE )
 {
  _tprintf(_T("Unable to open %s\n"), argv[1]);
  goto Exit;
 }

 DWORD cbConfig = GetFileSize(hFile, NULL);
 BYTE* pBuffer = new BYTE[cbConfig];
 if ( !pBuffer )
  goto Exit;

 ReadFile(hFile, pBuffer, cbConfig, &cbConfig, NULL);
 
 LPCWSTR pOut;
 LPWSTR pIn;
 pIn = new WCHAR[cbConfig + 1];
 ZeroMemory(pIn, (cbConfig+1) * 2);
 mbstowcs(pIn, (LPCSTR)pBuffer, cbConfig);
 HRESULT hr;
 if ( FAILED(hr = CeProcessConfig(pIn, 1, &pOut) ))
 {
  _tprintf(_T("Unable to process: %d\n"), hr);
 }

 HANDLE hFileOut = CreateFile(argv[2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
 if ( hFileOut == INVALID_HANDLE_VALUE )
 {
  _tprintf(_T("Unable to create %s\n"), argv[2]);
  goto Exit;
 }

 WriteFile(hFileOut, pOut, (wcslen(pOut) + 1 )* 2, &cbConfig, NULL);

 CloseHandle(hFileOut);
 CeRapiFreeBuffer((LPVOID)pOut);

Exit:
 if ( hFile != INVALID_HANDLE_VALUE )
  CloseHandle(hFile);

 CeRapiUninit();
 return 0;
}

 

4/13/2007 5:43:46 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]  | 
 Sunday, February 25, 2007

Raffaele Rialdi pointed out that attempting to run RTF Host from Compact Framework 3.5 Power Toys on an emulator produces the following error:

This is caused by RTF getting confused because the default CoreCon transport on the emulator is DMA (DeviceDMA.dll). Here are the steps to add emulator as a manual Tcp connection. Not that many will need it, but it is useful for a demo

1. Start Emulator using Device Emulator Manager.
2. Configure Network and Storage card folder
3. Copy to storage card folder the following file: "C:\Program Files\Common
Files\microsoft shared\CoreCon\1.0\Target\wce400\armv4i\TCPConnectionA.dll"
4. In File ExplorerNavigate to \Windows\Corecon1.1. If you don't see it
there, connect to the emulator from Studio
5. Launch ClientShutdown (you should see a guid-named folder to appear)
6. Copy \Storage Card\TcpConnectionA.dll to \Windows
7. Go to \Windows and delete DeviceDMA.dll (if you can't, you forgot to
launch ClientShutdown)
8. Go back to \Windows\Corecon1.1 and launch ConmanClient.exe
9. Launch RTF Host. Enjoy

2/25/2007 6:45:36 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 

Raffaele Rialdi has pointed out that trying to run RTF Host from CF 3.5 Power Toys (required for manual connectivity) on a Windows Mobile emulator produces an error :

This is caused by RTF getting confused and trying to use DMA transport instead of TCP. Here are the steps to establish a manual RTF connection to an emulator (you don't really need it unless you are doing a demo)

1. Start Emulator using Device Emulator Manager.

2. Configure Network and Storage card folder

3. Copy to storage card folder the following file: "C:\Program Files\Common
Files\microsoft shared\CoreCon\1.0\Target\wce400\armv4i\TCPConnectionA.dll"

4. In File ExplorerNavigate to \Windows\Corecon1.1. If you don't see it
there, connect to the emulator from Studio

5. Launch ClientShutdown (you should see a guid-named folder to appear)

6. Copy \Storage Card\TcpConnectionA.dll to \Windows

7. Go to \Windows and delete DeviceDMA.dll (if you can't, you forgot to
launch ClientShutdown)

8. Go back to \Windows\Corecon1.1 and launch ConmanClient.exe

9. Launch RTF Host. Enjoy

2/25/2007 4:55:18 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  |