Monday 7 January 2008

ShellExecuteEx

Its better to use shellexecuteEx to launch apps.
The device can have lot of flexibility from where we launch the apps from.

the example given below shows how we could read from the registry and run the apps programmatically on windows mobile devices.

SHELLEXECUTEINFO sei;
HKEY hKey;
TCHAR szKeyName[250], szApplName[250], szApplDir[250], szApplParam[250];

RegOpenKeyEx(HKEY_LOCAL_MACHINE, , 0, 0, &hKey);

dwcbData=sizeof(szApplName)*sizeof(TCHAR);
rc = RegQueryValueEx (hKey, szKeyName, 0, &dwType, (LPBYTE)szApplName, &dwcbData);

if (rc != ERROR_SUCCESS)
{
//do something
}

dwcbData=sizeof(szApplParam)*sizeof(TCHAR);
rc = RegQueryValueEx (hKey, szKeyName, 0, &dwType, (LPBYTE)szApplParam, &dwcbData);


dwcbData=sizeof(szApplDir)*sizeof(TCHAR);
rc = RegQueryValueEx (hKey, szKeyName, 0, &dwType, (LPBYTE)szApplDir, &dwcbData);

RegCloseKey (hKey);
if()
{
wcscpy(szApplName, _T(""));
wcscpy(szApplParam, _T(""));
wcscpy(szApplDir, _T(""));
}

memset(&sei, 0, sizeof(sei));
sei.cbSize = sizeof(sei);
sei.hwnd = NULL;
sei.lpFile = szApplName;
sei.lpParameters = szApplParam;
sei.lpDirectory = szApplDir;
sei.nShow = SW_SHOWNORMAL;

ShellExecuteEx(&sei) ; //parse application szDirNameText to szDirName

No comments: