BOOL HCR_GetDefaultVerbW( HKEY hkeyClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len ) { WCHAR sTemp[MAX_PATH]; LONG size; HKEY hkey; TRACE("%p %s %p\n", hkeyClass, debugstr_w(szVerb), szDest); if (szVerb) { lstrcpynW(szDest, szVerb, len); return TRUE; } size=len; *szDest='\0'; if (!RegQueryValueW(hkeyClass, swShell, szDest, &size) && *szDest) { /* The MSDN says to first try the default verb */ lstrcpyW(sTemp, swShell); lstrcatW(sTemp, szDest); lstrcatW(sTemp, swCommand); if (!RegOpenKeyExW(hkeyClass, sTemp, 0, 0, &hkey)) { RegCloseKey(hkey); TRACE("default verb=%s\n", debugstr_w(szDest)); return TRUE; } } /* then fallback to 'open' */ lstrcpyW(sTemp, swShell); lstrcatW(sTemp, swOpen); lstrcatW(sTemp, swCommand); if (!RegOpenKeyExW(hkeyClass, sTemp, 0, 0, &hkey)) { RegCloseKey(hkey); lstrcpynW(szDest, swOpen, len); TRACE("default verb=open\n"); return TRUE; } /* and then just use the first verb on Windows >= 2000 */ if (!RegEnumKeyW(hkeyClass, 0, szDest, len) && *szDest) { TRACE("default verb=first verb=%s\n", debugstr_w(szDest)); return TRUE; } TRACE("no default verb!\n"); return FALSE; }
/*********************************************************************** * WINTRUST_RemoveProviderFromReg * * Helper function for WintrustRemoveActionID * */ static void WINTRUST_RemoveProviderFromReg(WCHAR* GuidString, const WCHAR* FunctionType) { WCHAR ProvKey[MAX_PATH]; /* Create the needed key string */ ProvKey[0]='\0'; lstrcatW(ProvKey, Trust); lstrcatW(ProvKey, FunctionType); lstrcatW(ProvKey, GuidString); /* We don't care about success or failure */ RegDeleteKeyW(HKEY_LOCAL_MACHINE, ProvKey); }
static BOOL msidbImportStorages(LPCWSTR dbfile, LPCWSTR wdir, LPWSTR storageNames[]) { static const WCHAR delim[] = {'/', 0}; UINT r, len, i; MSIHANDLE dbhandle, view, rec; WCHAR *storagePath = 0; char *query = "INSERT INTO _Storages (Name, Data) VALUES(?, ?)"; r = MsiOpenDatabaseW(dbfile, (LPWSTR) MSIDBOPEN_TRANSACT, &dbhandle); if (r != ERROR_SUCCESS) return FALSE; r = MsiDatabaseOpenView(dbhandle, query, &view); if (r != ERROR_SUCCESS) return FALSE; MsiViewExecute(view, 0); r = MsiViewFetch(view, &rec); if (r != ERROR_SUCCESS) return FALSE; for (i = 0; i < MAX_STORAGES && storageNames[i] != 0; ++i) { len = lstrlenW(wdir) + lstrlenW(storageNames[i]) + 2; storagePath = malloc(len * sizeof(WCHAR)); if (storagePath == NULL) return FALSE; lstrcpyW(storagePath, wdir); lstrcatW(storagePath, delim); lstrcatW(storagePath, storageNames[i]); rec = MsiCreateRecord(2); MsiRecordSetStringW(rec, 1, storageNames[i]); r = MsiRecordSetStreamW(rec, 2, storagePath); if (r != ERROR_SUCCESS) { return FALSE; } r = MsiViewExecute(view, rec); if (r != ERROR_SUCCESS) { return FALSE; } MsiCloseHandle(rec); } MsiViewClose(view); MsiCloseHandle(view); MsiDatabaseCommit(dbhandle); MsiCloseHandle(dbhandle); return TRUE; }
/* determines the proper working directory for the INF file */ static HRESULT get_working_dir(ADVInfo *info, LPCWSTR inf_filename, LPCWSTR working_dir) { WCHAR path[MAX_PATH]; LPCWSTR ptr; DWORD len; static const WCHAR backslash[] = {'\\',0}; static const WCHAR inf_dir[] = {'\\','I','N','F',0}; if ((ptr = strrchrW(inf_filename, '\\'))) { len = ptr - inf_filename + 1; ptr = inf_filename; } else if (working_dir && *working_dir) { len = lstrlenW(working_dir) + 1; ptr = working_dir; } else { GetCurrentDirectoryW(MAX_PATH, path); lstrcatW(path, backslash); lstrcatW(path, inf_filename); /* check if the INF file is in the current directory */ if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES) { GetCurrentDirectoryW(MAX_PATH, path); } else { /* default to the windows\inf directory if all else fails */ GetWindowsDirectoryW(path, MAX_PATH); lstrcatW(path, inf_dir); } len = lstrlenW(path) + 1; ptr = path; } info->working_dir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); if (!info->working_dir) return E_OUTOFMEMORY; lstrcpynW(info->working_dir, ptr, len); return S_OK; }
/*********************************************************************** * AddDelBackupEntryW (ADVPACK.@) * * Either appends the files in the file list to the backup section of * the specified INI, or deletes the entries from the INI file. * * PARAMS * lpcszFileList [I] NULL-separated list of filenames. * lpcszBackupDir [I] Path of the backup directory. * lpcszBaseName [I] Basename of the INI file. * dwFlags [I] AADBE_ADD_ENTRY adds the entries in the file list * to the INI file, while AADBE_DEL_ENTRY removes * the entries from the INI file. * * RETURNS * S_OK in all cases. * * NOTES * If the INI file does not exist before adding entries to it, the file * will be created. * * If lpcszBackupDir is NULL, the INI file is assumed to exist in * c:\windows or created there if it does not exist. */ HRESULT WINAPI AddDelBackupEntryW(LPCWSTR lpcszFileList, LPCWSTR lpcszBackupDir, LPCWSTR lpcszBaseName, DWORD dwFlags) { WCHAR szIniPath[MAX_PATH]; LPCWSTR szString = NULL; static const WCHAR szBackupEntry[] = { '-','1',',','0',',','0',',','0',',','0',',','0',',','-','1',0 }; static const WCHAR backslash[] = {'\\',0}; static const WCHAR ini[] = {'.','i','n','i',0}; static const WCHAR backup[] = {'b','a','c','k','u','p',0}; TRACE("(%s, %s, %s, %d)\n", debugstr_w(lpcszFileList), debugstr_w(lpcszBackupDir), debugstr_w(lpcszBaseName), dwFlags); if (!lpcszFileList || !*lpcszFileList) return S_OK; if (lpcszBackupDir) lstrcpyW(szIniPath, lpcszBackupDir); else GetWindowsDirectoryW(szIniPath, MAX_PATH); lstrcatW(szIniPath, backslash); lstrcatW(szIniPath, lpcszBaseName); lstrcatW(szIniPath, ini); SetFileAttributesW(szIniPath, FILE_ATTRIBUTE_NORMAL); if (dwFlags & AADBE_ADD_ENTRY) szString = szBackupEntry; else if (dwFlags & AADBE_DEL_ENTRY) szString = NULL; /* add or delete the INI entries */ while (*lpcszFileList) { WritePrivateProfileStringW(backup, lpcszFileList, szString, szIniPath); lpcszFileList += lstrlenW(lpcszFileList) + 1; } /* hide the INI file */ SetFileAttributesW(szIniPath, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN); return S_OK; }
__declspec(dllexport) ULONG_PTR TITCALL HandlerGetOpenMutexHandleW(HANDLE hProcess, DWORD ProcessId, wchar_t* szMutexString) { if(!szMutexString || lstrlenW(szMutexString) >= 512) return 0; int i; HANDLE myHandle; char HandleBuffer[0x1000] = {0}; LPVOID cHandleBuffer = HandleBuffer; int OpenHandleCount = HandlerEnumerateOpenMutexes(hProcess, ProcessId, HandleBuffer, 0x1000 / sizeof HANDLE); wchar_t RealMutexName[512] = L"\\BaseNamedObjects\\"; wchar_t* HandleName; if(OpenHandleCount > NULL) { lstrcatW(RealMutexName, szMutexString); for(i = 0; i < OpenHandleCount; i++) { RtlMoveMemory(&myHandle, cHandleBuffer, sizeof HANDLE); HandleName = (wchar_t*)HandlerGetHandleNameW(hProcess, ProcessId, myHandle, true); if(HandleName != NULL) { if(lstrcmpiW(HandleName, RealMutexName) == NULL) { return((ULONG_PTR)myHandle); } } cHandleBuffer = (LPVOID)((ULONG_PTR)cHandleBuffer + sizeof HANDLE); } } return(NULL); }
static HRESULT register_clsid(LPCGUID guid) { static const WCHAR clsid[] = {'C','L','S','I','D','\\',0}; static const WCHAR ips[] = {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0}; static const WCHAR hlink[] = {'h','l','i','n','k','.','d','l','l',0}; static const WCHAR threading_model[] = {'T','h','r','e','a','d','i','n','g','M','o','d','e','l',0}; static const WCHAR apartment[] = {'A','p','a','r','t','m','e','n','t',0}; WCHAR path[80]; HKEY key = NULL; LONG r; lstrcpyW(path, clsid); StringFromGUID2(guid, &path[6], 80); lstrcatW(path, ips); r = RegCreateKeyW(HKEY_CLASSES_ROOT, path, &key); if (r != ERROR_SUCCESS) return E_FAIL; RegSetValueExW(key, NULL, 0, REG_SZ, (const BYTE *)hlink, sizeof hlink); RegSetValueExW(key, threading_model, 0, REG_SZ, (const BYTE *)apartment, sizeof apartment); RegCloseKey(key); return S_OK; }
DWORD MakeComputerNameW( LPCWSTR lpwComputer, LPWSTR lpwComputerName, LPDWORD lpcbwComputerName ) { DWORD cchComputer; if( lpwComputer == NULL || lpwComputerName == NULL || lpcbwComputerName == NULL ) return ERROR_INVALID_PARAMETER; if( *lpwComputer == L'\0' ) return ERROR_INVALID_COMPUTERNAME; cchComputer = lstrlenW( lpwComputer ); if( lpwComputer[0] != L'\\' && lpwComputer[1] != L'\\' ) { lpwComputerName[0] = L'\\'; lpwComputerName[1] = L'\\'; lpwComputerName[2] = L'\x0'; } else { cchComputer -= 2; lpwComputerName[0] = L'\0'; } if( cchComputer > CNLEN ) return ERROR_INVALID_COMPUTERNAME; if( lstrcatW( lpwComputerName, lpwComputer ) == NULL ) return GetLastError(); cchComputer = lstrlenW( lpwComputerName ) + 1; if( cchComputer > *lpcbwComputerName ) return ERROR_MORE_DATA; *lpcbwComputerName = cchComputer; return ERROR_SUCCESS; }
void RegConfig::BookmarkInsertInt(int nPos, RegPath* pKey, BOOL abSaveImmediate /*= TRUE*/) { if (szBookmarksValueName[0] == 0 || !pszBookmarks) { _ASSERTE(szBookmarksValueName[0] && pszBookmarks); return; } // Сформировать полный путь с "HKEY_xxx" wchar_t* pszNewKey = NULL; int nKeyLen = pKey->mpsz_Key ? lstrlenW(pKey->mpsz_Key) : 0; pszNewKey = (wchar_t*)calloc(nKeyLen+40,2); if (pKey->mh_Root) { if (!pKey->IsKeyPredefined(pKey->mh_Root)) { pszNewKey[0] = 0; } else if (!HKeyToStringKey(pKey->mh_Root, pszNewKey , 40)) { // Неизвестный ключ! InvalidOp(); SafeFree(pszNewKey); return; } MCHKHEAP; } if (*pKey->mpsz_Key) { lstrcatW(pszNewKey, L"\\"); lstrcpynW(pszNewKey+lstrlenW(pszNewKey), pKey->mpsz_Key, nKeyLen+1); } BookmarkInsertInt(nPos, pszNewKey, abSaveImmediate); SafeFree(pszNewKey); }
/****************************************************************************** * ItemMoniker_GetDisplayName ******************************************************************************/ static HRESULT WINAPI ItemMonikerImpl_GetDisplayName(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName) { ItemMonikerImpl *This = impl_from_IMoniker(iface); TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName); if (ppszDisplayName==NULL) return E_POINTER; if (pmkToLeft!=NULL){ return E_INVALIDARG; } *ppszDisplayName=CoTaskMemAlloc(sizeof(WCHAR)*(lstrlenW(This->itemDelimiter)+lstrlenW(This->itemName)+1)); if (*ppszDisplayName==NULL) return E_OUTOFMEMORY; lstrcpyW(*ppszDisplayName,This->itemDelimiter); lstrcatW(*ppszDisplayName,This->itemName); TRACE("-- %s\n", debugstr_w(*ppszDisplayName)); return S_OK; }
/**************************************************************************** * SHGetStockIconInfo [SHELL32.@] * * Receive information for builtin icons * * PARAMS * id [I] selected icon-id to get information for * flags [I] selects the information to receive * sii [IO] SHSTOCKICONINFO structure to fill * * RETURNS * Success: S_OK * Failure: A HRESULT failure code * */ HRESULT WINAPI SHGetStockIconInfo(SHSTOCKICONID id, UINT flags, SHSTOCKICONINFO *sii) { static const WCHAR shell32dll[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0}; FIXME("(%d, 0x%x, %p) semi-stub\n", id, flags, sii); if ((id < 0) || (id >= SIID_MAX_ICONS) || !sii || (sii->cbSize != sizeof(SHSTOCKICONINFO))) { return E_INVALIDARG; } GetSystemDirectoryW(sii->szPath, MAX_PATH); /* no icons defined: use default */ sii->iIcon = -IDI_SHELL_DOCUMENT; lstrcatW(sii->szPath, shell32dll); if (flags) FIXME("flags 0x%x not implemented\n", flags); sii->hIcon = NULL; sii->iSysImageIndex = -1; TRACE("%3d: returning %s (%d)\n", id, debugstr_w(sii->szPath), sii->iIcon); return S_OK; }
/*********************************************************************** * SetupQuerySpaceRequiredOnDriveA (SETUPAPI.@) */ BOOL WINAPI SetupQuerySpaceRequiredOnDriveA(HDSKSPC DiskSpace, LPCSTR DriveSpec, LONGLONG* SpaceRequired, PVOID Reserved1, UINT Reserved2) { WCHAR driveW[20]; unsigned int i; LPDISKSPACELIST list = (LPDISKSPACELIST)DiskSpace; BOOL rc = FALSE; static const WCHAR bkslsh[]= {'\\',0}; MultiByteToWideChar(CP_ACP,0,DriveSpec,-1,driveW,20); lstrcatW(driveW,bkslsh); TRACE("Looking for drive %s\n",debugstr_w(driveW)); for (i = 0; i < list->dwDriveCount; i++) { TRACE("checking drive %s\n",debugstr_w(list->Drives[i].lpzName)); if (lstrcmpW(driveW,list->Drives[i].lpzName)==0) { rc = TRUE; *SpaceRequired = list->Drives[i].dwWantedSpace; break; } } return rc; }
static HRESULT write_predefined_strings(HMODULE hm, LPCWSTR ini_path) { WCHAR mod_path[MAX_PATH + 2]; WCHAR sys_mod_path[MAX_PATH + 2]; WCHAR sys_root[MAX_PATH]; *mod_path = '\"'; if (!GetModuleFileNameW(hm, mod_path + 1, sizeof(mod_path) / sizeof(WCHAR) - 2)) return E_FAIL; lstrcatW(mod_path, quote); WritePrivateProfileStringW(Strings, MOD_PATH, mod_path, ini_path); *sys_root = '\0'; GetEnvironmentVariableW(SystemRoot, sys_root, sizeof(sys_root) / sizeof(WCHAR)); if(!strncmpiW(sys_root, mod_path + 1, strlenW(sys_root))) { *sys_mod_path = '\"'; strcpyW(sys_mod_path + 1, escaped_SystemRoot); strcatW(sys_mod_path, mod_path + 1 + strlenW(sys_root)); } else { FIXME("SYS_MOD_PATH needs more work\n"); strcpyW(sys_mod_path, mod_path); } WritePrivateProfileStringW(Strings, SYS_MOD_PATH, sys_mod_path, ini_path); return S_OK; }
BOOL HCR_GetIconW(LPCWSTR szClass, LPWSTR szDest, LPCWSTR szName, DWORD len, int* picon_idx) { static const WCHAR swDefaultIcon[] = {'\\','D','e','f','a','u','l','t','I','c','o','n',0}; HKEY hkey; WCHAR sTemp[MAX_PATH]; BOOL ret = FALSE; TRACE("%s\n",debugstr_w(szClass) ); lstrcpynW(sTemp, szClass, MAX_PATH); lstrcatW(sTemp, swDefaultIcon); if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, sTemp, 0, KEY_READ, &hkey)) { ret = HCR_RegGetIconW(hkey, szDest, szName, len, picon_idx); RegCloseKey(hkey); } if(ret) TRACE("-- %s %i\n", debugstr_w(szDest), *picon_idx); else TRACE("-- not found\n"); return ret; }
static BOOL start_rpcss(void) { PROCESS_INFORMATION pi; STARTUPINFOW si; WCHAR cmd[MAX_PATH]; static const WCHAR rpcss[] = {'\\','r','p','c','s','s','.','e','x','e',0}; BOOL rslt; void *redir; TRACE("\n"); ZeroMemory(&si, sizeof(STARTUPINFOA)); si.cb = sizeof(STARTUPINFOA); GetSystemDirectoryW( cmd, MAX_PATH - sizeof(rpcss)/sizeof(WCHAR) ); lstrcatW( cmd, rpcss ); Wow64DisableWow64FsRedirection( &redir ); rslt = CreateProcessW( cmd, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ); Wow64RevertWow64FsRedirection( redir ); if (rslt) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); Sleep(100); } return rslt; }
static BOOL msidbImportStreams(LPCWSTR dbfile, LPCWSTR wdir, LPWSTR streamNames[]) { UINT r, len; MSIHANDLE dbhandle, view, rec; int i = 0; WCHAR *streamPath = 0; char *query = "INSERT INTO _Streams (Name, Data) VALUES(?, ?)"; r = MsiOpenDatabaseW(dbfile, (LPWSTR) MSIDBOPEN_TRANSACT, &dbhandle); if (r != ERROR_SUCCESS) return FALSE; r = MsiDatabaseOpenView(dbhandle, query, &view); if (r != ERROR_SUCCESS) return FALSE; for (i = 0; i < MAX_STREAMS && streamNames[i] != NULL; i++) { len = lstrlenW(wdir) + lstrlenW(streamNames[i]) + 2; streamPath = malloc(len * sizeof(WCHAR)); if (streamPath == NULL) return FALSE; lstrcpyW(streamPath, wdir); lstrcatW(streamPath, PATH_DELIMITERW); lstrcatW(streamPath, streamNames[i]); rec = MsiCreateRecord(2); MsiRecordSetStringW(rec, 1, streamNames[i]); r = MsiRecordSetStreamW(rec, 2, streamPath); if (r != ERROR_SUCCESS) { return FALSE; } r = MsiViewExecute(view, rec); if (r != ERROR_SUCCESS) { return FALSE; } MsiCloseHandle(rec); } MsiViewClose(view); MsiCloseHandle(view); MsiDatabaseCommit(dbhandle); MsiCloseHandle(dbhandle); return TRUE; }
// рекурсивная ф-я void EnumRegistry(PWCHAR RootKey/* должно быть выделено MAX_REGPATH_LEN WCHARов*/, ULONG Depth) { // не будем перегружать стек PWCHAR KeyName = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*MAX_KEYVALUENAME_LEN); if (!KeyName) return; PWCHAR ValueName = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*MAX_KEYVALUENAME_LEN); if (!ValueName) { HeapFree(GetProcessHeap(), 0, KeyName); return; } // енумерим валушки, начиная с дефолтовой PrintTabs(Depth); printf("Values:\n"); // дефолтовая не установлена if (!PrintValue(RootKey, L"", Depth)) { PrintTabs(Depth); printf("(Default):\tvalue not set\n"); } for (ULONG ValueIndex = 0; EnumValues(RootKey, ValueIndex, ValueName); ValueIndex++) { // пропускаем установленное дефолтовое значение if (ValueName[0]) PrintValue(RootKey, ValueName, Depth); } ULONG OldLen = lstrlenW(RootKey); for (ULONG KeyIndex = 0; EnumKeys(RootKey, KeyIndex, KeyName); KeyIndex++) { lstrcatW(RootKey, L"\\"); lstrcatW(RootKey, KeyName); PrintTabs(Depth); printf("%S\n", KeyName); EnumRegistry(RootKey, Depth+1); RootKey[OldLen] = 0; } HeapFree(GetProcessHeap(), 0 ,ValueName); HeapFree(GetProcessHeap(), 0, KeyName); }
LPWSTR apxLogFile( APXHANDLE hPool, LPCWSTR szPath, LPCWSTR szPrefix, LPCWSTR szName) { LPWSTR sRet; WCHAR sPath[MAX_PATH+1]; WCHAR sName[MAX_PATH+1]; SYSTEMTIME sysTime; GetLocalTime(&sysTime); if (!szPath) { if (GetSystemDirectoryW(sPath, MAX_PATH) == 0) return INVALID_HANDLE_VALUE; lstrcatW(sPath, L"\\LogFiles\\"); if (!szPrefix) lstrcatW(sPath, L"Apache"); else lstrcatW(sPath, szPrefix); wsprintfW(sName, L"\\%s%04d%02d%02d.log", szName, sysTime.wYear, sysTime.wMonth, sysTime.wDay); } else { lstrcpyW(sPath, szPath); if (szPrefix) wsprintfW(sName, L"\\%s", szPrefix); else wsprintfW(sName, L"\\%s%04d%02d%02d.log", szName, sysTime.wYear, sysTime.wMonth, sysTime.wDay); } sRet = apxPoolAlloc(hPool, (MAX_PATH + 1) * sizeof(WCHAR)); /* Set default level to info */ CreateDirectoryW(sPath, NULL); lstrcpyW(sRet, sPath); lstrcatW(sRet, sName); return sRet; }
void __DEBUG_MSG__(const WCHAR* szFormat, va_list args) { const size_t SIZE = 4096; WCHAR szBuf[SIZE] = {0}; _vsnwprintf_s(szBuf, SIZE, SIZE, szFormat, args); lstrcatW(szBuf, L"\n"); DebugConsole::Printf(GetStdString(szBuf).c_str()); }
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdLine, int nCmdShow) { int res = 0; srand(time(NULL)); wchar_t a[100] = L"Your Number Is "; wchar_t b[4]; wchar_t buf[30]; int rand_num = 300; wsprintf(b, TEXT("%d"), rand_num); lstrcpyW(buf, a); lstrcatW(buf, b); int min = 0; int max = 1000; int count = 0; while (res != IDYES) { res = MessageBox(0, buf, L"gurss number", MB_YESNOCANCEL | MB_ICONEXCLAMATION); if (res == IDYES) { wsprintf(b, TEXT("%d"), count); lstrcpyW(buf, L"I Win in "); lstrcatW(buf, b); lstrcatW(buf, L" steps"); MessageBox(0, buf, L"поздравляем!", MB_OK | MB_ICONINFORMATION); } if (res == IDNO) { min = rand_num + 1; } if (res == IDCANCEL) { max = rand_num - 1; } rand_num = min + rand() % (min - max); wsprintf(b, TEXT("%d"), rand_num); lstrcpyW(buf, a); lstrcatW(buf, b); count++; } }
/** * Sets the caption of the main window according to Globals.szFileTitle: * Untitled - Notepad if no file is open * filename - Notepad if a file is given */ void UpdateWindowCaption(void) { WCHAR szCaption[MAX_STRING_LEN]; WCHAR szNotepad[MAX_STRING_LEN]; static const WCHAR hyphenW[] = { ' ','-',' ',0 }; if (Globals.szFileTitle[0] != '\0') lstrcpyW(szCaption, Globals.szFileTitle); else LoadStringW(Globals.hInstance, STRING_UNTITLED, szCaption, ARRAY_SIZE(szCaption)); LoadStringW(Globals.hInstance, STRING_NOTEPAD, szNotepad, ARRAY_SIZE(szNotepad)); lstrcatW(szCaption, hyphenW); lstrcatW(szCaption, szNotepad); SetWindowTextW(Globals.hMainWnd, szCaption); }
/* * Helper for CryptSIPAddProvider * * Add a registry key containing a dll name and function under * "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\<func>\\<guid>" */ static LONG CRYPT_SIPWriteFunction( LPGUID guid, LPCWSTR szKey, LPCWSTR szDll, LPCWSTR szFunction ) { static const WCHAR szOID[] = { 'S','o','f','t','w','a','r','e','\\', 'M','i','c','r','o','s','o','f','t','\\', 'C','r','y','p','t','o','g','r','a','p','h','y','\\', 'O','I','D','\\', 'E','n','c','o','d','i','n','g','T','y','p','e',' ','0','\\', 'C','r','y','p','t','S','I','P','D','l','l', 0 }; static const WCHAR szBackSlash[] = { '\\', 0 }; static const WCHAR szDllName[] = { 'D','l','l',0 }; static const WCHAR szFuncName[] = { 'F','u','n','c','N','a','m','e',0 }; WCHAR szFullKey[ 0x100 ]; LONG r; HKEY hKey; if( !szFunction ) return ERROR_SUCCESS; /* max length of szFullKey depends on our code only, so we won't overrun */ lstrcpyW( szFullKey, szOID ); lstrcatW( szFullKey, szKey ); lstrcatW( szFullKey, szBackSlash ); CRYPT_guid2wstr( guid, &szFullKey[ lstrlenW( szFullKey ) ] ); lstrcatW( szFullKey, szBackSlash ); TRACE("key is %s\n", debugstr_w( szFullKey ) ); r = RegCreateKeyW( HKEY_LOCAL_MACHINE, szFullKey, &hKey ); if( r != ERROR_SUCCESS ) return r; /* write the values */ RegSetValueExW( hKey, szFuncName, 0, REG_SZ, (const BYTE*) szFunction, ( lstrlenW( szFunction ) + 1 ) * sizeof (WCHAR) ); RegSetValueExW( hKey, szDllName, 0, REG_SZ, (const BYTE*) szDll, ( lstrlenW( szDll ) + 1) * sizeof (WCHAR) ); RegCloseKey( hKey ); return ERROR_SUCCESS; }
/********************************************************************** * EnumThemes (UXTHEME.8) * * Enumerate available themes, calls specified EnumThemeProc for each * theme found. Passes lpData through to callback function. * * PARAMS * pszThemePath Path containing themes * callback Called for each theme found in path * lpData Passed through to callback * * RETURNS * Success: S_OK * Failure: HRESULT error-code */ HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, ENUMTHEMEPROC callback, LPVOID lpData) { WCHAR szDir[MAX_PATH]; WCHAR szPath[MAX_PATH]; static const WCHAR szStar[] = {'*','.','*','\0'}; static const WCHAR szFormat[] = {'%','s','%','s','\\','%','s','.','m','s','s','t','y','l','e','s','\0'}; static const WCHAR szDisplayName[] = {'d','i','s','p','l','a','y','n','a','m','e','\0'}; static const WCHAR szTooltip[] = {'t','o','o','l','t','i','p','\0'}; WCHAR szName[60]; WCHAR szTip[60]; HANDLE hFind; WIN32_FIND_DATAW wfd; HRESULT hr; size_t pathLen; TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath), callback, lpData); if(!pszThemePath || !callback) return E_POINTER; lstrcpyW(szDir, pszThemePath); pathLen = lstrlenW (szDir); if ((pathLen > 0) && (pathLen < MAX_PATH-1) && (szDir[pathLen - 1] != '\\')) { szDir[pathLen] = '\\'; szDir[pathLen+1] = 0; } lstrcpyW(szPath, szDir); lstrcatW(szPath, szStar); TRACE("searching %s\n", debugstr_w(szPath)); hFind = FindFirstFileW(szPath, &wfd); if(hFind != INVALID_HANDLE_VALUE) { do { if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) { wsprintfW(szPath, szFormat, szDir, wfd.cFileName, wfd.cFileName); hr = GetThemeDocumentationProperty(szPath, szDisplayName, szName, sizeof(szName)/sizeof(szName[0])); if(SUCCEEDED(hr)) hr = GetThemeDocumentationProperty(szPath, szTooltip, szTip, sizeof(szTip)/sizeof(szTip[0])); if(SUCCEEDED(hr)) { TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData); if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) { TRACE("callback ended enum\n"); break; } } } } while(FindNextFileW(hFind, &wfd)); FindClose(hFind); } return S_OK; }
__declspec(dllexport) bool TITCALL DumpRegionsW(HANDLE hProcess, wchar_t* szDumpFolder, bool DumpAboveImageBaseOnly) { int i; DWORD cbNeeded = NULL; wchar_t szDumpName[MAX_PATH]; wchar_t szDumpFileName[MAX_PATH]; MEMORY_BASIC_INFORMATION MemInfo; ULONG_PTR DumpAddress = NULL; HMODULE EnumeratedModules[1024] = {0}; bool AddressIsModuleBase = false; if(hProcess != NULL) { if (!EnumProcessModules(hProcess, EnumeratedModules, sizeof(EnumeratedModules), &cbNeeded)) { return false; } while(VirtualQueryEx(hProcess, (LPVOID)DumpAddress, &MemInfo, sizeof MEMORY_BASIC_INFORMATION) != NULL) { AddressIsModuleBase = false; for(i = 0; i < (int)(cbNeeded / sizeof(HMODULE)); i++) { if(EnumeratedModules[i] == (HMODULE)MemInfo.AllocationBase) { AddressIsModuleBase = true; i = 1024; } else if(EnumeratedModules[i] == 0) { i = 1024; } } if(!(MemInfo.Protect & PAGE_NOACCESS) && AddressIsModuleBase == false) { if(DumpAboveImageBaseOnly == false || (DumpAboveImageBaseOnly == true && EnumeratedModules[0] < (HMODULE)MemInfo.BaseAddress)) { RtlZeroMemory(&szDumpName, MAX_PATH); RtlZeroMemory(&szDumpFileName, MAX_PATH); lstrcpyW(szDumpFileName, szDumpFolder); if(szDumpFileName[lstrlenW(szDumpFileName)-1] != L'\\') { szDumpFileName[lstrlenW(szDumpFileName)] = L'\\'; } wsprintfW(szDumpName, L"Dump-%x_%x.dmp", (ULONG_PTR)MemInfo.BaseAddress, (ULONG_PTR)MemInfo.RegionSize); lstrcatW(szDumpFileName, szDumpName); DumpMemoryW(hProcess, (LPVOID)MemInfo.BaseAddress, (ULONG_PTR)MemInfo.RegionSize, szDumpFileName); } } DumpAddress = DumpAddress + (ULONG_PTR)MemInfo.RegionSize; } return true; } return false; }
static void UpdateWindowCaption(void) { WCHAR szCaption[MAX_PATH]; WCHAR szView[MAX_PATH]; static const WCHAR hyphenW[] = { ' ','-',' ',0 }; LoadStringW(hInst, IDS_DESCRIPTION, szView, sizeof(szView)/sizeof(WCHAR)); if (szFileTitle[0] != '\0') { lstrcpyW(szCaption, szFileTitle); LoadStringW(hInst, IDS_DESCRIPTION, szView, sizeof(szView)/sizeof(WCHAR)); lstrcatW(szCaption, hyphenW); lstrcatW(szCaption, szView); } else lstrcpyW(szCaption, szView); SetWindowTextW(hMainWnd, szCaption); }
void initExceptionHandler() { memset(fileName, 0, sizeof(fileName)); GetModuleFileNameW(NULL, fileName, sizeof(fileName) - 1); for (int i = lstrlenW(fileName) - 1; i >= 0; i--) { if ('.' == fileName[i]) { fileName[i] = 0; break; } } lstrcatW(fileName, L"-"); lstrcpyW(fileName + lstrlenW(fileName), TEXT(SCHAT_VERSION)); lstrcatW(fileName, L"-"); lstrcpynW(fileName + lstrlenW(fileName), TEXT(GIT_REVISION), 8); lstrcatW(fileName, L"-"); SetUnhandledExceptionFilter(exceptionFilter); }
static HANDLE unixem__dirent__wfindfile_directory(wchar_t const *name, LPWIN32_FIND_DATAW data) { wchar_t search_spec[_MAX_PATH +1]; /* Simply add the *.*, ensuring the path separator is * included. */ lstrcpyW(search_spec, name); if( L'\\' != search_spec[lstrlenW(search_spec) - 1] && L'/' != search_spec[lstrlenW(search_spec) - 1]) { lstrcatW(search_spec, L"\\*.*"); } else { lstrcatW(search_spec, L"*.*"); } return FindFirstFileW(search_spec, data); }
static HRESULT WINAPI MSTASK_ITaskScheduler_Delete(ITaskScheduler *iface, LPCWSTR name) { static const WCHAR tasksW[] = { '\\','T','a','s','k','s','\\',0 }; static const WCHAR jobW[] = { '.','j','o','b',0 }; WCHAR task_name[MAX_PATH]; TRACE("%p, %s\n", iface, debugstr_w(name)); if (strchrW(name, '.')) return E_INVALIDARG; GetWindowsDirectoryW(task_name, MAX_PATH); lstrcatW(task_name, tasksW); lstrcatW(task_name, name); lstrcatW(task_name, jobW); if (!DeleteFileW(task_name)) return HRESULT_FROM_WIN32(GetLastError()); return S_OK; }
HRESULT UpdatePublisherPolicyTimeStampFile(IAssemblyName *pName) { HRESULT hr = S_OK; DWORD dwSize; HANDLE hFile = INVALID_HANDLE_VALUE; WCHAR wzTimeStampFile[MAX_PATH + 1]; WCHAR wzAsmName[MAX_PATH]; ASSERT(pName); // If the name of the assembly begins with "policy." then update // the publisher policy timestamp file. wzAsmName[0] = L'\0'; dwSize = MAX_PATH; hr = pName->GetProperty(ASM_NAME_NAME, wzAsmName, &dwSize); if (FAILED(hr)) { goto Exit; } if (StrCmpNI(wzAsmName, POLICY_ASSEMBLY_PREFIX, lstrlenW(POLICY_ASSEMBLY_PREFIX))) { // No work needs to be done goto Exit; } // Touch the file dwSize = MAX_PATH; hr = GetCachePath(ASM_CACHE_GAC, wzTimeStampFile, &dwSize); if (lstrlenW(wzTimeStampFile) + lstrlenW(FILENAME_PUBLISHER_PCY_TIMESTAMP) + 1 >= MAX_PATH) { hr = HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW); goto Exit; } PathRemoveBackslash(wzTimeStampFile); lstrcatW(wzTimeStampFile, FILENAME_PUBLISHER_PCY_TIMESTAMP); hFile = CreateFileW(wzTimeStampFile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit; } Exit: if (hFile != INVALID_HANDLE_VALUE) { CloseHandle(hFile); } return hr; }
static LRESULT registry_get_handle(HKEY *hKey, LPDWORD action, LPCWSTR subKey) { LONG ret; static const WCHAR wszProgramKey[] = {'S','o','f','t','w','a','r','e','\\', 'M','i','c','r','o','s','o','f','t','\\', 'W','i','n','d','o','w','s','\\', 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', 'A','p','p','l','e','t','s','\\', 'W','o','r','d','p','a','d',0 }; LPWSTR key = (LPWSTR)wszProgramKey; if(subKey) { WCHAR backslash[] = {'\\',0}; key = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(wszProgramKey)+lstrlenW(subKey)+lstrlenW(backslash)+1) *sizeof(WCHAR)); if(!key) return 1; lstrcpyW(key, wszProgramKey); lstrcatW(key, backslash); lstrcatW(key, subKey); } if(action) { ret = RegCreateKeyExW(HKEY_CURRENT_USER, key, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, hKey, action); } else { ret = RegOpenKeyExW(HKEY_CURRENT_USER, key, 0, KEY_READ | KEY_WRITE, hKey); } if(subKey) HeapFree(GetProcessHeap(), 0, key); return ret; }