Uninstalling calls for a different approach. First, you have to make sure that the DLL is not being used by the SMS-handling process. My answer to this is to shut down the tmail.exe process. Here is some code:
BOOL KillProcess(LPCTSTR pszProcName)
{
HANDLE hSnapshot;
BOOL bRet = FALSE;
hSnapshot = CreateToolhelp32Snapshot(
TH32CS_SNAPPROCESS, 0);
if((int)hSnapshot != -1)
{
BOOL bOk;
PROCESSENTRY32 pe;
DWORD dwID = 0;
HANDLE hProcess;
pe.dwSize = sizeof(PROCESSENTRY32);
for(bOk = Process32First(hSnapshot, &pe);
bOk;
bOk = Process32Next(hSnapshot, &pe))
{
if(!wcsicmp(pe.szExeFile, pszProcName))
dwID = pe.th32ProcessID;
}
CloseToolhelp32Snapshot(hSnapshot);
if(dwID != 0)
{
// Kill the process
hProcess = OpenProcess(0, FALSE, dwID);
if(hProcess != INVALID_HANDLE_VALUE)
{
bRet = TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
}
}
}
return bRet;
}
After killing the process, you have to unregister the DLL (sample code here) and finally soft-reset the device.
A sample setup dll project is available on demand.
2 comments:
Is this post relevant to WM 5.0 and later ?
This is the thing. I have an app that uses SMS's for some its business logic. The SMS handling code is taken from the sample provided by PPC 2003. Now the problem is when I uninstall the application. Even though the DllUnregisterServer() call is provided, it does not unregister this dll from the SMS service and hence I cannot delete the dll.
You suggested that tmail.exe process be killed. Is this documented anywhere or is this from your experience ?
Thanks
The easiest way to close the mail client is to send a WM_CLOSE message to the top-level window whose class name is "Inbox.MainWnd". This will close the mail client and you will be able to unregister your DLL (hopefully).
Post a Comment