Friday, December 18, 2009

Getting your Huawei E220 Modem to Work on Windows Vista

    I had been using my Huawei E220 on Windows XP for a couple of years until I got my new Dell XPS with Windows Vista pre-installed. I could not wait to get my first Internet experience on Vista and plugged my HSPA dongle in to come online as quickly as possible as it used to be on XP. Then only I realized that my Huawei E220 mobile broadband modem was not working on Vista. Apparently the device driver was failing to detect the plug-and-play device on Vista.

    I started to Google looking for some solution and found that it required a firmware upgrade. An office colleague of mine also told me that he managed to get his Huawei E220 to work on Vista by doing a firmware upgrade. Yesterday I also managed to get my dongle to work on Vista after a firmware upgrade.

    This is how you go about doing this simple upgrade process.

1. Go to http://www.huawei.com/mobileweb/en/doc/list.do?type=-1&id=736 and download the file E220 Client Software WINMACB300D00SP02C03 (UTPS11[1].002.03.16.03_MAC11.201.01.00.03) for WinXP&2K&Vista & Mac.zip.

2. Fix your dongle into a 32-bit Windows machine (say Windows XP) and execute this file to do the firmware upgrade. Please note that your dongle can become completely unusable in case you disturb this upgrade process.

3. Once it is done, you can use your newly upgraded Huawei E220 HSPA modem on your Vista machine without any issue.

Happy upgrade and Good Luck !!!

Thursday, October 22, 2009

C++ - Referring to an enum inside a type

When you refer to an enum inside a type, you do not have to specify the name of the enum. See the code snippets below.

Say you have a class like what is given below.

class MyClass {
enum MyEnum { a };
};


Incorrect use of a value of type MyEnum



int i = MyClass::MyEnum::a;


Correct use of a value of type MyEnum



int j = MyClass::a;

Tuesday, October 13, 2009

Why AFX_MANAGE_STATE is important in Windows programming?

I happened to write a Windows shell extension about an year back. It was this macro that helped me fix issues when my application was crashing here and there. I am developing an MS Excel extension for a client project and again I ran into the same problem. I spent a couple of days figuring out what was going wrong and finally found that this same old macro was going to fix my issue.

So what is this macro and what does it do?

MFC uses the resource handle of the main application to load the resource templates. If you have an exported function in a DLL, such as one that launches a dialog box in the DLL, this template is actually stored in the DLL module. You need to switch the module state for the correct handle to be used. Otherwise the program crashes as it tries to access some resource resides in a different module. You can do this module switching by adding the following code to the beginning of the function. That is just before using the resource from the other module.


AFX_MANAGE_STATE(AfxGetStaticModuleState( ));

This swaps the current module state with the state returned from AfxGetStaticModuleState until the end of the current scope. When the execution flow goes out of the current scope, the module state gets switched back to that of the current application.

Thursday, May 7, 2009

Exporting a Global Variable from a DLL

Lets say you want to export a global variable of type int and use it in another application. You need to do it as follows.

1. In the header file where you are going to declare your variable do this.
   extern DLL_EXTERN int i;

2. In the .c or .cpp file, you need to define it like this.
   DLL_EXTERN int i = 10;

You should make your pre-processor settings such that DLL_EXTERN is equal to __declspec(dllexport).

3. Now in your application, where you are going to consume this variable, you need to set your pre-processor options such that DLL_EXTERN is equal to __declspec(dllimport).

NOTE:
For functions, not having __declspec(dllimport) does not give any compile/link errors. But of course it helps generate better code as with this the compiler knows that the function resides in a DLL and hence it can avoid the level of indirection that is there when a function call is done across the boundary of a DLL. But its a MUST that you have __declspec(dllimport) in front of variables as without that you will get the famous "unresolved external symbol" errors.

Thursday, April 23, 2009

%cd% vs. %~dp0

Until today, I also did not have an idea about the difference between these two.

%cd% available to a batch file or at the command prompt and expands to the drive letter and the path of the current directory.

%~dp0 is available to a batch file only. This expands to the drive letter and the path in which the batch file is located.

If you take the following command for an example where the batch file prints the two variables, the output would be as shown.

C:\danushka\runtime>D:\my_scripts\test_script.bat

%cd% = C:\danushka\runtime

%~dp0 = D:\my_scripts