Click here to Skip to main content
6,630,586 members and growing! (18,244 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » General     Intermediate License: The Code Project Open License (CPOL)

How to Unload the Input Method DLL on Pocket PC

By Aleh

Shows how to unload the Input Method (IM) DLL for the Software Input Panel (SIP) on Pocket PC, which is important to Input Method uninstallers
C++, eVC 3.0, eVC 4.0, Windows, Visual Studio, Dev
Posted:26 Apr 2007
Updated:5 Jan 2008
Views:18,931
Bookmarked:15 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
6 votes for this article.
Popularity: 3.60 Rating: 4.63 out of 5

1

2

3
2 votes, 33.3%
4
4 votes, 66.7%
5

Introduction

Many developers who wrote their own Input Methods (IM) for the Software Input Panel (SIP) on Pocket PC, or those who developed uninstallers for custom Input Methods faced with the problem of unloading their DLL's in order to update them or remove from the device. However it seems a bit hard to find any information on how to achieve this without rebooting the system. This short article aims to solve this problem.

Background

According to the official documentation the SIP should release the Input Method COM object just after calling of IInputMethod->Deselect() method, i.e. just after another Input Method is selected. And I can confirm the SIP does release it. So it seems that the easiest method would be to simply select another Input Method. This does not work however.

As you know, the COM subsystem does not unload unused DLL's immediately. Instead, it waits for the user code to call CoFreeUnusedLibraries() or CoFreeUnusedLibrariesEx(). The SIP does call the first function, but, unfortunately, this is not enough to unload all unused input methods immediately. Inside this function the COM subsystem calls DllCanUnloadNow() routine for all DLL's that do not seem to be used anymore and puts all those DLL's that returned S_OK (DLL can be unloaded) into a list of candidates for unloading. When a DLL from this list is needed to the COM again (for example, the application requests to create a new COM object that sits in this DLL) the DLL is removed from this candidate list. If some DLL is still sitting in the candidate list when either CoFreeUnusedLibraries(), or CoFreeUnusedLibrariesEx() is called again, this DLL finally gets unloaded if and only if enough time has passed since putting the DLL into the list.

When using CoFreeUnusedLibrariesEx() this time interval can be specified as the first parameter, but for CoFreeUnusedLibraries() used by the SIP this timeout is the system default value, which is 10 minutes! Quite a long time to ask the user to wait for...

Solution

One of the possible ways to workaround this problem would be to call CoFreeUnusedLibrariesEx() from the same process where the SIP lives with zero or near to zero timeout parameter. Fortunately, this is easily to achieve, because the SIP is implemented as a device driver and resides where all device drivers reside--in the device.exe process. So we can create a simple driver, which calls needed function(s), then load it and enjoy the possibility to remove our DLL. Sure, the input method should be deselected before this. There is also another trick.

The driver would be simpler, if we could call CoFreeUnusedLibrariesEx() from the Init() entry point. This does not work, because the COM subsystem needs the owner process ID to be equal to the current process ID (device.exe), for which we need DLL's to be unloaded. However the owner process ID inside the Init() call is equal to the ID of process which loaded our driver (i.e. our example program), and therefore COM tries to unload COM DLL's for this example application.

To overcome this, we just need to create another thread and do our call from the context of this thread. Owner process ID for this thread is equal to the ID of device.exe, where the SIP and Input Methods live.

Using the code

The example can be compiled with eVC++ 4.0. There are two projects in the archieve: a simple device driver, which when loaded calls CoFreeUnusedLibrariesEx() as described above; and a simple executable that loads this driver.

The driver exposes a minimal set of required entry points (Init/Deinit, Open/Close, IOControl), because we just need it to be loaded into the device.exe, nothing more.

Notes

When it is needed to unload the Input Method DLL while an application is being uninstalled from the device via the Remove Programs applet, it is possible to use a Custom Setup DLL as a driver itself by providing needed entry points, i.e. there is no need in a separate DLL.

I hope this article will be helpful to Input Method writers. Do not hesitate to comment or ask any questions.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Aleh


Member
I am an independent professional based in Minsk, Belarus, specializing in embedded and in particular Windows Mobile related software development. I have extensive experience in projects ranging from Windows CE drivers and firmware for AVR and PIC microcontrollers to end-user Windows Mobile and J2ME applications.

If you have any questions related (or unrelated) to my article then feel free to contact me.
Occupation: Software Developer
Location: Belarus Belarus

Other popular Mobile Development articles:

  • Writing Your Own GPS Applications: Part 2
    In part two of the series, the author of "GPS.NET" teaches developers how to write GPS applications suitable for the real world by mastering GPS precision concepts. Source code includes a working NMEA interpreter and sample high-precision application in C# and VB.NET.
  • Writing Your Own GPS Applications: Part I
    What is it that GPS applications need to be good enough to use for in-car navigation? Also, how does the process of interpreting GPS data actually work? In this three-part series, I will cover both topics and give you the skills you need to write a commercial-grade GPS application.
  • Learn How to Find GPS Location on Any SmartPhone, and Then Make it Relevant
    A step by step tutorial for getting GPS from any SmartPhone, even without GPS built in, and then making location useful.
  • iPhone UI in Windows Mobile
    It's an interface that works with transparency effects. As a sample I used an interface just like the iPhone one. In this tutorial I am explaining how simple is working with transparency on Windows Mobile.
  • Pocket 1945 - A C# .NET CF Shooter
    An article on Pocket PC game development
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 10 of 10 (Total in Forum: 10) (Refresh)FirstPrevNext
General[Message Deleted] Pinmemberit.ragester6:32 28 Mar '09  
GeneralGreat! PinmemberBitBlaster23:17 9 Sep '08  
QuestionCan CoFreeUnusedLibrariesEx() help with DLL load errors? PinmemberUdara_G6:23 21 Aug '07  
AnswerRe: Can CoFreeUnusedLibrariesEx() help with DLL load errors? PinmemberAleh10:35 22 Aug '07  
GeneralRe: Can CoFreeUnusedLibrariesEx() help with DLL load errors? PinmemberUdara_G20:32 22 Aug '07  
GeneralThanks a lot PinmemberQuentin Pouplard8:49 4 Aug '07  
GeneralRe: Thanks a lot PinmemberAleh9:03 4 Aug '07  
GeneralI could not download the source files Pinmemberschwarz.works11:25 4 May '07  
GeneralRe: I could not download the source files PinmemberAleh13:42 4 May '07  
QuestionCan you help with "the IM Select" Problem? Pinmemberschwarz.works11:21 4 May '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 Jan 2008
Editor:
Copyright 2007 by Aleh
Everything else Copyright © CodeProject, 1999-2009
Web11 | Advertise on the Code Project