//---------------------------Start InitPropVariantFromCString----------------------// inline HRESULT InitPropVariantFromCString (__in PCSTR psz, __out PROPVARIANT *ppropvar) { const size_t cSize = strlen (psz) + 1; std::wstring wc (cSize, L'#'); mbstowcs (&wc[0], psz, cSize); return InitPropVariantFromString (wc.c_str (), ppropvar); }
bool validateShortcut() { QString path = systemShortcutPath(); if (path.isEmpty() || cExeName().isEmpty()) return false; if (cAlphaVersion()) { path += qsl("TelegramAlpha.lnk"); if (validateShortcutAt(path)) return true; } else { if (validateShortcutAt(path + qsl("Telegram Desktop/Telegram.lnk"))) return true; if (validateShortcutAt(path + qsl("Telegram Win (Unofficial)/Telegram.lnk"))) return true; path += qsl("Telegram.lnk"); if (validateShortcutAt(path)) return true; } ComPtr<IShellLink> shellLink; HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); if (!SUCCEEDED(hr)) return false; hr = shellLink->SetPath(QDir::toNativeSeparators(cExeDir() + cExeName()).toStdWString().c_str()); if (!SUCCEEDED(hr)) return false; hr = shellLink->SetArguments(L""); if (!SUCCEEDED(hr)) return false; hr = shellLink->SetWorkingDirectory(QDir::toNativeSeparators(QDir(cWorkingDir()).absolutePath()).toStdWString().c_str()); if (!SUCCEEDED(hr)) return false; ComPtr<IPropertyStore> propertyStore; hr = shellLink.As(&propertyStore); if (!SUCCEEDED(hr)) return false; PROPVARIANT appIdPropVar; hr = InitPropVariantFromString(getId(), &appIdPropVar); if (!SUCCEEDED(hr)) return false; hr = propertyStore->SetValue(getKey(), appIdPropVar); PropVariantClear(&appIdPropVar); if (!SUCCEEDED(hr)) return false; PROPVARIANT startPinPropVar; hr = InitPropVariantFromUInt32(APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL, &startPinPropVar); if (!SUCCEEDED(hr)) return false; hr = propertyStore->SetValue(pkey_AppUserModel_StartPinOption, startPinPropVar); PropVariantClear(&startPinPropVar); if (!SUCCEEDED(hr)) return false; hr = propertyStore->Commit(); if (!SUCCEEDED(hr)) return false; ComPtr<IPersistFile> persistFile; hr = shellLink.As(&persistFile); if (!SUCCEEDED(hr)) return false; hr = persistFile->Save(QDir::toNativeSeparators(path).toStdWString().c_str(), TRUE); if (!SUCCEEDED(hr)) return false; return true; }
void AsfContentInfoBuilder::SetMetadataAsString(PCWSTR field, PCWSTR value) { PROPVARIANT pv; InitPropVariantFromString(value, &pv); HRESULT hr = _mfMetadata->SetProperty(field, &pv); PropVariantClear(&pv); }
HRESULT CTaskbar7::CreateShellLink(Destination destination, IShellLink **ppShellLink) { USES_CONVERSION; IShellLink *pShellLink = NULL; IPropertyStore *pPropertyStore = NULL; PROPVARIANT propVariant; HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pShellLink)); EXIT_ON_ERROR(hr); // Path hr = pShellLink->SetPath(CW2A(destination.path.c_str())); EXIT_ON_ERROR(hr); // Arguments hr = pShellLink->SetArguments(CW2A(destination.arguments.c_str())); EXIT_ON_ERROR(hr); // Working Directory if (!destination.workingFolder.empty()) { hr = pShellLink->SetWorkingDirectory(CW2A(destination.workingFolder.c_str())); EXIT_ON_ERROR(hr); } // Icon Location if (!destination.icon.empty()) { hr = pShellLink->SetIconLocation(CW2A(destination.icon.c_str()), destination.iconIndex); EXIT_ON_ERROR(hr); } hr = pShellLink->QueryInterface(IID_PPV_ARGS(&pPropertyStore)); EXIT_ON_ERROR(hr); // Name hr = InitPropVariantFromString(destination.name.c_str(), &propVariant); EXIT_ON_ERROR(hr); hr = pPropertyStore->SetValue(PKEY_Title, propVariant); EXIT_ON_ERROR(hr); hr = pPropertyStore->Commit(); EXIT_ON_ERROR(hr); hr = pShellLink->QueryInterface(IID_PPV_ARGS(ppShellLink)); Exit: PropVariantClear(&propVariant); SAFE_RELEASE(pPropertyStore); SAFE_RELEASE(pShellLink); return hr; }
bool validateShortcutAt(const QString &path) { static const int maxFileLen = MAX_PATH * 10; std::wstring p = QDir::toNativeSeparators(path).toStdWString(); DWORD attributes = GetFileAttributes(p.c_str()); if (attributes >= 0xFFFFFFF) return false; // file does not exist ComPtr<IShellLink> shellLink; HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); if (!SUCCEEDED(hr)) return false; ComPtr<IPersistFile> persistFile; hr = shellLink.As(&persistFile); if (!SUCCEEDED(hr)) return false; hr = persistFile->Load(p.c_str(), STGM_READWRITE); if (!SUCCEEDED(hr)) return false; ComPtr<IPropertyStore> propertyStore; hr = shellLink.As(&propertyStore); if (!SUCCEEDED(hr)) return false; PROPVARIANT appIdPropVar; hr = propertyStore->GetValue(getKey(), &appIdPropVar); if (!SUCCEEDED(hr)) return false; WCHAR already[MAX_PATH]; hr = Dlls::PropVariantToString(appIdPropVar, already, MAX_PATH); if (SUCCEEDED(hr)) { if (std::wstring(getId()) == already) { PropVariantClear(&appIdPropVar); return true; } } if (appIdPropVar.vt != VT_EMPTY) { PropVariantClear(&appIdPropVar); return false; } PropVariantClear(&appIdPropVar); hr = InitPropVariantFromString(getId(), &appIdPropVar); if (!SUCCEEDED(hr)) return false; hr = propertyStore->SetValue(getKey(), appIdPropVar); PropVariantClear(&appIdPropVar); if (!SUCCEEDED(hr)) return false; hr = propertyStore->Commit(); if (!SUCCEEDED(hr)) return false; if (persistFile->IsDirty() == S_OK) { persistFile->Save(p.c_str(), TRUE); } return true; }
HRESULT SetPropertyValue(PCWSTR pszFilename, PCWSTR pszCanonicalName, PCWSTR pszValue) { // Convert the Canonical name of the property to PROPERTYKEY PROPERTYKEY key; HRESULT hr = PSGetPropertyKeyFromName(pszCanonicalName, &key); if (SUCCEEDED(hr)) { IPropertyStore* pps = NULL; // Call the helper to get the property store for the // initialized item hr = GetPropertyStore(pszFilename, GPS_READWRITE, &pps); if (SUCCEEDED(hr)) { PROPVARIANT propvarValue = {0}; hr = InitPropVariantFromString(pszValue, &propvarValue); if (SUCCEEDED(hr)) { hr = PSCoerceToCanonicalValue(key, &propvarValue); if (SUCCEEDED(hr)) { // Set the value to the property store of the item. hr = pps->SetValue(key, propvarValue); if (SUCCEEDED(hr)) { // Commit does the actual writing back to the file stream. hr = pps->Commit(); if (SUCCEEDED(hr)) { wprintf(L"Property %s value %s written successfully \n", pszCanonicalName, pszValue); } else { wprintf(L"Error %x: Commit to the propertystore failed.\n", hr); } } else { wprintf(L"Error %x: Set value to the propertystore failed.\n", hr); } } PropVariantClear(&propvarValue); } pps->Release(); } else { wprintf(L"Error %x: getting the propertystore for the item.\n", hr); } } else { wprintf(L"Invalid property specified: %s\n", pszCanonicalName); } return hr; }
extern "C" void __declspec(dllexport) Set(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) { g_stringsize = string_size; g_stacktop = stacktop; g_variables = variables; { IPropertyStore *m_pps = NULL; WCHAR wszPath[MAX_PATH]; WCHAR wszAppID[MAX_PATH]; TCHAR szPath[MAX_PATH]; TCHAR szAppID[MAX_PATH]; bool success = false; ZeroMemory(wszPath, sizeof(wszPath)); ZeroMemory(wszAppID, sizeof(wszAppID)); ZeroMemory(szPath, sizeof(szPath)); ZeroMemory(szAppID, sizeof(szAppID)); popstring(szPath, MAX_PATH); popstring(szAppID, MAX_PATH); #if !defined(UNICODE) MultiByteToWideChar(CP_ACP, 0, szPath, -1, wszPath, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, szAppID, -1, wszAppID, MAX_PATH); #else wcscpy(wszPath, szPath); wcscpy(wszAppID, szAppID); #endif ::CoInitialize(NULL); if (SUCCEEDED(SHGetPropertyStoreFromParsingName(wszPath, NULL, GPS_READWRITE, IID_PPV_ARGS(&m_pps)))) { PROPVARIANT propvar; if (SUCCEEDED(InitPropVariantFromString(wszAppID, &propvar))) { if (SUCCEEDED(m_pps->SetValue(PKEY_AppUserModel_ID, propvar))) { if (SUCCEEDED(m_pps->Commit())) { success = true; } } } } if (m_pps != NULL) m_pps->Release(); CoUninitialize(); pushstring(success == true ? TEXT("0") : TEXT("-1"), MAX_PATH); } }
HRESULT _CreateShellLink(PCSTR pszArguments, PCWSTR pszTitle, LPCSTR szDescription, IShellLink **ppsl) { IShellLink *psl; HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl)); if (SUCCEEDED(hr)) { // Determine our executable's file path so the task will execute this application CHAR szAppPath[MAX_PATH]; if (GetModuleFileName(NULL, szAppPath, ARRAYSIZE(szAppPath))) { hr = psl->SetPath(szAppPath); if (SUCCEEDED(hr)) { hr = psl->SetArguments(pszArguments); if (SUCCEEDED(hr)) { hr = psl->SetDescription( szDescription ); if (SUCCEEDED(hr)) { // The title property is required on Jump List items provided as an IShellLink // instance. This value is used as the display name in the Jump List. IPropertyStore *pps; hr = psl->QueryInterface(IID_PPV_ARGS(&pps)); if (SUCCEEDED(hr)) { PROPVARIANT propvar; hr = InitPropVariantFromString(pszTitle, &propvar); if (SUCCEEDED(hr)) { hr = pps->SetValue(PKEY_Title, propvar); if (SUCCEEDED(hr)) { hr = pps->Commit(); if (SUCCEEDED(hr)) { hr = psl->QueryInterface(IID_PPV_ARGS(ppsl)); } } PropVariantClear(&propvar); } pps->Release(); } } } } } else { hr = HRESULT_FROM_WIN32(GetLastError()); } psl->Release(); } return hr; }
// (static) ShellItems are used to encapsulate links to things. We currently only support URI links, // but more support could be added, such as local file and directory links. nsresult JumpListLink::GetShellItem(nsCOMPtr<nsIJumpListItem>& item, nsRefPtr<IShellItem2>& aShellItem) { IShellItem2 *psi = nullptr; nsresult rv; int16_t type; if (NS_FAILED(item->GetType(&type))) return NS_ERROR_INVALID_ARG; if (type != nsIJumpListItem::JUMPLIST_ITEM_LINK) return NS_ERROR_INVALID_ARG; nsCOMPtr<nsIJumpListLink> link = do_QueryInterface(item, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIURI> uri; rv = link->GetUri(getter_AddRefs(uri)); NS_ENSURE_SUCCESS(rv, rv); nsAutoCString spec; rv = uri->GetSpec(spec); NS_ENSURE_SUCCESS(rv, rv); // Create the IShellItem if (FAILED(WinUtils::SHCreateItemFromParsingName( NS_ConvertASCIItoUTF16(spec).get(), NULL, IID_PPV_ARGS(&psi)))) { return NS_ERROR_INVALID_ARG; } // Set the title nsAutoString linkTitle; link->GetUriTitle(linkTitle); IPropertyStore* pPropStore = nullptr; HRESULT hres = psi->GetPropertyStore(GPS_DEFAULT, IID_IPropertyStore, (void**)&pPropStore); if (FAILED(hres)) return NS_ERROR_UNEXPECTED; PROPVARIANT pv; InitPropVariantFromString(linkTitle.get(), &pv); // May fail due to shell item access permissions. pPropStore->SetValue(PKEY_ItemName, pv); pPropStore->Commit(); pPropStore->Release(); PropVariantClear(&pv); aShellItem = dont_AddRef(psi); return NS_OK; }
BOOL install_util::CreateLnkPath(std::wstring wsSourceFilePath, std::wstring wsDestLnkPath, std::wstring wsArgument, std::wstring wsAppId) { IShellLink *pisl = NULL; HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pisl); if (FAILED(hr)) { return FALSE; } pisl->SetPath(wsSourceFilePath.c_str()); pisl->SetArguments(wsArgument.c_str()); int nStart = wsSourceFilePath.find_last_of(_T("/\\")); pisl->SetWorkingDirectory(wsSourceFilePath.substr(0,nStart).c_str()); IPersistFile *plPF = NULL; hr = pisl->QueryInterface(IID_IPersistFile, (void**)&plPF); bool shortcut_existed = false; if (SUCCEEDED(hr)) { if (PathExists(wsDestLnkPath)) { shortcut_existed = true; install_util::DeleteFile(wsDestLnkPath.c_str()); } if (Win7OrLater() && !wsAppId.empty() && wsAppId.length() < 64) { IPropertyStore *piPS = NULL; if (SUCCEEDED(pisl->QueryInterface(IID_IPropertyStore, (void**)&piPS))) { PROPVARIANT property_value; if (SUCCEEDED(InitPropVariantFromString(wsAppId.c_str(), &property_value))) { if (piPS->SetValue(PKEY_AppUserModel_ID, property_value) == S_OK) piPS->Commit(); PropVariantClear(&property_value); } piPS->Release(); } } hr = plPF->Save(wsDestLnkPath.c_str(), TRUE); plPF->Release(); } pisl->Release(); SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); return SUCCEEDED(hr); }
void SetAppID(HWND hWnd, wstring appId) { IPropertyStore *pps; HRESULT hr = SHGetPropertyStoreForWindow(hWnd, IID_PPV_ARGS(&pps)); if (SUCCEEDED(hr)) { PROPVARIANT pv; hr = InitPropVariantFromString(appId.c_str(), &pv); if (SUCCEEDED(hr)) { hr = pps->SetValue(PKEY_AppUserModel_ID, pv); PropVariantClear(&pv); } pps->Release(); } }
HRESULT CTaskbar7::AddRecent(BSTR name, BSTR path, BSTR arguments, BSTR icon) { USES_CONVERSION; // ANSI version doesn't seem to work correctly with Win7 jump lists, so explicitly use Unicode interface. IShellLinkW *pShellLink = NULL; IPropertyStore *pPropertyStore = NULL; PROPVARIANT propVariant; HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pShellLink)); EXIT_ON_ERROR(hr); // Path hr = pShellLink->SetPath(path); EXIT_ON_ERROR(hr); // Arguments hr = pShellLink->SetArguments(arguments); EXIT_ON_ERROR(hr); // Icon Location hr = pShellLink->SetIconLocation(wstring(icon).empty() ? path : icon, 0); EXIT_ON_ERROR(hr); hr = pShellLink->QueryInterface(IID_PPV_ARGS(&pPropertyStore)); EXIT_ON_ERROR(hr); // Name hr = InitPropVariantFromString(name, &propVariant); EXIT_ON_ERROR(hr); hr = pPropertyStore->SetValue(PKEY_Title, propVariant); EXIT_ON_ERROR(hr); hr = pPropertyStore->Commit(); EXIT_ON_ERROR(hr); // SHAddToRecentDocs will cause the link to be added to the Recent list, allowing the user to pin them. SHAddToRecentDocs(SHARD_LINK, pShellLink); Exit: PropVariantClear(&propVariant); SAFE_RELEASE(pPropertyStore); SAFE_RELEASE(pShellLink); return hr; }
HRESULT CreateShellLink(PCWSTR pszArguments, PCWSTR pszTitle, int iconIndex, IShellLink **ppsl) { ATL::CComPtr<IShellLink> psl; HRESULT hr = psl.CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER); if (FAILED(hr)) return hr; WCHAR szAppPath[MAX_PATH]; if (GetModuleFileName(NULL, szAppPath, _countof(szAppPath)) == 0) { hr = HRESULT_FROM_WIN32(GetLastError()); return hr; } hr = psl->SetPath(szAppPath); if (FAILED(hr)) return hr; hr = psl->SetArguments(pszArguments); if (FAILED(hr)) return hr; hr = psl->SetIconLocation(szAppPath, iconIndex); if (FAILED(hr)) return hr; ATL::CComPtr<IPropertyStore> pps; hr = psl.QueryInterface(&pps); if (FAILED(hr)) return hr; PROPVARIANT propvar; hr = InitPropVariantFromString(pszTitle, &propvar); if (SUCCEEDED(hr)) { hr = pps->SetValue(PKEY_Title, propvar); if (SUCCEEDED(hr)) { hr = pps->Commit(); if (SUCCEEDED(hr)) { hr = psl.QueryInterface(ppsl); } } PropVariantClear(&propvar); } return hr; }
HRESULT SetShortcutProps(LPCWSTR aShortcutPath, LPCWSTR aAppModelID, bool aSetID, bool aSetMode) { HRESULT hres; ::CoInitialize(nullptr); IPropertyStore *m_pps = nullptr; if (FAILED(hres = SHGetPropertyStoreFromParsingName(aShortcutPath, nullptr, GPS_READWRITE, IID_PPV_ARGS(&m_pps)))) { printf("SHGetPropertyStoreFromParsingName failed\n"); goto Exit; } if (aSetMode) { PROPVARIANT propvar; if (FAILED(hres = InitPropVariantFromBoolean(true, &propvar)) || FAILED(hres = m_pps->SetValue(PKEY_AppUserModel_IsDualMode, propvar))) { goto Exit; } PropVariantClear(&propvar); } if (aSetID && aAppModelID) { PROPVARIANT propvar; if (FAILED(hres = InitPropVariantFromString(aAppModelID, &propvar)) || FAILED(hres = m_pps->SetValue(PKEY_AppUserModel_ID, propvar))) { goto Exit; } PropVariantClear(&propvar); } hres = m_pps->Commit(); Exit: if (m_pps) { m_pps->Release(); } CoUninitialize(); return hres; }
STDMETHODIMP CLocationReport::GetValue(REFPROPERTYKEY pKey, PROPVARIANT *pValue) { HRESULT hr = S_OK; // properties for civic address reports if (pKey.pid == SENSOR_DATA_TYPE_ADDRESS1.pid) { hr = InitPropVariantFromString(m_address1, pValue); } else if (pKey.pid == SENSOR_DATA_TYPE_ADDRESS2.pid) { hr = InitPropVariantFromString(m_address2, pValue); } else if (pKey.pid == SENSOR_DATA_TYPE_CITY.pid) { hr = InitPropVariantFromString(m_city, pValue); } else if (pKey.pid == SENSOR_DATA_TYPE_STATE_PROVINCE.pid) { hr = InitPropVariantFromString(m_stateprovince, pValue); } else if (pKey.pid == SENSOR_DATA_TYPE_POSTALCODE.pid) { hr = InitPropVariantFromString(m_postalcode, pValue); } else if (pKey.pid == SENSOR_DATA_TYPE_COUNTRY_REGION.pid) { hr = InitPropVariantFromString(m_countryregion, pValue); } // properties for latitude/longitude reports else if (pKey.pid == SENSOR_DATA_TYPE_LATITUDE_DEGREES.pid) { hr = InitPropVariantFromDouble(m_latitude, pValue); } else if (pKey.pid == SENSOR_DATA_TYPE_LONGITUDE_DEGREES.pid) { hr = InitPropVariantFromDouble(m_longitude, pValue); } else if (pKey.pid == SENSOR_DATA_TYPE_ERROR_RADIUS_METERS.pid) { hr = InitPropVariantFromDouble(m_errorradius, pValue); } else { hr = HRESULT_FROM_WIN32(ERROR_NO_DATA); PropVariantInit(pValue); } return hr; }
void CWin7::SetAppID(HWND hWnd, bool bDestory ) { IPropertyStore *pps; HRESULT hr = SHGetPropertyStoreForWindow2(hWnd, IID_PPV_ARGS(&pps)); if (SUCCEEDED(hr)) { PROPVARIANT pv; if ( !bDestory ) hr = InitPropVariantFromString(g_wszAppID, &pv); else PropVariantInit(&pv); if (SUCCEEDED(hr)) { hr = pps->SetValue(PKEY_AppUserModel_ID, pv); PropVariantClear(&pv); } pps->Release(); } }
// (static) Creates a ShellLink that encapsulate a shortcut to local apps. nsresult JumpListShortcut::GetShellLink(nsCOMPtr<nsIJumpListItem>& item, nsRefPtr<IShellLinkW>& aShellLink, nsCOMPtr<nsIThread> &aIOThread) { HRESULT hr; IShellLinkW* psl; nsresult rv; // Shell links: // http://msdn.microsoft.com/en-us/library/bb776891(VS.85).aspx // http://msdn.microsoft.com/en-us/library/bb774950(VS.85).aspx int16_t type; if (NS_FAILED(item->GetType(&type))) return NS_ERROR_INVALID_ARG; if (type != nsIJumpListItem::JUMPLIST_ITEM_SHORTCUT) return NS_ERROR_INVALID_ARG; nsCOMPtr<nsIJumpListShortcut> shortcut = do_QueryInterface(item, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsILocalHandlerApp> handlerApp; rv = shortcut->GetApp(getter_AddRefs(handlerApp)); NS_ENSURE_SUCCESS(rv, rv); // Create a IShellLink hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (LPVOID*)&psl); if (FAILED(hr)) return NS_ERROR_UNEXPECTED; // Retrieve the app path, title, description and optional command line args. nsAutoString appPath, appTitle, appDescription, appArgs; int32_t appIconIndex = 0; // Path nsCOMPtr<nsIFile> executable; handlerApp->GetExecutable(getter_AddRefs(executable)); rv = executable->GetPath(appPath); NS_ENSURE_SUCCESS(rv, rv); // Command line parameters uint32_t count = 0; handlerApp->GetParameterCount(&count); for (uint32_t idx = 0; idx < count; idx++) { if (idx > 0) appArgs.Append(NS_LITERAL_STRING(" ")); nsAutoString param; rv = handlerApp->GetParameter(idx, param); if (NS_FAILED(rv)) return rv; appArgs.Append(param); } handlerApp->GetName(appTitle); handlerApp->GetDetailedDescription(appDescription); bool useUriIcon = false; // if we want to use the URI icon bool usedUriIcon = false; // if we did use the URI icon shortcut->GetIconIndex(&appIconIndex); nsCOMPtr<nsIURI> iconUri; rv = shortcut->GetFaviconPageUri(getter_AddRefs(iconUri)); if (NS_SUCCEEDED(rv) && iconUri) { useUriIcon = true; } // Store the title of the app if (appTitle.Length() > 0) { IPropertyStore* pPropStore = nullptr; hr = psl->QueryInterface(IID_IPropertyStore, (LPVOID*)&pPropStore); if (FAILED(hr)) return NS_ERROR_UNEXPECTED; PROPVARIANT pv; InitPropVariantFromString(appTitle.get(), &pv); pPropStore->SetValue(PKEY_Title, pv); pPropStore->Commit(); pPropStore->Release(); PropVariantClear(&pv); } // Store the rest of the params psl->SetPath(appPath.get()); psl->SetDescription(appDescription.get()); psl->SetArguments(appArgs.get()); if (useUriIcon) { nsString icoFilePath; rv = mozilla::widget::FaviconHelper::ObtainCachedIconFile(iconUri, icoFilePath, aIOThread, false); if (NS_SUCCEEDED(rv)) { // Always use the first icon in the ICO file // our encoded icon only has 1 resource psl->SetIconLocation(icoFilePath.get(), 0); usedUriIcon = true; } } // We didn't use an ICO via URI so fall back to the app icon if (!usedUriIcon) { psl->SetIconLocation(appPath.get(), appIconIndex); } aShellLink = dont_AddRef(psl); return NS_OK; }
static HRESULT register_task(IObjectCollection *pobjs, wstring title, wstring cmd, wstring icon, int ii) { HRESULT hr = S_OK; IShellLinkW *pShellLink; if (!cmd || !*cmd) return S_OK; wstring show_title = (!title || !*title) ? cmd : title; wchar exe_path[MAX_PATH + 1]; if (GetModuleFileNameW(NULL, exe_path, MAX_PATH) == 0) return S_FALSE; //printf("register_task <%ls>: <%ls> <%ls>\n", title, exe_path, cmd); hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (void **)&pShellLink); if (SUCCEEDED(hr)) { do { // set title IPropertyStore *pPropertyStore; hr = pShellLink->lpVtbl->QueryInterface((void *)pShellLink, &IID_IPropertyStore, (void **)&pPropertyStore); if (SUCCEEDED(hr)) { PROPVARIANT propVariant; hr = InitPropVariantFromString(show_title, &propVariant); if (SUCCEEDED(hr)) { hr = pPropertyStore->lpVtbl->SetValue((void *)pPropertyStore, &PKEY_Title, &propVariant); if (SUCCEEDED(hr)) { pPropertyStore->lpVtbl->Commit((void *)pPropertyStore); } } } if (FAILED(hr)) break; // set icon path and index if (icon) hr = pShellLink->lpVtbl->SetIconLocation((void *)pShellLink, icon, ii); else hr = pShellLink->lpVtbl->SetIconLocation((void *)pShellLink, exe_path, 0); if (FAILED(hr)) break; // set full path of mintty.exe hr = pShellLink->lpVtbl->SetPath((void *)pShellLink, exe_path); if (FAILED(hr)) break; // set arguments hr = pShellLink->lpVtbl->SetArguments((void *)pShellLink, cmd); if (FAILED(hr)) break; // finally, register this column into the jump list hr = pobjs->lpVtbl->AddObject((void *)pobjs, (IUnknown *)pShellLink); } while (0); pShellLink->lpVtbl->Release((void *)pShellLink); } return hr; }
void TaskList::addToRecentList(QString name, QString user, QString host, int port) { if (! bIsWin7) return; HRESULT hr; IShellLink *link = NULL; IPropertyStore *ps = NULL; PROPVARIANT pt; hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, __uuidof(IShellLink), reinterpret_cast<void **>(&link)); if (!link || FAILED(hr)) return; QUrl url; url.setScheme(QLatin1String("mumble")); url.setUserName(user); url.setHost(host); url.setPort(port); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QUrlQuery query; query.addQueryItem(QLatin1String("title"), name); query.addQueryItem(QLatin1String("version"), QLatin1String("1.2.0")); url.setQuery(query); #else url.addQueryItem(QLatin1String("title"), name); url.addQueryItem(QLatin1String("version"), QLatin1String("1.2.0")); #endif QSettings settings(QLatin1String("HKEY_CLASSES_ROOT"), QSettings::NativeFormat); QString app = settings.value(QLatin1String("mumble/DefaultIcon/.")).toString(); if (app.isEmpty() || ! QFileInfo(app).exists()) app = QCoreApplication::applicationFilePath(); link->SetPath(app.toStdWString().c_str()); link->SetArguments(QString::fromLatin1(url.toEncoded()).toStdWString().c_str()); hr = link->QueryInterface(__uuidof(IPropertyStore), reinterpret_cast<void **>(&ps)); if (FAILED(hr)) { qFatal("TaskList: Failed to get property store"); goto cleanup; } InitPropVariantFromString(name.toStdWString().c_str(), &pt); hr = ps->SetValue(PKEY_Title, pt); PropVariantClear(&pt); if (FAILED(hr)) { qFatal("TaskList: Failed to set title"); goto cleanup; } hr = ps->Commit(); if (FAILED(hr)) { qFatal("TaskList: Failed commit"); goto cleanup; } SHAddToRecentDocs(SHARD_LINK, link); cleanup: if (ps) ps->Release(); if (link) link->Release(); }
//------------------------------------------------------------------------------ // Function: Initialize // // This routine initializes the sensor to its default properties // // Arguments: // Device: IN: WDFDEVICE object // SensorInstance: IN: SENSOROBJECT for each sensor instance // // Return Value: // NTSTATUS code //------------------------------------------------------------------------------ NTSTATUS PrxDevice::Initialize( _In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorInstance ) { NTSTATUS Status = STATUS_SUCCESS; SENSOR_FunctionEnter(); // // Store device and instance // m_Device = Device; m_SensorInstance = SensorInstance; m_Started = FALSE; // // Create Lock // Status = WdfWaitLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &m_Lock); if (!NT_SUCCESS(Status)) { TraceError("COMBO %!FUNC! PRX WdfWaitLockCreate failed %!STATUS!", Status); goto Exit; } // // Create timer object for polling sensor samples // { WDF_OBJECT_ATTRIBUTES TimerAttributes; WDF_TIMER_CONFIG TimerConfig; WDF_TIMER_CONFIG_INIT(&TimerConfig, OnTimerExpire); WDF_OBJECT_ATTRIBUTES_INIT(&TimerAttributes); TimerAttributes.ParentObject = SensorInstance; TimerAttributes.ExecutionLevel = WdfExecutionLevelPassive; Status = WdfTimerCreate(&TimerConfig, &TimerAttributes, &m_Timer); if (!NT_SUCCESS(Status)) { TraceError("COMBO %!FUNC! PRX WdfTimerCreate failed %!STATUS!", Status); goto Exit; } } // // Sensor Enumeration Properties // { WDF_OBJECT_ATTRIBUTES MemoryAttributes; WDFMEMORY MemoryHandle = NULL; ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_PRX_ENUMERATION_PROPERTY_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSORV2_POOL_TAG_PROXIMITY, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pEnumerationProperties)); if (!NT_SUCCESS(Status) || nullptr == m_pEnumerationProperties) { TraceError("COMBO %!FUNC! PRX WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pEnumerationProperties, Size); m_pEnumerationProperties->Count = SENSOR_ENUMERATION_PROPERTIES_COUNT; m_pEnumerationProperties->Count = SENSOR_PRX_ENUMERATION_PROPERTY_COUNT; m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; InitPropVariantFromCLSID(GUID_SensorType_Proximity, &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; InitPropVariantFromString(L"Manufacturer name", &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; InitPropVariantFromString(L"PRX", &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Key = DEVPKEY_Sensor_ConnectionType; // The DEVPKEY_Sensor_ConnectionType values match the SensorConnectionType enumeration InitPropVariantFromUInt32(static_cast<ULONG>(SensorConnectionType::Integrated), &(m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Value)); m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Key = DEVPKEY_Sensor_PersistentUniqueId; InitPropVariantFromCLSID(GUID_PrxDevice_UniqueID, &(m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Value)); m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Key = DEVPKEY_Sensor_IsPrimary; InitPropVariantFromBoolean(FALSE, &(m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Value)); m_pEnumerationProperties->List[SENSOR_PROPERTY_PRX_TYPE].Key = DEVPKEY_Sensor_ProximityType; InitPropVariantFromUInt32(PROXIMITY_TYPE::ProximityType_HumanProximity, &(m_pEnumerationProperties->List[SENSOR_PROPERTY_PRX_TYPE].Value)); m_pEnumerationProperties->List[SENSOR_ISWAKECAPABLE].Key = PKEY_Sensor_WakeCapable; InitPropVariantFromBoolean(FALSE, &(m_pEnumerationProperties->List[SENSOR_ISWAKECAPABLE].Value)); } // // Supported Data-Fields // { WDF_OBJECT_ATTRIBUTES MemoryAttributes; WDFMEMORY MemoryHandle = NULL; ULONG Size = SENSOR_PROPERTY_LIST_SIZE(PRX_DATA_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSORV2_POOL_TAG_PROXIMITY, Size, &MemoryHandle, (PVOID*)&m_pSupportedDataFields); if (!NT_SUCCESS(Status) || m_pSupportedDataFields == nullptr) { TraceError("COMBO %!FUNC! PRX WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); m_pSupportedDataFields->Count = PRX_DATA_COUNT; m_pSupportedDataFields->List[PRX_DATA_TIMESTAMP] = PKEY_SensorData_Timestamp; m_pSupportedDataFields->List[PRX_DATA_DETECT] = PKEY_SensorData_ProximityDetection; m_pSupportedDataFields->List[PRX_DATA_DISTANCE] = PKEY_SensorData_ProximityDistanceMillimeters; } // // Data // { WDF_OBJECT_ATTRIBUTES MemoryAttributes; WDFMEMORY MemoryHandle = NULL; ULONG Size = SENSOR_COLLECTION_LIST_SIZE(PRX_DATA_COUNT); FILETIME Time = {}; MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSORV2_POOL_TAG_PROXIMITY, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pData)); if (!NT_SUCCESS(Status) || nullptr == m_pData) { TraceError("COMBO %!FUNC! PRX WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pData, Size); m_pData->Count = PRX_DATA_COUNT; m_pData->List[PRX_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; GetSystemTimePreciseAsFileTime(&Time); InitPropVariantFromFileTime(&Time, &(m_pData->List[PRX_DATA_TIMESTAMP].Value)); m_pData->List[PRX_DATA_DETECT].Key = PKEY_SensorData_ProximityDetection; InitPropVariantFromBoolean(FALSE, &(m_pData->List[PRX_DATA_DETECT].Value)); m_pData->List[PRX_DATA_DISTANCE].Key = PKEY_SensorData_ProximityDistanceMillimeters; InitPropVariantFromUInt32(FALSE, &(m_pData->List[PRX_DATA_DISTANCE].Value)); m_CachedData.Detected = FALSE; m_CachedData.DistanceMillimeters = PrxDevice_Maximum_Millimeters; m_LastSample.Detected = FALSE; m_LastSample.DistanceMillimeters = PrxDevice_Maximum_Millimeters; } // // Sensor Properties // { WDF_OBJECT_ATTRIBUTES MemoryAttributes; WDFMEMORY MemoryHandle = NULL; ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_COMMON_PROPERTY_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSORV2_POOL_TAG_PROXIMITY, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pProperties)); if (!NT_SUCCESS(Status) || nullptr == m_pProperties) { TraceError("COMBO %!FUNC! PRX WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pProperties, Size); m_pProperties->Count = SENSOR_COMMON_PROPERTY_COUNT; m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Key = PKEY_Sensor_State; InitPropVariantFromUInt32(SensorState_Initializing, &(m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Value)); m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Key = PKEY_Sensor_MinimumDataInterval_Ms; InitPropVariantFromUInt32(Prx_MinDataInterval_Ms, &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Value)); m_IntervalMs = Prx_MinDataInterval_Ms; m_MinimumIntervalMs = Prx_MinDataInterval_Ms; m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Key = PKEY_Sensor_MaximumDataFieldSize_Bytes; InitPropVariantFromUInt32(CollectionsListGetMarshalledSize(m_pData), &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Value)); m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Key = PKEY_Sensor_Type; InitPropVariantFromCLSID(GUID_SensorType_Proximity, &(m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Value)); } // // Data field properties // { WDF_OBJECT_ATTRIBUTES MemoryAttributes; WDFMEMORY MemoryHandle = NULL; ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_DATA_FIELD_PROPERTY_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSORV2_POOL_TAG_PROXIMITY, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pDataFieldProperties)); if (!NT_SUCCESS(Status) || nullptr == m_pDataFieldProperties) { TraceError("COMBO %!FUNC! PRX WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pDataFieldProperties, Size); m_pDataFieldProperties->Count = SENSOR_DATA_FIELD_PROPERTY_COUNT; m_pDataFieldProperties->List[SENSOR_RESOLUTION].Key = PKEY_SensorDataField_Resolution; InitPropVariantFromUInt32(PrxDevice_Resolution_Millimeters, &(m_pDataFieldProperties->List[SENSOR_RESOLUTION].Value)); m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Key = PKEY_SensorDataField_RangeMinimum; InitPropVariantFromUInt32(PrxDevice_Minimum_Millimeters, &(m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Value)); m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Key = PKEY_SensorDataField_RangeMaximum; InitPropVariantFromUInt32(PrxDevice_Maximum_Millimeters, &(m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Value)); } // // Set default threshold // { WDF_OBJECT_ATTRIBUTES MemoryAttributes; WDFMEMORY MemoryHandle = NULL; ULONG Size = SENSOR_COLLECTION_LIST_SIZE(PRX_THRESHOLD_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSORV2_POOL_TAG_PROXIMITY, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pThresholds)); if (!NT_SUCCESS(Status) || nullptr == m_pThresholds) { TraceError("COMBO %!FUNC! PRX WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pThresholds, Size); m_FirstSample = TRUE; } Exit: SENSOR_FunctionExit(Status); return Status; }
// This routine initializes the sensor's enumeration properties NTSTATUS ActivityDevice::InitializeEnumerationProperties() { WDF_OBJECT_ATTRIBUTES memoryAttributes = {}; WDFMEMORY memoryHandle = NULL; const ULONG size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_ENUMERATION_PROPERTIES_COUNT); NTSTATUS status = STATUS_SUCCESS; SENSOR_FunctionEnter(); WDF_OBJECT_ATTRIBUTES_INIT(&memoryAttributes); memoryAttributes.ParentObject = m_SensorInstance; status = WdfMemoryCreate(&memoryAttributes, PagedPool, SENSOR_POOL_TAG_ACTIVITY, size, &memoryHandle, reinterpret_cast<PVOID*>(&m_pEnumerationProperties)); if (!NT_SUCCESS(status) || nullptr == m_pEnumerationProperties) { TraceError("ACT %!FUNC! WdfMemoryCreate failed %!STATUS!", status); } else { SENSOR_COLLECTION_LIST_INIT(m_pEnumerationProperties, size); m_pEnumerationProperties->Count = SENSOR_ENUMERATION_PROPERTIES_COUNT; m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; InitPropVariantFromCLSID(GUID_SensorType_ActivityDetection, &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; InitPropVariantFromString(L"Microsoft", &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; InitPropVariantFromString(L"Fake ACTIVITY V2", &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Key = DEVPKEY_Sensor_PersistentUniqueId; InitPropVariantFromCLSID(GUID_ActivityDevice_UniqueID, &(m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Value)); m_pEnumerationProperties->List[SENSOR_CATEGORY].Key = DEVPKEY_Sensor_Category; InitPropVariantFromCLSID(GUID_SensorCategory_Motion, &(m_pEnumerationProperties->List[SENSOR_CATEGORY].Value)); m_pEnumerationProperties->List[SENSOR_MIN_INTERVAL].Key = PKEY_Sensor_MinimumDataInterval_Ms; InitPropVariantFromUInt32(Act_Default_MinDataInterval_Ms, &(m_pEnumerationProperties->List[SENSOR_MIN_INTERVAL].Value)); m_pEnumerationProperties->List[SENSOR_POWER].Key = PKEY_Sensor_Power_Milliwatts; InitPropVariantFromFloat((m_HistoryPowerInuW / 1000.0f), &(m_pEnumerationProperties->List[SENSOR_POWER].Value)); m_pEnumerationProperties->List[SENSOR_SUPPORTEDACTIVITIES].Key = PKEY_SensorData_SupportedActivityStates; InitPropVariantFromUInt32(Act_Default_SubscribedStates, &(m_pEnumerationProperties->List[SENSOR_SUPPORTEDACTIVITIES].Value)); m_pEnumerationProperties->List[SENSOR_MAX_HISTORYSIZE].Key = PKEY_SensorHistory_MaxSize_Bytes; InitPropVariantFromUInt32(SENSOR_COLLECTION_LIST_HEADER_SIZE + ((m_HistoryMarshalledRecordSize - SENSOR_COLLECTION_LIST_HEADER_SIZE) * m_HistorySizeInRecords), &(m_pEnumerationProperties->List[SENSOR_MAX_HISTORYSIZE].Value)); // History only logs one most probable state } SENSOR_FunctionExit(status); return status; }
// This routine initializes the sensor to its default properties NTSTATUS PedometerDevice::Initialize( _In_ WDFDEVICE Device, // WDFDEVICE object _In_ SENSOROBJECT SensorInstance // SENSOROBJECT for each sensor instance ) { ULONG Size = 0; WDF_OBJECT_ATTRIBUTES MemoryAttributes; WDFMEMORY MemoryHandle = NULL; FILETIME Time = {}; WDF_OBJECT_ATTRIBUTES TimerAttributes; WDF_TIMER_CONFIG TimerConfig; NTSTATUS Status = STATUS_SUCCESS; PHardwareSimulator pSimulator = nullptr; ULONG HistorySizeInRecords = 0; SENSOR_FunctionEnter(); // Store device and instance m_FxDevice = Device; m_SensorInstance = SensorInstance; m_Started = FALSE; m_HistoryRetrievalStarted = FALSE; // Initialize the pedometer simulator Status = HardwareSimulator::Initialize(Device, &m_SimulatorInstance); if (!NT_SUCCESS(Status)) { TraceError("PED %!FUNC! HardwareSimulator::Initialize failed %!STATUS!", Status); goto Exit; } pSimulator = GetHardwareSimulatorContextFromInstance(m_SimulatorInstance); if (nullptr == pSimulator) { Status = STATUS_INSUFFICIENT_RESOURCES; TraceError("PED %!FUNC! GetHardwareSimulatorContextFromInstance failed %!STATUS!", Status); goto Exit; } // Create Lock Status = WdfWaitLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &m_Lock); if (!NT_SUCCESS(Status)) { TraceError("PED %!FUNC! WdfWaitLockCreate failed %!STATUS!", Status); goto Exit; } // Create timer object for polling sensor samples WDF_TIMER_CONFIG_INIT(&TimerConfig, PedometerDevice::OnTimerExpire); WDF_OBJECT_ATTRIBUTES_INIT(&TimerAttributes); TimerAttributes.ParentObject = SensorInstance; TimerAttributes.ExecutionLevel = WdfExecutionLevelPassive; Status = WdfTimerCreate(&TimerConfig, &TimerAttributes, &m_Timer); if (!NT_SUCCESS(Status)) { TraceError("PED %!FUNC! WdfTimerCreate failed %!STATUS!", Status); goto Exit; } // Supported Data-Fields Size = SENSOR_PROPERTY_LIST_SIZE(PEDOMETER_DATAFIELD_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSOR_POOL_TAG_PEDOMETER, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pSupportedDataFields)); if (!NT_SUCCESS(Status) || nullptr == m_pSupportedDataFields) { TraceError("PED %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); m_pSupportedDataFields->Count = PEDOMETER_DATAFIELD_COUNT; m_pSupportedDataFields->List[PEDOMETER_DATAFIELD_TIMESTAMP] = PKEY_SensorData_Timestamp; m_pSupportedDataFields->List[PEDOMETER_DATAFIELD_FIRST_AFTER_RESET] = PKEY_SensorData_PedometerReset; m_pSupportedDataFields->List[PEDOMETER_DATAFIELD_STEP_TYPE] = PKEY_SensorData_PedometerStepType; m_pSupportedDataFields->List[PEDOMETER_DATAFIELD_STEP_COUNT] = PKEY_SensorData_PedometerStepCount; m_pSupportedDataFields->List[PEDOMETER_DATAFIELD_STEP_DURATION] = PKEY_SensorData_PedometerStepDuration_Ms; // Data Size = SENSOR_COLLECTION_LIST_SIZE(PEDOMETER_DATA_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSOR_POOL_TAG_PEDOMETER, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pData)); if (!NT_SUCCESS(Status) || nullptr == m_pData) { TraceError("PED %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pData, Size); m_pData->Count = PEDOMETER_DATA_COUNT; m_pData->List[PEDOMETER_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; GetSystemTimePreciseAsFileTime(&Time); InitPropVariantFromFileTime(&Time, &(m_pData->List[PEDOMETER_DATA_TIMESTAMP].Value)); m_pData->List[PEDOMETER_DATA_FIRST_AFTER_RESET].Key = PKEY_SensorData_PedometerReset; InitPropVariantFromBoolean(FALSE, &(m_pData->List[PEDOMETER_DATA_FIRST_AFTER_RESET].Value)); m_pData->List[PEDOMETER_DATA_UNKNOWN_STEP_TYPE].Key = PKEY_SensorData_PedometerStepType; InitPropVariantFromUInt32(static_cast<ULONG>(PedometerStepType_Unknown), &(m_pData->List[PEDOMETER_DATA_UNKNOWN_STEP_TYPE].Value)); m_pData->List[PEDOMETER_DATA_UNKNOWN_STEP_COUNT].Key = PKEY_SensorData_PedometerStepCount; InitPropVariantFromUInt32(600, &(m_pData->List[PEDOMETER_DATA_UNKNOWN_STEP_COUNT].Value)); m_pData->List[PEDOMETER_DATA_UNKNOWN_STEP_DURATION].Key = PKEY_SensorData_PedometerStepDuration_Ms; InitPropVariantFromInt64(123, &(m_pData->List[PEDOMETER_DATA_UNKNOWN_STEP_DURATION].Value)); m_pData->List[PEDOMETER_DATA_WALKING_STEP_TYPE].Key = PKEY_SensorData_PedometerStepType; InitPropVariantFromUInt32(static_cast<ULONG>(PedometerStepType_Walking), &(m_pData->List[PEDOMETER_DATA_WALKING_STEP_TYPE].Value)); m_pData->List[PEDOMETER_DATA_WALKING_STEP_COUNT].Key = PKEY_SensorData_PedometerStepCount; InitPropVariantFromUInt32(700, &(m_pData->List[PEDOMETER_DATA_WALKING_STEP_COUNT].Value)); m_pData->List[PEDOMETER_DATA_WALKING_STEP_DURATION].Key = PKEY_SensorData_PedometerStepDuration_Ms; InitPropVariantFromInt64(456, &(m_pData->List[PEDOMETER_DATA_WALKING_STEP_DURATION].Value)); m_pData->List[PEDOMETER_DATA_RUNNING_STEP_TYPE].Key = PKEY_SensorData_PedometerStepType; InitPropVariantFromUInt32(static_cast<ULONG>(PedometerStepType_Running), &(m_pData->List[PEDOMETER_DATA_RUNNING_STEP_TYPE].Value)); m_pData->List[PEDOMETER_DATA_RUNNING_STEP_COUNT].Key = PKEY_SensorData_PedometerStepCount; InitPropVariantFromUInt32(800, &(m_pData->List[PEDOMETER_DATA_RUNNING_STEP_COUNT].Value)); m_pData->List[PEDOMETER_DATA_RUNNING_STEP_DURATION].Key = PKEY_SensorData_PedometerStepDuration_Ms; InitPropVariantFromInt64(789, &(m_pData->List[PEDOMETER_DATA_RUNNING_STEP_DURATION].Value)); m_LastSample.Timestamp = Time; m_LastSample.UnknownStepCount = 0; m_LastSample.UnknownStepDurationMs = 0; m_LastSample.WalkingStepCount = 0; m_LastSample.WalkingStepDurationMs = 0; m_LastSample.RunningStepCount = 0; m_LastSample.RunningStepDurationMs = 0; m_LastSample.IsFirstAfterReset = FALSE; // Get the History Size to populate 'PKEY_SensorHistory_MaxSize_Bytes' // Typically the size needed to store a history record on the hardware is // smaller than the size needed to represent a history record as a // SENSOR_COLLECTION_LIST (collection of SENSOR_VALUE_PAIRs) // To be able to accurately represent the size of the history on the // hardware (simulator in this case), get the number of records that the HW // can store and multiply it with the marshalled size of // SENSOR_COLLECTION_LIST needed to represent a single record. HistorySizeInRecords = pSimulator->GetHistorySizeInRecords(); m_HistorySupported = (HistorySizeInRecords > 0) ? TRUE : FALSE; // Pedometer History format is exactly same as it's data sample. // so, we can simply reuse the 'm_pData' to compute the marshalled size // History Retrieval is not WOW64 compatible and hence will not involve // serializing the collections list. Should Use // CollectionsListGetMarshalledSizeWithoutSerialization instead of // CollectionsListGetMarshalledSize when dealing with History Collection list. m_HistoryMarshalledRecordSize = CollectionsListGetMarshalledSizeWithoutSerialization(m_pData); // Sensor Enumeration Properties Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_ENUMERATION_PROPERTIES_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSOR_POOL_TAG_PEDOMETER, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pEnumerationProperties)); if (!NT_SUCCESS(Status) || nullptr == m_pEnumerationProperties) { TraceError("PED %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pEnumerationProperties, Size); m_pEnumerationProperties->Count = SENSOR_ENUMERATION_PROPERTIES_COUNT; m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; InitPropVariantFromCLSID(GUID_SensorType_Pedometer, &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; InitPropVariantFromString(L"Microsoft", &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; InitPropVariantFromString(L"PEDOMETER", &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Key = DEVPKEY_Sensor_PersistentUniqueId; InitPropVariantFromCLSID(GUID_PedometerDevice_UniqueID, &(m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Value)); m_pEnumerationProperties->List[SENSOR_CATEGORY].Key = DEVPKEY_Sensor_Category; InitPropVariantFromCLSID(GUID_SensorCategory_Motion, &(m_pEnumerationProperties->List[SENSOR_CATEGORY].Value)); m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Key = DEVPKEY_Sensor_IsPrimary; InitPropVariantFromBoolean(FALSE, &(m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Value)); // This value should be set to TRUE if multiple pedometers // exist on the system and this sensor is the primary sensor m_pEnumerationProperties->List[SENSOR_POWER].Key = PKEY_Sensor_Power_Milliwatts; InitPropVariantFromFloat(Pedometer_Default_Power_Milliwatts, &(m_pEnumerationProperties->List[SENSOR_POWER].Value)); m_pEnumerationProperties->List[SENSOR_MAX_HISTORYSIZE].Key = PKEY_SensorHistory_MaxSize_Bytes; InitPropVariantFromUInt32(((FALSE != m_HistorySupported) ? (SENSOR_COLLECTION_LIST_HEADER_SIZE + ((m_HistoryMarshalledRecordSize - SENSOR_COLLECTION_LIST_HEADER_SIZE) * HistorySizeInRecords)) : 0), &(m_pEnumerationProperties->List[SENSOR_MAX_HISTORYSIZE].Value)); m_pEnumerationProperties->List[SENSOR_SUPPORTED_STEPTYPES].Key = PKEY_SensorData_SupportedStepTypes; InitPropVariantFromUInt32(PedometerStepType_Unknown | PedometerStepType_Walking | PedometerStepType_Running, &(m_pEnumerationProperties->List[SENSOR_SUPPORTED_STEPTYPES].Value)); // Sensor Properties m_Interval = Pedometer_Default_MinDataInterval_Ms; Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_COMMON_PROPERTIES_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSOR_POOL_TAG_PEDOMETER, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pProperties)); if (!NT_SUCCESS(Status) || nullptr == m_pProperties) { TraceError("PED %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pProperties, Size); m_pProperties->Count = SENSOR_COMMON_PROPERTIES_COUNT; m_pProperties->List[SENSOR_PROPERTY_STATE].Key = PKEY_Sensor_State; InitPropVariantFromUInt32(SensorState_Initializing, &(m_pProperties->List[SENSOR_PROPERTY_STATE].Value)); m_pProperties->List[SENSOR_PROPERTY_MIN_INTERVAL].Key = PKEY_Sensor_MinimumDataInterval_Ms; InitPropVariantFromUInt32(Pedometer_Default_MinDataInterval_Ms, &(m_pProperties->List[SENSOR_PROPERTY_MIN_INTERVAL].Value)); m_pProperties->List[SENSOR_PROPERTY_MAX_DATAFIELDSIZE].Key = PKEY_Sensor_MaximumDataFieldSize_Bytes; InitPropVariantFromUInt32(CollectionsListGetMarshalledSize(m_pData), &(m_pProperties->List[SENSOR_PROPERTY_MAX_DATAFIELDSIZE].Value)); m_pProperties->List[SENSOR_PROPERTY_SENSOR_TYPE].Key = PKEY_Sensor_Type; InitPropVariantFromCLSID(GUID_SensorType_Pedometer, &(m_pProperties->List[SENSOR_PROPERTY_SENSOR_TYPE].Value)); m_pProperties->List[SENSOR_PROPERTY_SENSOR_POWER].Key = PKEY_Sensor_Power_Milliwatts; InitPropVariantFromFloat(Pedometer_Default_Power_Milliwatts, &(m_pProperties->List[SENSOR_PROPERTY_SENSOR_POWER].Value)); m_pProperties->List[SENSOR_PROPERTY_MAX_HISTORYSIZE].Key = PKEY_SensorHistory_MaxSize_Bytes; InitPropVariantFromUInt32(((FALSE != m_HistorySupported) ? (SENSOR_COLLECTION_LIST_HEADER_SIZE + ((m_HistoryMarshalledRecordSize - SENSOR_COLLECTION_LIST_HEADER_SIZE) * HistorySizeInRecords)) : 0), &(m_pProperties->List[SENSOR_PROPERTY_MAX_HISTORYSIZE].Value)); m_pProperties->List[SENSOR_PROPERTY_HISTORY_INTERVAL].Key = PKEY_SensorHistory_Interval_Ms; InitPropVariantFromUInt32(pSimulator->GetHistoryIntervalInMs(), &(m_pProperties->List[SENSOR_PROPERTY_HISTORY_INTERVAL].Value)); m_pProperties->List[SENSOR_PROPERTY_MAX_HISTROYRECORDSIZE].Key = PKEY_SensorHistory_MaximumRecordSize_Bytes; InitPropVariantFromUInt32(m_HistoryMarshalledRecordSize, &(m_pProperties->List[SENSOR_PROPERTY_MAX_HISTROYRECORDSIZE].Value)); m_pProperties->List[SENSOR_PROPERTY_SUPPORTED_STEPTYPES].Key = PKEY_SensorData_SupportedStepTypes; InitPropVariantFromUInt32(PedometerStepType_Unknown | PedometerStepType_Walking | PedometerStepType_Running, &(m_pProperties->List[SENSOR_PROPERTY_SUPPORTED_STEPTYPES].Value)); // Data field properties Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_DATA_FIELD_PROPERTY_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSOR_POOL_TAG_PEDOMETER, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pDataFieldProperties)); if (!NT_SUCCESS(Status) || nullptr == m_pDataFieldProperties) { TraceError("PED %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pDataFieldProperties, Size); m_pDataFieldProperties->Count = SENSOR_DATA_FIELD_PROPERTY_COUNT; m_pDataFieldProperties->List[SENSOR_RESOLUTION].Key = PKEY_SensorDataField_Resolution; InitPropVariantFromInt64(PedometerDevice_StepCount_Resolution, &(m_pDataFieldProperties->List[SENSOR_RESOLUTION].Value)); m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Key = PKEY_SensorDataField_RangeMinimum; InitPropVariantFromUInt32(PedometerDevice_StepCount_Minimum, &(m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Value)); m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Key = PKEY_SensorDataField_RangeMaximum; InitPropVariantFromUInt32(PedometerDevice_StepCount_Maximum, &(m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Value)); // Set default threshold m_FirstSample = TRUE; Size = SENSOR_COLLECTION_LIST_SIZE(PEDOMETER_THRESHOLD_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSOR_POOL_TAG_PEDOMETER, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pThresholds)); if (!NT_SUCCESS(Status) || nullptr == m_pThresholds) { TraceError("PED %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pThresholds, Size); m_pThresholds->Count = PEDOMETER_THRESHOLD_COUNT; m_pThresholds->List[PEDOMETER_THRESHOLD_STEP_COUNT].Key = PKEY_SensorData_PedometerStepCount; InitPropVariantFromUInt32(Pedometer_Default_Threshold_StepCount, &(m_pThresholds->List[PEDOMETER_THRESHOLD_STEP_COUNT].Value)); m_CachedThreshold = Pedometer_Default_Threshold_StepCount; Exit: SENSOR_FunctionExit(Status); return Status; }
void checkPinned() { if (!Dlls::PropVariantToString) return; static const int maxFileLen = MAX_PATH * 10; HRESULT hr = CoInitialize(0); if (!SUCCEEDED(hr)) return; QString path = pinnedPath(); std::wstring p = QDir::toNativeSeparators(path).toStdWString(); WCHAR src[MAX_PATH]; GetModuleFileName(GetModuleHandle(0), src, MAX_PATH); BY_HANDLE_FILE_INFORMATION srcinfo = { 0 }; HANDLE srcfile = CreateFile(src, 0x00, 0x00, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (srcfile == INVALID_HANDLE_VALUE) return; BOOL srcres = GetFileInformationByHandle(srcfile, &srcinfo); CloseHandle(srcfile); if (!srcres) return; LOG(("Checking...")); WIN32_FIND_DATA findData; HANDLE findHandle = FindFirstFileEx((p + L"*").c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, 0, 0); if (findHandle == INVALID_HANDLE_VALUE) { LOG(("Init Error: could not find files in pinned folder")); return; } do { std::wstring fname = p + findData.cFileName; LOG(("Checking %1").arg(QString::fromStdWString(fname))); if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { continue; } else { DWORD attributes = GetFileAttributes(fname.c_str()); if (attributes >= 0xFFFFFFF) continue; // file does not exist ComPtr<IShellLink> shellLink; HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); if (!SUCCEEDED(hr)) continue; ComPtr<IPersistFile> persistFile; hr = shellLink.As(&persistFile); if (!SUCCEEDED(hr)) continue; hr = persistFile->Load(fname.c_str(), STGM_READWRITE); if (!SUCCEEDED(hr)) continue; WCHAR dst[MAX_PATH]; hr = shellLink->GetPath(dst, MAX_PATH, 0, 0); if (!SUCCEEDED(hr)) continue; BY_HANDLE_FILE_INFORMATION dstinfo = { 0 }; HANDLE dstfile = CreateFile(dst, 0x00, 0x00, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (dstfile == INVALID_HANDLE_VALUE) continue; BOOL dstres = GetFileInformationByHandle(dstfile, &dstinfo); CloseHandle(dstfile); if (!dstres) continue; if (srcinfo.dwVolumeSerialNumber == dstinfo.dwVolumeSerialNumber && srcinfo.nFileIndexLow == dstinfo.nFileIndexLow && srcinfo.nFileIndexHigh == dstinfo.nFileIndexHigh) { ComPtr<IPropertyStore> propertyStore; hr = shellLink.As(&propertyStore); if (!SUCCEEDED(hr)) return; PROPVARIANT appIdPropVar; hr = propertyStore->GetValue(getKey(), &appIdPropVar); if (!SUCCEEDED(hr)) return; LOG(("Reading...")); WCHAR already[MAX_PATH]; hr = Dlls::PropVariantToString(appIdPropVar, already, MAX_PATH); if (SUCCEEDED(hr)) { if (std::wstring(getId()) == already) { LOG(("Already!")); PropVariantClear(&appIdPropVar); return; } } if (appIdPropVar.vt != VT_EMPTY) { PropVariantClear(&appIdPropVar); return; } PropVariantClear(&appIdPropVar); hr = InitPropVariantFromString(getId(), &appIdPropVar); if (!SUCCEEDED(hr)) return; hr = propertyStore->SetValue(getKey(), appIdPropVar); PropVariantClear(&appIdPropVar); if (!SUCCEEDED(hr)) return; hr = propertyStore->Commit(); if (!SUCCEEDED(hr)) return; if (persistFile->IsDirty() == S_OK) { persistFile->Save(fname.c_str(), TRUE); } return; } } } while (FindNextFile(findHandle, &findData)); DWORD errorCode = GetLastError(); if (errorCode && errorCode != ERROR_NO_MORE_FILES) { // everything is found LOG(("Init Error: could not find some files in pinned folder")); return; } FindClose(findHandle); }
// This routine initializes the sensor to its default properties NTSTATUS CustomSensorDevice::Initialize( _In_ WDFDEVICE Device, // WDFDEVICE object _In_ SENSOROBJECT SensorInstance // SENSOROBJECT for each sensor instance ) { ULONG Size = 0; WDF_OBJECT_ATTRIBUTES MemoryAttributes; WDFMEMORY MemoryHandle = NULL; FILETIME Time = {}; WDF_OBJECT_ATTRIBUTES TimerAttributes; WDF_TIMER_CONFIG TimerConfig; NTSTATUS Status = STATUS_SUCCESS; SENSOR_FunctionEnter(); // Store device and instance m_FxDevice = Device; m_SensorInstance = SensorInstance; m_Started = FALSE; // Initialize the CO2 simulator HardwareSimulator::Initialize(Device, &m_SimulatorInstance); // Create Lock Status = WdfWaitLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &m_Lock); if (!NT_SUCCESS(Status)) { TraceError("CSTM %!FUNC! WdfWaitLockCreate failed %!STATUS!", Status); goto Exit; } // Create timer object for polling sensor samples WDF_TIMER_CONFIG_INIT(&TimerConfig, CustomSensorDevice::OnTimerExpire); WDF_OBJECT_ATTRIBUTES_INIT(&TimerAttributes); TimerAttributes.ParentObject = SensorInstance; TimerAttributes.ExecutionLevel = WdfExecutionLevelPassive; Status = WdfTimerCreate(&TimerConfig, &TimerAttributes, &m_Timer); if (!NT_SUCCESS(Status)) { TraceError("CSTM %!FUNC! WdfTimerCreate failed %!STATUS!", Status); goto Exit; } // Sensor Enumeration Properties Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_ENUMERATION_PROPERTIES_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSORV2_POOL_TAG_CUSTOM_SENSOR, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pEnumerationProperties)); if (!NT_SUCCESS(Status) || nullptr == m_pEnumerationProperties) { TraceError("CSTM %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pEnumerationProperties, Size); m_pEnumerationProperties->Count = SENSOR_ENUMERATION_PROPERTIES_COUNT; // The sensor type must be GUID_SensorType_Custom, the driver must also define and "vendor defined subtype" m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; InitPropVariantFromCLSID(GUID_SensorType_Custom, &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; InitPropVariantFromString(L"Microsoft", &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; InitPropVariantFromString(L"CO2 based sample Custom sensor V2", &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Key = DEVPKEY_Sensor_PersistentUniqueId; InitPropVariantFromCLSID(GUID_CustomSensorDevice_UniqueID, &(m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Value)); m_pEnumerationProperties->List[SENSOR_CATEGORY].Key = DEVPKEY_Sensor_Category; InitPropVariantFromCLSID(GUID_SensorCategory_Other, &(m_pEnumerationProperties->List[SENSOR_CATEGORY].Value)); m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Key = DEVPKEY_Sensor_IsPrimary; InitPropVariantFromBoolean(FALSE, &(m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Value)); // This value should be set to TRUE if multiple custom sensors // with the same vendor defined type exist on the system and // this sensor is the primary sensor m_pEnumerationProperties->List[SENSOR_VENDOR_DEFINED_TYPE].Key = DEVPKEY_Sensor_VendorDefinedSubType; InitPropVariantFromCLSID(GUID_CustomSensorDevice_VendorDefinedSubTypeID, &(m_pEnumerationProperties->List[SENSOR_VENDOR_DEFINED_TYPE].Value)); // Supported Data-Fields Size = SENSOR_PROPERTY_LIST_SIZE(CSTM_DATA_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSORV2_POOL_TAG_CUSTOM_SENSOR, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pSupportedDataFields)); if (!NT_SUCCESS(Status) || nullptr == m_pSupportedDataFields) { TraceError("CSTM %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); m_pSupportedDataFields->Count = CSTM_DATA_COUNT; m_pSupportedDataFields->List[CSTM_DATA_TIMESTAMP] = PKEY_SensorData_Timestamp; m_pSupportedDataFields->List[CSTM_DATA_CO2_LEVEL_PERCENT] = PKEY_CustomSensorSampleData_CO2Level; // Data Size = SENSOR_COLLECTION_LIST_SIZE(CSTM_DATA_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSORV2_POOL_TAG_CUSTOM_SENSOR, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pData)); if (!NT_SUCCESS(Status) || nullptr == m_pData) { TraceError("CSTM %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pData, Size); m_pData->Count = CSTM_DATA_COUNT; m_pData->List[CSTM_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; GetSystemTimePreciseAsFileTime(&Time); InitPropVariantFromFileTime(&Time, &(m_pData->List[CSTM_DATA_TIMESTAMP].Value)); // Initialize the sample, at this point of time the sensor is not started yet, // So, initialize the sample to a default value m_pData->List[CSTM_DATA_CO2_LEVEL_PERCENT].Key = PKEY_CustomSensorSampleData_CO2Level; InitPropVariantFromFloat(CustomSensorDevice_Minimum_CO2Level, &(m_pData->List[CSTM_DATA_CO2_LEVEL_PERCENT].Value)); // Sensor Properties m_Interval = Cstm_Default_MinDataInterval_Ms; Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_COMMON_PROPERTIES_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSORV2_POOL_TAG_CUSTOM_SENSOR, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pProperties)); if (!NT_SUCCESS(Status) || nullptr == m_pProperties) { TraceError("CSTM %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pProperties, Size); m_pProperties->Count = SENSOR_COMMON_PROPERTIES_COUNT; m_pProperties->List[SENSOR_PROPERTY_STATE].Key = PKEY_Sensor_State; InitPropVariantFromUInt32(SensorState_Initializing, &(m_pProperties->List[SENSOR_PROPERTY_STATE].Value)); m_pProperties->List[SENSOR_PROPERTY_MIN_INTERVAL].Key = PKEY_Sensor_MinimumDataInterval_Ms; InitPropVariantFromUInt32(Cstm_Default_MinDataInterval_Ms, &(m_pProperties->List[SENSOR_PROPERTY_MIN_INTERVAL].Value)); m_pProperties->List[SENSOR_PROPERTY_MAX_DATAFIELDSIZE].Key = PKEY_Sensor_MaximumDataFieldSize_Bytes; InitPropVariantFromUInt32(CollectionsListGetMarshalledSize(m_pData), &(m_pProperties->List[SENSOR_PROPERTY_MAX_DATAFIELDSIZE].Value)); m_pProperties->List[SENSOR_PROPERTY_SENSOR_TYPE].Key = PKEY_Sensor_Type; InitPropVariantFromCLSID(GUID_SensorType_Custom, &(m_pProperties->List[SENSOR_PROPERTY_SENSOR_TYPE].Value)); // Data filed properties Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_DATA_FIELD_PROPERTY_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, SENSORV2_POOL_TAG_CUSTOM_SENSOR, Size, &MemoryHandle, reinterpret_cast<PVOID*>(&m_pDataFieldProperties)); if (!NT_SUCCESS(Status) || nullptr == m_pDataFieldProperties) { TraceError("CSTM %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pDataFieldProperties, Size); m_pDataFieldProperties->Count = SENSOR_DATA_FIELD_PROPERTY_COUNT; m_pDataFieldProperties->List[SENSOR_RESOLUTION].Key = PKEY_SensorDataField_Resolution; InitPropVariantFromFloat((float)CustomSensorDevice_Resolution, &(m_pDataFieldProperties->List[SENSOR_RESOLUTION].Value)); m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Key = PKEY_SensorDataField_RangeMinimum; InitPropVariantFromFloat(CustomSensorDevice_Minimum_CO2Level, &(m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Value)); m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Key = PKEY_SensorDataField_RangeMaximum; InitPropVariantFromFloat(CustomSensorDevice_Maximum_CO2Level, &(m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Value)); // Reset the FirstSample flag m_FirstSample = TRUE; Exit: SENSOR_FunctionExit(Status); return Status; }
// (static) Creates a ShellLink that encapsulate a shortcut to local apps. nsresult JumpListShortcut::GetShellLink(nsCOMPtr<nsIJumpListItem>& item, nsRefPtr<IShellLinkW>& aShellLink) { HRESULT hr; IShellLinkW* psl; nsresult rv; // Shell links: // http://msdn.microsoft.com/en-us/library/bb776891(VS.85).aspx // http://msdn.microsoft.com/en-us/library/bb774950(VS.85).aspx PRInt16 type; if (NS_FAILED(item->GetType(&type))) return NS_ERROR_INVALID_ARG; if (type != nsIJumpListItem::JUMPLIST_ITEM_SHORTCUT) return NS_ERROR_INVALID_ARG; nsCOMPtr<nsIJumpListShortcut> shortcut = do_QueryInterface(item, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsILocalHandlerApp> handlerApp; rv = shortcut->GetApp(getter_AddRefs(handlerApp)); NS_ENSURE_SUCCESS(rv, rv); // Create a IShellLink hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (LPVOID*)&psl); if (FAILED(hr)) return NS_ERROR_UNEXPECTED; // Retrieve the app path, title, description and optional command line args. nsAutoString appPath, appTitle, appDescription, appArgs; PRInt32 appIconIndex = 0; // Path nsCOMPtr<nsIFile> executable; handlerApp->GetExecutable(getter_AddRefs(executable)); nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(executable, &rv); NS_ENSURE_SUCCESS(rv, rv); rv = localFile->GetPath(appPath); NS_ENSURE_SUCCESS(rv, rv); // Command line parameters PRUint32 count = 0; handlerApp->GetParameterCount(&count); for (PRUint32 idx = 0; idx < count; idx++) { if (idx > 0) appArgs.Append(NS_LITERAL_STRING(" ")); nsAutoString param; rv = handlerApp->GetParameter(idx, param); if (NS_FAILED(rv)) return rv; appArgs.Append(param); } handlerApp->GetName(appTitle); handlerApp->GetDetailedDescription(appDescription); shortcut->GetIconIndex(&appIconIndex); // Store the title of the app if (appTitle.Length() > 0) { IPropertyStore* pPropStore = nsnull; hr = psl->QueryInterface(IID_IPropertyStore, (LPVOID*)&pPropStore); if (FAILED(hr)) return NS_ERROR_UNEXPECTED; PROPVARIANT pv; InitPropVariantFromString(appTitle.get(), &pv); pPropStore->SetValue(PKEY_Title, pv); pPropStore->Commit(); pPropStore->Release(); PropVariantClear(&pv); } // Store the rest of the params psl->SetPath(appPath.get()); psl->SetDescription(appDescription.get()); psl->SetArguments(appArgs.get()); psl->SetIconLocation(appPath.get(), appIconIndex); aShellLink = dont_AddRef(psl); return NS_OK; }