Monday, December 29, 2008

Modem Error: NO CARRIER

What to check when you get "NO CARRIER" (numeric code: 3) error from Modem:
  • Verify Modem is connected to phone line properly;
  • Verify the phone number you are dialing works properly by calling this number using your phone, and verify that you hear: first ring tone, then the negotiation tone (yes, you should be able to hear the chirping sound over a regular phone);
If you can hear the negotiation tone, but frequently get "NO CARRIER" error, here is a solution:
Set modem register S7 to a longer timeout value. 50 is the default, you can set it to 120 (ATS7=120). Sometimes, you can set this timeout value through MODEM configuration GUI, you can find something like: "Cancel the call if not connected within __ seconds".

Friday, November 07, 2008

Firefox keep crashing -- a solution

Every couple of days, I will see my Firefox using 99% of CPU and crash.

I am a web developer. My Firefox has all sorts of add-ons: Abduction, Firebug, Html Validator, ScapBook, Screen grab!, Web Developer, YSlow. So, I do not need YSlow to know why my Firefox is slow and tend to crash.

I have an idea: how about start two instances of Firefox, one with all the add-ons and the other one clean. I will use the clean one for normal web browsing, and the fully loaded one with development. And, guess what, there is already someone who has done this and posted a blog about it: Firefox: Run a Regular and Development Profile at the Same Time. I used the solution, and it works perfectly.

Friday, September 26, 2008

Blue Screen Trying to Install Windows XP SP3

During last few months, I have been through a couple of Windows XP SP3 installation. They are mostly eventless. One of the worst was a computer that hung after reboot, but after a forced power recycle that system seem to be fine.

Just when I am about to conclude that Windows XP SP3 update is pretty good, I got the famous Blue Screen of Death.

While trying to install Windows XP SP3 on my computer, I got an "Access is denied" error message. So that was not too scary, I typed the error message along with keyword "Windows XP SP3" in Google and found an MSKB 949377 which provided a solution to this exact problem.

Now, following KB 949377, I downloaded full Windows XP SP3 package and subinacl.exe, and created Reset.CMD. But, I tried it 3 times, everytime I ran Reset.CMD, it gave me Blue Screen of Death with error message about registry access. So, I did another Google search with keywords: "windows xp sp3 access denied subinacl registry blue screen". Now "I'm feeling lucky". The first hit provides a solution that works perfectly for me. Here is link to Jason's blog post that solved my problem:

The trick is to remove the HKLM line in RESET.CMD. The new RESET.CMD file would be like this:

cd /d "%ProgramFiles%\Windows Resource Kits\Tools"
REM subinacl /subkeyreg HKEY_LOCAL_MACHINE /grant=administrators=f /grant=system=f
subinacl /subkeyreg HKEY_CURRENT_USER /grant=administrators=f /grant=system=f
subinacl /subkeyreg HKEY_CLASSES_ROOT /grant=administrators=f /grant=system=f
subinacl /subdirectories %SystemDrive% /grant=administrators=f /grant=system=f
subinacl /subdirectories %windir%\*.* /grant=administrators=f /grant=system=f
secedit /configure /cfg %windir%\repair\secsetup.inf /db secsetup.sdb /verbose

Thursday, August 21, 2008

How to Delete Broken Windows Service

As a developer who writes Windows Services, I sometimes get services registered with the source code and executables long gone (because I no longer work on that project). When it finally came the time to cleanup. I found it difficult to remove them from the registry without the original executables.

After a bit of Google, however, I found a useful tool: sc.exe (Service Controller Tool) come with Windows Resource Kit. This command line tool make deleting service very easy, just run:
sc.exe delete [service name]

Notice: the service name for the command line is not the same as "Name" you see in the list (this is usually the "Display Name"). You need to double click the service to open the properties page. And there you will find "Service Name".

Thursday, July 24, 2008

C++/CLI Gotchas

C++/CLI is a hybrid monster. I am very green in the world of C++/CLI. Below are a few very stupid problems I have met.

Example 1: If you are writing unsafe code in C++/CLI with mixed managed code and unmanaged code, it proved to be more dangerous than plain old C++. Here are a few examples of using System::String together with char (C native data type). Without thorough understanding of the new .NET String class will create code that compiles perfectly but return unexpected results to you in run time.

String^ str = "";
char ch = 'a';
str += ch; //result: str="97", instead of "a", because it called ch.ToString()
str = gcnew String(&ch); //result: str="a@#!$%", because &ch is considered to be a string
str = gcnew String(&ch, 0, 1); //result: str="a" as expected.

Example 2: Visual Studio 2005 Debugger is a liar

int i;
... //all the code in between so that you forgot what is defined
for(int i=0; i < 3; i++)
int k = i++; //if you set a break here, Visual Studio Debugger will tell you i=4??!

I agree that the code above is stupid which is an artifact from trying to correct old VC++ code. But Debugger giving a wrong answer wouldn't help!

Monday, July 07, 2008

C++/CLI Warning C4945

Reason: This warning was generated because I referenced multiple C# projects in the C++/CLI project, and they all have "copy local" set to true.

Solution: Change reference to the C# projects, set all "copy local ..." properties to false.

A hotfix is available, which does not seem to be in SP1 as of 7/7/2008. So this fix probably will never be publicly available. This proves again C++/CLI is not on the top of TODO list for Visual Studio team.

Microsoft KB 922271:

Wednesday, May 07, 2008

Convert VC++6 to VC++7 -- (2)

Below is a laundry list of the problems and solutions.

Compiler Error: fatal error C1083: Cannot open include file: 'fstream.h': No such file or directory
Solution: change include from fsream.h to fstream, and add using namespace std;
Related problems: ios::nocreate and ios::noreplace are deprecated. ios::nocreate is replace by ios::in

CFile::ReadHuge() and CFile::WriteHuge() are obsolete. Use CFile::Read() and CFile::Write() instead.

Replace &afxChNil by empty string "".

Compiler Error:
  • error C2059: syntax error : '<'
  • error C2143: syntax error : missing ';' before '<'
  • error C2182: 'ConstructElements' : illegal use of type 'void'
  • error C2988: unrecognizable template declaration/definition
Solution: ConstructElements and DestructElements are deprecated. Remove definition of these functions. Ref: Microsoft KB 318734

WINVER default changed to 0x0501 (Windows XP). If your program still want to support Windows 2000, the the following line must be included in the project:
#define WINVER 0x0400

CPropetySheetEx, CPropertyPageEx are deprecated, they are included back to CPropertySheet and CPropertyPage.

CString s(45) no longer compiles. Because CString is changed to template based function with more constructors. This definition has ambiguous overloaded constructors. Change to CString s((TCHAR)45).

VC++7.1 has stricter type requirements. For example, conversion from HANDLE to int and uint is not allowed.

Compiler Error:
error C2668: 'sqrt' : ambiguous call to overloaded function
sqrt, fabs, log and other CRT math functions support both double and float type now. An integer input to these functions will cause the error above.
int i = 10;
float f = sqrt(i); //error C2688
float f = sqrt((float)i); //compiles ok

Compiler Error:
error C2440: 'static_cast' : cannot convert from 'void (__thiscall XXXXXXXX::* )(void)' to 'void (__thiscall XXXXXX::* )(NMHDR *,LRESULT *)'
Function signature of event handler OnKillfocus was changed from void Func(void) to void Func(NMHDR*, LRESULT*).

Thursday, May 01, 2008

Convert VC++6 to VC++7 -- (1)

VC++6 is a pretty solid product, which can still produce decent software in Windows XP. But Microsoft has decided to stop support for VC6 for about 2 years now. With the arrival of VS2008 and Windows Vista, it might finally be the time to convert those old projects that you still want to keep alive into a newer platform.

To start the conversion is really easy, just open the .dsp file in Visual Studio 2003. It will convert the project for you automatically, and generate the .vcproj and .sln files. If you are lucky, the next step is press F7 to build the solution and press F5 to run it, and you are done. Unfortunately, 90% of us will need to change the code to make it even compile. VC++6 is less standard compliant than VC++7 and there are some other breaking changes in VC++7.

This series will report problems I've seen when I convert a VC++6 project to VC++7 and some tips to help smooth the process.

Tip 1: for a project that is still actively maintained, during the conversion care must be taken so that changes do not break the software under VC++6. Use this to allow the code changes exists peacefully in VC++6:

#if _MSC_VER >=1500
//this is VC++9.0 or above
#elif _MSC_VER >= 1400
// this is VC++8.0
#elif _MSC_VER >= 1310
// this is VC++7.1
#elif _MSC_VER > 1300
// this is VC++7.0
//assume VC++6

Monday, March 24, 2008

ActiveSync Remote Display for Windows Mobile 5.0 Devices

The Problem

"ActiveSync Remote Display" (ARD) version 2.03 does not support Windows Mobile 5.0. If a Windows Mobile 5.0 device is connected to a PC through ActiveSync, when you start the program, you will see a dialog with title: "Remote Display for Windows CE" and error message: "The OS or CPU of this device is unknown to this application". After you click OK,it will show another error dialog and a blank screen.

Work Around

To Enable ActiveSync Remote Display

Go to directory: C:\Program Files\Windows Mobile Developer Power Toys\ActiveSync_Remote_Display\devices\wce400\armv4
Copy the two files to the Windows directory on the mobile device.

To Use the ActiveSync Remote Display

  • Start the ARD program;

  • You will see the same error dialog as before, click "OK";

  • There will no longer be the second error dialog and you will see the screen shown on the PC or laptop;

  • After you are done, click on the ARD icon on the Mobile Device and select exit (if you simply close the remote display on the PC end, the ARD will still be running on the mobile device);

Wednesday, February 13, 2008

Embed Silverlight Streaming in Blogger

I tried to post a video hosted on Microsoft Silverlight Streaming service in the previous post. This post will show you how to embed Silverlight in a Blogger post.

1. Source code to embed the video in Blogger post. Notice, since Blogger tend to insert <br/> for new lines, the Javascript segment has to be on a single line:

<script type="text/javascript" src=""></script>
<script type="text/javascript">function CreateSilverlight() { Silverlight.createHostedObjectEx( { source:"streaming:/[account ID]/MovieTest", parentElement:Wrapper_MovieTest}); } </script>
<div id="Wrapper_MovieTest" style="width: 640px; height: 480px;"></div>
<script type="text/javascript">var Wrapper_MovieTest = document.getElementById("Wrapper_MovieTest"); CreateSilverlight(); </script>

2. manifest.xml (required for Microsoft Silverlight Streaming upload)


3.Movie.xaml (stage layout)

<Canvas x:Name="movieCanvas"
Width="640" Height="480" Background="White" MouseEnter ="mouseEnter"
MouseLeave ="mouseLeave">

<MediaElement x:Name="movie" Source="Lake.wmv"/>
<Canvas MouseLeftButtonDown="moviePlay"
Canvas.Left="10" Canvas.Top="365">
<TextBlock Canvas.Left="5" Canvas.Top="5" Visibility="Collapsed" x:Name="playButton" Foreground="White">Play</TextBlock>
<Canvas MouseLeftButtonDown="moviePause"
Canvas.Left="70" Canvas.Top="365">
<TextBlock Canvas.Left="5" Canvas.Top="5" Visibility="Collapsed" x:Name="pauseButton" Foreground="White">Pause</TextBlock>
<Canvas MouseLeftButtonDown="movieStop"
Canvas.Left="130" Canvas.Top="365">
<TextBlock Canvas.Left="5" Canvas.Top="5" Visibility="Collapsed" x:Name="stopButton" Foreground="White">Stop</TextBlock>

4. Movie.xaml.js (event handler, logic)

function movieStop(sender, args) {
function moviePause(sender, args) {
function moviePlay(sender, args) {

function mouseEnter(sender, args) {
setControlVisibility(sender, "Visible");

function mouseLeave(sender, args) {
setControlVisibility(sender, "Collapsed");

function setControlVisibility(sender, visibility) {
sender.findName("playButton").visibility = visibility;
sender.findName("stopButton").visibility = visibility;
sender.findName("pauseButton").visibility = visibility;

Files 2-4 and the movie are added to a zip file and uploaded to the Microsoft Silverlight Streaming host.

You might also be interested in the following previous posts:

Tuesday, February 12, 2008

Microsoft Silverlight Streaming Service Test

This is a test of Microsoft Silverlight Streaming -- a free service that provides 4GB online space for Silverlight application hosting. You will need Silverlight 1.1 or higher to see the content. Move mouse over the video to see the movie controls. Resources for this implementation: a video file from Windows Vista, Silverlight 1.1 SDK, Visual Studio Express (Visual Web Developer 2008 Express Edition), and a Microsoft Silverlight Streaming account.