J2i.Net

Nothing at all and Everything in general.

Custom Actions in a Cab Installation

Creating a cab installer for a Windows Mobile program is easy.  After making a cab project you add your files and Visual Studio does everything else for you.  But when you uninstall your application what happens to all of the registry entries and data files that your application has made?  They get left behind unless you erase them yourself. Chances are your program won't ever receive any notification that it is about to be uninstalled, so your program won't be able to cleanup after itself.  Instead you will need to create a DLL that contains custom actions.   The installer build into the Windows Mobile device will call your DLL once before installation, once after installation, once before deinstallation, and right after deinstallation.  So how to you make this custom DLL?

The custom DLL will be a Win32 DLL smart device project. The DLL must define four functions, Install_Init, Install_Exit, Uninstall_Init, and Uninstall_Exit. To cleanup after your program has been uninstalled you will place cleanup code in Uninstall_Exit Here is the code for the custom actions DLL that I wrote. I've added code to clean up the registry.  If there are other programs that I've written still on the device they will be using the same registry hive to store their keys.  If other programs are found the program will leave behing the \HKCU\Software\J2i.Net key as not to accidentally erase the keys that my other programs use.  If there are no other programs found then J2i.Net will be removed.

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
void RemoveRegistryKeys();
///////////////////////////////////////////////////////////////
codeINSTALL_INIT Install_Init
(
HWND hWndParent,
BOOL fFirstCall,
BOOL fPreviouslyInstalled,
LPCSTR pszInstallDir
)
{
MessageBeep(0);
return codeINSTALL_INIT_CONTINUE;
}
///////////////////////////////////////////////////////////////
codeINSTALL_EXIT Install_Exit
(
HWND hWndParent,
LPCSTR pszInstallDir,
WORD cFailedDirs,
WORD cFailedRegKeys,
WORD cFailedRegVals,
WORD cFailedShortcuts
)
{
MessageBeep(0);
return codeINSTALL_EXIT_DONE;
}
///////////////////////////////////////////////////////////////
codeUNINSTALL_INIT Uninstall_Init
(
HWND hwndParent,
LPCSTR pszInstallDir
)
{
MessageBeep(0);
return codeUNINSTALL_INIT_CONTINUE;
}
///////////////////////////////////////////////////////////////
codeUNINSTALL_EXIT Uninstall_Exit
(
HWND hwndParent
)
{
RemoveRegistryKeys();
MessageBeep(0);
return codeUNINSTALL_EXIT_DONE;
}
void RemoveRegistryKeys()
{
HKEY hCompanyKey = NULL;
HKEY hSoftwareKey = NULL;
TCHAR buffer[MAX_PATH];
DWORD bufferSize = MAX_PATH;
bool canEraseCompanyKey = false;
//Delete the application key
RegOpenKeyEx(HKEY_CURRENT_USER,L"Software", 0,0,&hSoftwareKey);
if(hSoftwareKey)
{
RegOpenKeyEx(hSoftwareKey, L"J2i.Net",0,0,&hCompanyKey);
if(hCompanyKey)
{
RegDeleteKey(hCompanyKey, L"MyColourPreferences");
canEraseCompanyKey = (ERROR_SUCCESS!=RegEnumKeyEx(hCompanyKey,0,buffer,&bufferSize,0,0,0,0));
RegCloseKey(hCompanyKey);
RegCloseKey(hCompanyKey);
if(canEraseCompanyKey)
RegDeleteKey(hSoftwareKey,L"J2i.Net");
}
if(hSoftwareKey)
RegCloseKey(hSoftwareKey);
}
}

To export the four functions the DLL will also need to contain a Module Definition file that exports the four functions. The contents of that file must look like the following.

EXPORTS
Install_Init
Install_Exit
Uninstall_Init
Uninstall_Exit

That's all that needs to be in the DLL. When you create your installer you will need to add both the primary output of your program and this DLL to the project. The last thing that you need to do is change the CE Setup DLL setting on the CAB project. Select the CAB project from the Solutions Explorer and you will see the CE Setup DLL setting in the property editor. Click on the dropdown to the right of the setting and select Browse. Navigate to the native DLL that you created and your done. All you need to do is compile and build the CAB.

As an example there is a Visual Studio project attached to this entry.  The project contains a program of trivial simplicity.  All that you need to know about that program is that it will save the information you enter to the registry.  Without the custom action when you uninstall this program that information would be left in the registry.   But thanks to the custom action it will be removed.

The Global Economy and the Terminal Redux

Earlier today Microsoft announced its plans for adjusting to the world economy. The news story I read stated that mid-PC sales were down while server software was up.  I can't help but associate that with what a Sony exec called "A race to the bottom" in which consumer and OEMs begin to target building the cheaper computer instead of the higher performing computer.   With the increasing emphasis being placed on Cloud Computing and Web Services and it all supports a prediction that software was going to move from the individual PCs back to the servers.  We can find evidence of this now.  Previously if you wanted to work on a word document you needed a computer with sufficient space and a reasonably powered processor.  You would then need to purchase and install Microsoft Word and you could edit documents from your siloed computer.  While you can still do this today you also have the option of using an online service to essentially do the same thing.  You can use a low powered computer with any of a variety of operating systems as long as that computer has a supported browser.   The power of the individual computer matters a little less and connectivity matters a whole lot more. as applications begin to target modern terminals. 

It's possibly that my view of the future is slightly exagerated but I doubt it is completely wrong.  That being said my plans for adjusting to what I think to be the needs of the future are to accelerate my learning path for Microsoft Azure Services Platoform and Live Services. I've been experimenting with Live Services for some time now and have found them to be useful in quickly putting together useful applications.  An Azure application runs across several 64-bit Windows 2008 servers.  Installation of patches is handled for you, failover is taken care of, and so are several other maintenance tasks allowing development of highly available, secure, and redundant applications with more ease.   Effective use of the platform is going to require a different way of thinking than developing the traditional application so I plan to get started tonight with the intent of having information to teach and share within the next week.

Free Visual Studio 2008 eBooks

 

I was reading through Mike Francis's blog and saw a rather useful offer from Microsoft for free eBooks on LINQ, ASP.NET Ajax, and Silverlight 2.0.  If you are interested all you have to do is register and you can download the eBooks.   I'll be teaching a Silverlight class in a little over a month so I hope to review the Silverlight book fairly soon so that I can consider recommending it to the students.

The Yellow Book for Students of C#

I'm glad Mike Hall posted on this.  There is a free book available to those wanting to learn C#.  This is especially convinent for me because I was going to write a series of "Getting Started"  articles on Windows Mobile development and I really see the task of learning the C# (or vb.net) language as being seperate from learning how to target Windows Mobile devices.  I'll be referencing this book in one of my next articles.

 

 

Innovate on Windows Mobile Code Signing Offer

If you've developed a Windows Mobile application and would like to see it listed on the Windows Mobile Application Catalog then it will need to be tested for certification requirements and code signed.  This normally cost up to $800.  But Microsoft is offering a program whereby you can have these services performed for free.  Just visit the Innovation Site  and register.  Remember, make sure that your application adhere's to certification guidelines before submitting the application. Otherwise you could consume part if the $800 woth of service unnecessarily.

Skyhook Wireless 3.0 SDK and Managed Code

As promised I uploaded the wrapper for the Skyhook Wireless SDK for Windows Mobile to the Skyhook Wireless discussion group.   I tried the wrapper out with the 3.0 SDK and it works fine.  It exposes all the SDK functionality with the exception of the WPS_tune_location function (I have no idea what that function does).  So I am done with my interaction with the Skyhook Wireless SDK for now.

If you program in C# or VB.Net and want to use the SDK then you can get the code from the files area of the Skyhook Wireless discussion group.

Microsoft Windows Mobile Developer Contest 2008 Coming to a Close

In case you've missed it the Windows Mobile Programming Contest at CodeProject.com comes to an end tomorrow night at  11:59:59 EST (thats only about 35 hours from now!).  In looking over the contest entries I see a lot of good entries.  Here they are in no specific order:

Augmented Reality on Windows Mobile

 

I was reading through WMPowerUser yesterday and happened upon an article on Augment Reality on Windows Mobile.  The article shows some videos from the Christian Dopler Laboratory  in which a mobile device is being used to track photographs and business cards and project 3D elements on them.  Very cool! Best of all there is code available for the computer vision library that they used.  Follow the link for the code and videos. 

Top 5 Searches

In reading through my Google Analytics report I see that there are a few searches that are always at the top of the list. 

 

 

Beyond having mentioned the Windows Mobile Power Toys once in refering to the "24 Hours of Windows Mobile" webcast I've not actually spoken about it.  But given the level of popularity I've decided to write an article covering it along with the EQATEC Profiler and the EQATEC Tracer.  All of these are free tools.  I wrote my outline for the article last night and am now working on the example code.  This will be something usable by both those that use Visual Studio and those that develop for Windows Mobile without Visual Studio.