static void set_desktop_window_title( HWND hwnd, const WCHAR *name ) { static const WCHAR desktop_nameW[] = {'W','i','n','e',' ','d','e','s','k','t','o','p',0}; static const WCHAR desktop_name_separatorW[] = {' ', '-', ' ', 0}; WCHAR *window_titleW = NULL; int window_title_len; if (!name[0]) { SetWindowTextW( hwnd, desktop_nameW ); return; } window_title_len = strlenW(name) * sizeof(WCHAR) + sizeof(desktop_name_separatorW) + sizeof(desktop_nameW); window_titleW = HeapAlloc( GetProcessHeap(), 0, window_title_len ); if (!window_titleW) { SetWindowTextW( hwnd, desktop_nameW ); return; } strcpyW( window_titleW, name ); strcatW( window_titleW, desktop_name_separatorW ); strcatW( window_titleW, desktop_nameW ); SetWindowTextW( hwnd, window_titleW ); HeapFree( GetProcessHeap(), 0, window_titleW ); }
/********************************************************************* * _wsystem (MSVCRT.@) * * Unicode version of system */ int CDECL _wsystem(const MSVCRT_wchar_t* cmd) { int res; MSVCRT_wchar_t *comspec, *fullcmd; unsigned int len; static const MSVCRT_wchar_t flag[] = {' ','/','c',' ',0}; if (!(comspec = msvcrt_get_comspec())) return -1; len = strlenW(comspec) + strlenW(flag) + strlenW(cmd) + 1; if (!(fullcmd = HeapAlloc(GetProcessHeap(), 0, len * sizeof(MSVCRT_wchar_t)))) { HeapFree(GetProcessHeap(), 0, comspec); return -1; } strcpyW(fullcmd, comspec); strcatW(fullcmd, flag); strcatW(fullcmd, cmd); res = msvcrt_spawn(MSVCRT__P_WAIT, comspec, fullcmd, NULL, 1); HeapFree(GetProcessHeap(), 0, comspec); HeapFree(GetProcessHeap(), 0, fullcmd); return res; }
/*********************************************************************** * SetupUninstallOEMInfW (SETUPAPI.@) */ BOOL WINAPI SetupUninstallOEMInfW( PCWSTR inf_file, DWORD flags, PVOID reserved ) { static const WCHAR infW[] = {'\\','i','n','f','\\',0}; WCHAR target[MAX_PATH]; TRACE("%s, 0x%08x, %p\n", debugstr_w(inf_file), flags, reserved); if (!inf_file) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } if (!GetWindowsDirectoryW( target, sizeof(target)/sizeof(WCHAR) )) return FALSE; strcatW( target, infW ); strcatW( target, inf_file ); if (flags & SUOI_FORCEDELETE) return DeleteFileW(target); FIXME("not deleting %s\n", debugstr_w(target)); return TRUE; }
static BOOL find_mono_dll(LPCWSTR path, LPWSTR dll_path) { static const WCHAR mono2_dll[] = {'\\','b','i','n','\\','m','o','n','o','-','2','.','0','.','d','l','l',0}; static const WCHAR libmono2_dll[] = {'\\','b','i','n','\\','l','i','b','m','o','n','o','-','2','.','0','.','d','l','l',0}; DWORD attributes=INVALID_FILE_ATTRIBUTES; strcpyW(dll_path, path); strcatW(dll_path, libmono2_arch_dll); attributes = GetFileAttributesW(dll_path); if (attributes == INVALID_FILE_ATTRIBUTES) { strcpyW(dll_path, path); strcatW(dll_path, mono2_dll); attributes = GetFileAttributesW(dll_path); } if (attributes == INVALID_FILE_ATTRIBUTES) { strcpyW(dll_path, path); strcatW(dll_path, libmono2_dll); attributes = GetFileAttributesW(dll_path); } return (attributes != INVALID_FILE_ATTRIBUTES); }
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow) { static const WCHAR wscriptW[] = {'\\','w','s','c','r','i','p','t','.','e','x','e',0}; static const WCHAR parbW[] = {' ','/','B',' ',0}; WCHAR app[MAX_PATH]; WCHAR cmd[MAX_PATH]; PROCESS_INFORMATION pi; BOOL ret; DWORD exitcode; STARTUPINFOW si = { sizeof(si) }; WINE_FIXME("(%p %p %s %x) forwarding to wscript\n", hInst, hPrevInst, wine_dbgstr_w(cmdline), cmdshow); GetSystemDirectoryW(app, MAX_PATH); strcatW(app, wscriptW); strcpyW(cmd, app); strcatW(app, parbW); strcatW(app, cmdline); if (!CreateProcessW(app, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) return 1; WaitForSingleObject( pi.hProcess, INFINITE ); ret = GetExitCodeProcess(pi.hProcess, &exitcode); CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); if (ret) return exitcode; else return 1; }
/****************************************************************** * macho_load_file_from_dll_path * * Tries to load a Mach-O file from the dll path */ static BOOL macho_load_file_from_dll_path(HANDLE hProcess, const WCHAR* filename, unsigned long load_addr, struct macho_info* macho_info) { BOOL ret = FALSE; unsigned int index = 0; const char *path; TRACE("(%p, %s, 0x%08lx, %p)\n", hProcess, debugstr_w(filename), load_addr, macho_info); while (!ret && (path = wine_dll_enum_load_path( index++ ))) { WCHAR *name; unsigned len; len = MultiByteToWideChar(CP_UNIXCP, 0, path, -1, NULL, 0); name = HeapAlloc( GetProcessHeap(), 0, (len + lstrlenW(filename) + 2) * sizeof(WCHAR) ); if (!name) break; MultiByteToWideChar(CP_UNIXCP, 0, path, -1, name, len); strcatW( name, S_SlashW ); strcatW( name, filename ); ret = macho_load_file(hProcess, name, load_addr, macho_info); HeapFree( GetProcessHeap(), 0, name ); } TRACE(" => %d\n", ret); return ret; }
static BOOL get_assembly_directory(LPWSTR dir, DWORD size, BYTE architecture) { static const WCHAR gac[] = {'\\','a','s','s','e','m','b','l','y','\\','G','A','C',0}; static const WCHAR msil[] = {'_','M','S','I','L',0}; static const WCHAR x86[] = {'_','3','2',0}; static const WCHAR amd64[] = {'_','6','4',0}; GetWindowsDirectoryW(dir, size); strcatW(dir, gac); switch (architecture) { case peMSIL: strcatW(dir, msil); break; case peI386: strcatW(dir, x86); break; case peAMD64: strcatW(dir, amd64); break; } return TRUE; }
HRESULT DEVENUM_GetCategoryKey(REFCLSID clsidDeviceClass, HKEY *pBaseKey, WCHAR *wszRegKeyName, UINT maxLen) { if (IsEqualGUID(clsidDeviceClass, &CLSID_AudioRendererCategory) || IsEqualGUID(clsidDeviceClass, &CLSID_AudioInputDeviceCategory) || IsEqualGUID(clsidDeviceClass, &CLSID_VideoInputDeviceCategory) || IsEqualGUID(clsidDeviceClass, &CLSID_MidiRendererCategory)) { *pBaseKey = HKEY_CURRENT_USER; strcpyW(wszRegKeyName, wszActiveMovieKey); if (!StringFromGUID2(clsidDeviceClass, wszRegKeyName + strlenW(wszRegKeyName), maxLen - strlenW(wszRegKeyName))) return E_OUTOFMEMORY; } else { *pBaseKey = HKEY_CLASSES_ROOT; strcpyW(wszRegKeyName, clsid_keyname); strcatW(wszRegKeyName, wszRegSeparator); if (!StringFromGUID2(clsidDeviceClass, wszRegKeyName + CLSID_STR_LEN, maxLen - CLSID_STR_LEN)) return E_OUTOFMEMORY; strcatW(wszRegKeyName, wszRegSeparator); strcatW(wszRegKeyName, wszInstanceKeyName); } return S_OK; }
static HRESULT WINAPI AboutProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl, IInternetProtocolSink* pOIProtSink, IInternetBindInfo* pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved) { AboutProtocol *This = PROTOCOL_THIS(iface); BINDINFO bindinfo; DWORD grfBINDF = 0; LPCWSTR text = NULL; static const WCHAR html_begin[] = {0xfeff,'<','H','T','M','L','>',0}; static const WCHAR html_end[] = {'<','/','H','T','M','L','>',0}; static const WCHAR wszBlank[] = {'b','l','a','n','k',0}; static const WCHAR wszAbout[] = {'a','b','o','u','t',':'}; static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0}; /* NOTE: * the about protocol seems not to work as I would expect. It creates html document * for a given url, eg. about:some_text -> <HTML>some_text</HTML> except for the case when * some_text = "blank", when document is blank (<HTML></HMTL>). The same happens * when the url does not have "about:" in the beginning. */ TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink, pOIBindInfo, grfPI, dwReserved); memset(&bindinfo, 0, sizeof(bindinfo)); bindinfo.cbSize = sizeof(BINDINFO); IInternetBindInfo_GetBindInfo(pOIBindInfo, &grfBINDF, &bindinfo); ReleaseBindInfo(&bindinfo); TRACE("bindf %x\n", grfBINDF); if(strlenW(szUrl)>=sizeof(wszAbout)/sizeof(WCHAR) && !memcmp(wszAbout, szUrl, sizeof(wszAbout))) { text = szUrl + sizeof(wszAbout)/sizeof(WCHAR); if(!strcmpW(wszBlank, text)) text = NULL; } This->data_len = sizeof(html_begin)+sizeof(html_end)-sizeof(WCHAR) + (text ? strlenW(text)*sizeof(WCHAR) : 0); This->data = heap_alloc(This->data_len); memcpy(This->data, html_begin, sizeof(html_begin)); if(text) strcatW((LPWSTR)This->data, text); strcatW((LPWSTR)This->data, html_end); This->cur = 0; IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml); IInternetProtocolSink_ReportData(pOIProtSink, BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE, This->data_len, This->data_len); IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL); return S_OK; }
BOOL WINAPI GetUserProfileDirectoryW( HANDLE hToken, LPWSTR lpProfileDir, LPDWORD lpcchSize ) { static const WCHAR slashW[] = {'\\',0}; TOKEN_USER *t; WCHAR *userW = NULL, *dirW = NULL; DWORD len, dir_len, domain_len; SID_NAME_USE use; BOOL ret = FALSE; TRACE( "%p %p %p\n", hToken, lpProfileDir, lpcchSize ); if (!lpcchSize) { SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } len = 0; GetTokenInformation( hToken, TokenUser, NULL, 0, &len ); if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FALSE; if (!(t = HeapAlloc( GetProcessHeap(), 0, len ))) return FALSE; if (!GetTokenInformation( hToken, TokenUser, t, len, &len )) goto done; len = domain_len = 0; LookupAccountSidW( NULL, t->User.Sid, NULL, &len, NULL, &domain_len, NULL ); if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done; if (!(userW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) goto done; if (!LookupAccountSidW( NULL, t->User.Sid, userW, &len, NULL, &domain_len, &use )) goto done; dir_len = 0; GetProfilesDirectoryW( NULL, &dir_len ); if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done; if (!(dirW = HeapAlloc( GetProcessHeap(), 0, (dir_len + 1) * sizeof(WCHAR) ))) goto done; if (!GetProfilesDirectoryW( dirW, &dir_len )) goto done; len += dir_len + 2; if (*lpcchSize < len) { SetLastError( ERROR_INSUFFICIENT_BUFFER ); *lpcchSize = len; goto done; } strcpyW( lpProfileDir, dirW ); strcatW( lpProfileDir, slashW ); strcatW( lpProfileDir, userW ); *lpcchSize = len; ret = TRUE; done: HeapFree( GetProcessHeap(), 0, t ); HeapFree( GetProcessHeap(), 0, userW ); HeapFree( GetProcessHeap(), 0, dirW ); return ret; }
/*********************************************************************** * CryptCATAdminAddCatalog (WINTRUST.@) */ HCATINFO WINAPI CryptCATAdminAddCatalog(HCATADMIN catAdmin, PWSTR catalogFile, PWSTR selectBaseName, DWORD flags) { static const WCHAR slashW[] = {'\\',0}; struct catadmin *ca = catAdmin; struct catinfo *ci; WCHAR *target; DWORD len; TRACE("%p %s %s %d\n", catAdmin, debugstr_w(catalogFile), debugstr_w(selectBaseName), flags); if (!selectBaseName) { FIXME("NULL basename not handled\n"); SetLastError(ERROR_INVALID_PARAMETER); return NULL; } if (!ca || ca->magic != CATADMIN_MAGIC || !catalogFile || flags) { SetLastError(ERROR_INVALID_PARAMETER); return NULL; } len = strlenW(ca->path) + strlenW(selectBaseName) + 2; if (!(target = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)))) { SetLastError(ERROR_OUTOFMEMORY); return NULL; } strcpyW(target, ca->path); strcatW(target, slashW); strcatW(target, selectBaseName); if (!CopyFileW(catalogFile, target, FALSE)) { HeapFree(GetProcessHeap(), 0, target); return NULL; } SetFileAttributesW(target, FILE_ATTRIBUTE_SYSTEM); if (!(ci = HeapAlloc(GetProcessHeap(), 0, sizeof(*ci)))) { HeapFree(GetProcessHeap(), 0, target); SetLastError(ERROR_OUTOFMEMORY); return NULL; } ci->magic = CATINFO_MAGIC; strcpyW(ci->file, target); HeapFree(GetProcessHeap(), 0, target); return ci; }
static BOOL resolve_filename(const WCHAR *filename, WCHAR *fullname, DWORD buflen) { static const WCHAR helpW[] = {'\\','h','e','l','p','\\',0}; GetFullPathNameW(filename, buflen, fullname, NULL); if (GetFileAttributesW(fullname) == INVALID_FILE_ATTRIBUTES) { GetWindowsDirectoryW(fullname, buflen); strcatW(fullname, helpW); strcatW(fullname, filename); } return (GetFileAttributesW(fullname) != INVALID_FILE_ATTRIBUTES); }
static BOOL get_mono_path(LPWSTR path) { static const WCHAR subdir_mono[] = {'\\','m','o','n','o',0}; static const WCHAR sibling_mono[] = {'\\','.','.','\\','m','o','n','o',0}; WCHAR base_path[MAX_PATH]; const char *unix_data_dir; WCHAR *dos_data_dir; BOOL build_tree = FALSE; static WCHAR* (CDECL *wine_get_dos_file_name)(const char*); /* First try c:\windows\mono */ GetWindowsDirectoryW(base_path, MAX_PATH); strcatW(base_path, subdir_mono); if (get_mono_path_from_folder(base_path, path)) return TRUE; /* Next: /usr/share/wine/mono */ unix_data_dir = wine_get_data_dir(); if (!unix_data_dir) { unix_data_dir = wine_get_build_dir(); build_tree = TRUE; } if (unix_data_dir) { if (!wine_get_dos_file_name) wine_get_dos_file_name = (void*)GetProcAddress(GetModuleHandleA("kernel32"), "wine_get_dos_file_name"); if (wine_get_dos_file_name) { dos_data_dir = wine_get_dos_file_name(unix_data_dir); if (dos_data_dir) { strcpyW(base_path, dos_data_dir); strcatW(base_path, build_tree ? sibling_mono : subdir_mono); HeapFree(GetProcessHeap(), 0, dos_data_dir); if (get_mono_path_from_folder(base_path, path)) return TRUE; } } } /* Last: the registry */ return get_mono_path_from_registry(path); }
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; }
static LPWSTR get_url(void) { HKEY hkey; DWORD res, type; DWORD size = INTERNET_MAX_URL_LENGTH*sizeof(WCHAR); LPWSTR url; static const WCHAR wszGeckoUrl[] = {'G','e','c','k','o','U','r','l',0}; static const WCHAR httpW[] = {'h','t','t','p'}; static const WCHAR v_formatW[] = {'?','v','=',0}; /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */ res = RegOpenKeyW(HKEY_CURRENT_USER, mshtml_keyW, &hkey); if(res != ERROR_SUCCESS) return NULL; url = heap_alloc(size); res = RegQueryValueExW(hkey, wszGeckoUrl, NULL, &type, (LPBYTE)url, &size); RegCloseKey(hkey); if(res != ERROR_SUCCESS || type != REG_SZ) { heap_free(url); return NULL; } if(size > sizeof(httpW) && !memcmp(url, httpW, sizeof(httpW))) { strcatW(url, v_formatW); MultiByteToWideChar(CP_ACP, 0, GECKO_VERSION, -1, url+strlenW(url), -1); } TRACE("Got URL %s\n", debugstr_w(url)); return url; }
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) ); strcatW( cmd, rpcss ); Wow64DisableWow64FsRedirection( &redir ); rslt = CreateProcessW( cmd, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi ); Wow64RevertWow64FsRedirection( redir ); if (rslt) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); Sleep(100); } return rslt; }
/*********************************************************************** * FD31_DirListDblClick [internal] */ static LRESULT FD31_DirListDblClick( PFD31_DATA lfs ) { LONG lRet; HWND hWnd = lfs->hwnd; LPWSTR pstr; WCHAR tmpstr[BUFFILE]; /* get the raw string (with brackets) */ lRet = SendDlgItemMessageW(hWnd, lst2, LB_GETCURSEL, 0, 0); if (lRet == LB_ERR) return TRUE; pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC); SendDlgItemMessageW(hWnd, lst2, LB_GETTEXT, lRet, (LPARAM)pstr); strcpyW( tmpstr, pstr ); HeapFree(GetProcessHeap(), 0, pstr); /* get the selected directory in tmpstr */ if (tmpstr[0] == '[') { tmpstr[lstrlenW(tmpstr) - 1] = 0; strcpyW(tmpstr,tmpstr+1); } strcatW(tmpstr, FILE_bslash); FD31_ScanDir(hWnd, tmpstr); /* notify the app */ if (lfs->hook) { if (FD31_CallWindowProc(lfs, lfs->lbselchstring, lst2, MAKELONG(lRet,CD_LBSELCHANGE))) return TRUE; } return TRUE; }
/************************************************************************** * CreateFolderEnumList() */ BOOL CreateFolderEnumList(IEnumIDListImpl *list, LPCWSTR lpszPath, DWORD dwFlags) { LPITEMIDLIST pidl=NULL; WIN32_FIND_DATAW stffile; HANDLE hFile; WCHAR szPath[MAX_PATH]; BOOL succeeded = TRUE; static const WCHAR stars[] = { '*','.','*',0 }; static const WCHAR dot[] = { '.',0 }; static const WCHAR dotdot[] = { '.','.',0 }; TRACE("(%p)->(path=%s flags=0x%08x)\n", list, debugstr_w(lpszPath), dwFlags); if(!lpszPath || !lpszPath[0]) return FALSE; strcpyW(szPath, lpszPath); PathAddBackslashW(szPath); strcatW(szPath,stars); hFile = FindFirstFileW(szPath,&stffile); if ( hFile != INVALID_HANDLE_VALUE ) { BOOL findFinished = FALSE; do { if ( !(stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || (dwFlags & SHCONTF_INCLUDEHIDDEN) ) { if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && dwFlags & SHCONTF_FOLDERS && strcmpW(stffile.cFileName, dot) && strcmpW(stffile.cFileName, dotdot)) { pidl = _ILCreateFromFindDataW(&stffile); succeeded = succeeded && AddToEnumList(list, pidl); } else if (!(stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && dwFlags & SHCONTF_NONFOLDERS) { pidl = _ILCreateFromFindDataW(&stffile); succeeded = succeeded && AddToEnumList(list, pidl); } } if (succeeded) { if (!FindNextFileW(hFile, &stffile)) { if (GetLastError() == ERROR_NO_MORE_FILES) findFinished = TRUE; else succeeded = FALSE; } } } while (succeeded && !findFinished); FindClose(hFile); } return succeeded; }
static HANDLE start_rundll32( const char *inf_path, BOOL wow64 ) { static const WCHAR rundll[] = {'\\','r','u','n','d','l','l','3','2','.','e','x','e',0}; static const WCHAR setupapi[] = {' ','s','e','t','u','p','a','p','i',',', 'I','n','s','t','a','l','l','H','i','n','f','S','e','c','t','i','o','n',0}; static const WCHAR definstall[] = {' ','D','e','f','a','u','l','t','I','n','s','t','a','l','l',0}; static const WCHAR wowinstall[] = {' ','W','o','w','6','4','I','n','s','t','a','l','l',0}; static const WCHAR inf[] = {' ','1','2','8',' ','\\','\\','?','\\','u','n','i','x',0 }; WCHAR app[MAX_PATH + sizeof(rundll)/sizeof(WCHAR)]; STARTUPINFOW si; PROCESS_INFORMATION pi; WCHAR *buffer; DWORD inf_len, cmd_len; memset( &si, 0, sizeof(si) ); si.cb = sizeof(si); if (wow64) { if (!GetSystemWow64DirectoryW( app, MAX_PATH )) return 0; /* not on 64-bit */ } else GetSystemDirectoryW( app, MAX_PATH ); strcatW( app, rundll ); cmd_len = strlenW(app) * sizeof(WCHAR) + sizeof(setupapi) + sizeof(definstall) + sizeof(inf); inf_len = MultiByteToWideChar( CP_UNIXCP, 0, inf_path, -1, NULL, 0 ); if (!(buffer = HeapAlloc( GetProcessHeap(), 0, cmd_len + inf_len * sizeof(WCHAR) ))) return 0; strcpyW( buffer, app ); strcatW( buffer, setupapi ); strcatW( buffer, wow64 ? wowinstall : definstall ); strcatW( buffer, inf ); MultiByteToWideChar( CP_UNIXCP, 0, inf_path, -1, buffer + strlenW(buffer), inf_len ); if (CreateProcessW( app, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi )) CloseHandle( pi.hThread ); else pi.hProcess = 0; HeapFree( GetProcessHeap(), 0, buffer ); return pi.hProcess; }
/********************************************************************* * _wsearchenv (MSVCRT.@) * * Unicode version of _searchenv */ void CDECL MSVCRT__wsearchenv(const MSVCRT_wchar_t* file, const MSVCRT_wchar_t* env, MSVCRT_wchar_t *buf) { MSVCRT_wchar_t *envVal, *penv; MSVCRT_wchar_t curPath[MAX_PATH]; *buf = '\0'; /* Try CWD first */ if (GetFileAttributesW( file ) != INVALID_FILE_ATTRIBUTES) { GetFullPathNameW( file, MAX_PATH, buf, NULL ); /* Sigh. This error is *always* set, regardless of success */ msvcrt_set_errno(ERROR_FILE_NOT_FOUND); return; } /* Search given environment variable */ envVal = MSVCRT__wgetenv(env); if (!envVal) { msvcrt_set_errno(ERROR_FILE_NOT_FOUND); return; } penv = envVal; TRACE(":searching for %s in paths %s\n", debugstr_w(file), debugstr_w(envVal)); do { MSVCRT_wchar_t *end = penv; while(*end && *end != ';') end++; /* Find end of next path */ if (penv == end || !*penv) { msvcrt_set_errno(ERROR_FILE_NOT_FOUND); return; } memcpy(curPath, penv, (end - penv) * sizeof(MSVCRT_wchar_t)); if (curPath[end - penv] != '/' && curPath[end - penv] != '\\') { curPath[end - penv] = '\\'; curPath[end - penv + 1] = '\0'; } else curPath[end - penv] = '\0'; strcatW(curPath, file); TRACE("Checking for file %s\n", debugstr_w(curPath)); if (GetFileAttributesW( curPath ) != INVALID_FILE_ATTRIBUTES) { strcpyW(buf, curPath); msvcrt_set_errno(ERROR_FILE_NOT_FOUND); return; /* Found */ } penv = *end ? end + 1 : end; } while(1); }
/* find the directory that contains the file being run */ static LPWSTR RunDlg_GetParentDir(LPCWSTR cmdline) { const WCHAR *src; WCHAR *dest, *result, *result_end=NULL; static const WCHAR dotexeW[] = L".exe"; result = (WCHAR *)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(strlenW(cmdline)+5)); if (NULL == result) { TRACE("HeapAlloc couldn't allocate %d bytes\n", sizeof(WCHAR)*(strlenW(cmdline)+5)); return NULL; } src = cmdline; dest = result; if (*src == '"') { src++; while (*src && *src != '"') { if (*src == '\\') result_end = dest; *dest++ = *src++; } } else { while (*src) { if (isspaceW(*src)) { *dest = 0; if (INVALID_FILE_ATTRIBUTES != GetFileAttributesW(result)) break; strcatW(dest, dotexeW); if (INVALID_FILE_ATTRIBUTES != GetFileAttributesW(result)) break; } else if (*src == '\\') result_end = dest; *dest++ = *src++; } } if (result_end) { *result_end = 0; return result; } else { HeapFree(GetProcessHeap(), 0, result); return NULL; } }
static HRESULT WINAPI ITSS_IStorageImpl_OpenStream( IStorage* iface, LPCOLESTR pwcsName, void* reserved1, DWORD grfMode, DWORD reserved2, IStream** ppstm) { ITSS_IStorageImpl *This = impl_from_IStorage(iface); IStream_Impl *stm; DWORD len; struct chmUnitInfo ui; int r; WCHAR *path, *p; TRACE("%p %s %p %u %u %p\n", This, debugstr_w(pwcsName), reserved1, grfMode, reserved2, ppstm ); len = strlenW( This->dir ) + strlenW( pwcsName ) + 1; path = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); strcpyW( path, This->dir ); if( pwcsName[0] == '/' || pwcsName[0] == '\\' ) { p = &path[strlenW( path ) - 1]; while( ( path <= p ) && ( *p == '/' ) ) *p-- = 0; } strcatW( path, pwcsName ); for(p=path; *p; p++) { if(*p == '\\') *p = '/'; } if(*--p == '/') *p = 0; TRACE("Resolving %s\n", debugstr_w(path)); r = chm_resolve_object(This->chmfile, path, &ui); HeapFree( GetProcessHeap(), 0, path ); if( r != CHM_RESOLVE_SUCCESS ) { WARN("Could not resolve object\n"); return STG_E_FILENOTFOUND; } stm = ITSS_create_stream( This, &ui ); if( !stm ) return E_FAIL; *ppstm = &stm->IStream_iface; return S_OK; }
/********************************************************************* * _wmakepath (MSVCRT.@) * * Unicode version of _wmakepath. */ VOID CDECL _wmakepath(MSVCRT_wchar_t *path, const MSVCRT_wchar_t *drive, const MSVCRT_wchar_t *directory, const MSVCRT_wchar_t *filename, const MSVCRT_wchar_t *extension) { MSVCRT_wchar_t ch; TRACE("%s %s %s %s\n", debugstr_w(drive), debugstr_w(directory), debugstr_w(filename), debugstr_w(extension)); if ( !path ) return; path[0] = 0; if (drive && drive[0]) { path[0] = drive[0]; path[1] = ':'; path[2] = 0; } if (directory && directory[0]) { strcatW(path, directory); ch = path[strlenW(path) - 1]; if (ch != '/' && ch != '\\') { static const MSVCRT_wchar_t backslashW[] = {'\\',0}; strcatW(path, backslashW); } } if (filename && filename[0]) { strcatW(path, filename); if (extension && extension[0]) { if ( extension[0] != '.' ) { static const MSVCRT_wchar_t dotW[] = {'.',0}; strcatW(path, dotW); } strcatW(path, extension); } } TRACE("returning %s\n", debugstr_w(path)); }
/*********************************************************************** * CryptCATAdminResolveCatalogPath (WINTRUST.@) */ BOOL WINAPI CryptCATAdminResolveCatalogPath(HCATADMIN hcatadmin, WCHAR *catalog_file, CATALOG_INFO *info, DWORD flags) { static const WCHAR slashW[] = {'\\',0}; struct catadmin *ca = hcatadmin; TRACE("%p %s %p %x\n", hcatadmin, debugstr_w(catalog_file), info, flags); if (!ca || ca->magic != CATADMIN_MAGIC || !info || info->cbStruct != sizeof(*info) || flags) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } strcpyW(info->wszCatalogFile, ca->path); strcatW(info->wszCatalogFile, slashW); strcatW(info->wszCatalogFile, catalog_file); return TRUE; }
static void append_productcode(MSIPACKAGE* package, LPCWSTR action_property, LPCWSTR productid) { LPWSTR prop; LPWSTR newprop; DWORD len; UINT r; prop = msi_dup_property(package->db, action_property ); if (prop) len = strlenW(prop); else len = 0; /*separator*/ len ++; len += strlenW(productid); /*null*/ len++; newprop = msi_alloc( len*sizeof(WCHAR) ); if (prop) { strcpyW(newprop,prop); strcatW(newprop,szSemiColon); } else newprop[0] = 0; strcatW(newprop,productid); r = msi_set_property( package->db, action_property, newprop ); if (r == ERROR_SUCCESS && !strcmpW( action_property, szSourceDir )) msi_reset_folders( package, TRUE ); TRACE("Found Related Product... %s now %s\n", debugstr_w(action_property), debugstr_w(newprop)); msi_free( prop ); msi_free( newprop ); }
static void write_propvalue_str(WCHAR *str, DBPROP *prop) { VARIANT *v = &prop->vValue; VARIANT vstr; HRESULT hr; if (V_VT(v) == VT_BSTR) { strcatW(str, V_BSTR(v)); return; } VariantInit(&vstr); hr = VariantChangeType(&vstr, v, VARIANT_ALPHABOOL, VT_BSTR); if (hr == S_OK) { strcatW(str, V_BSTR(&vstr)); VariantClear(&vstr); } }
static BOOL run_winemenubuilder( const WCHAR *args ) { static const WCHAR menubuilder[] = {'\\','w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',0}; LONG len; LPWSTR buffer; STARTUPINFOW si; PROCESS_INFORMATION pi; BOOL ret; WCHAR app[MAX_PATH]; void *redir; GetSystemDirectoryW( app, MAX_PATH - sizeof(menubuilder)/sizeof(WCHAR) ); strcatW( app, menubuilder ); len = (strlenW( app ) + strlenW( args ) + 1) * sizeof(WCHAR); buffer = heap_alloc( len ); if( !buffer ) return FALSE; strcpyW( buffer, app ); strcatW( buffer, args ); TRACE("starting %s\n",debugstr_w(buffer)); memset(&si, 0, sizeof(si)); si.cb = sizeof(si); Wow64DisableWow64FsRedirection( &redir ); ret = CreateProcessW( app, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ); Wow64RevertWow64FsRedirection( redir ); heap_free( buffer ); if (ret) { CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); } return ret; }
static WCHAR *get_full_name(const WCHAR *path, WCHAR **relative_path) { static const WCHAR tasksW[] = { '\\','t','a','s','k','s','\\',0 }; WCHAR *target; int len; len = GetSystemDirectoryW(NULL, 0); len += strlenW(tasksW) + strlenW(path); target = heap_alloc(len * sizeof(WCHAR)); if (target) { GetSystemDirectoryW(target, len); strcatW(target, tasksW); if (relative_path) *relative_path = target + strlenW(target) - 1; while (*path == '\\') path++; strcatW(target, path); } return target; }
/****************************************************************** * macho_load_file_from_path * Tries to load a Mach-O file from a set of paths (separated by ':') */ static BOOL macho_load_file_from_path(HANDLE hProcess, const WCHAR* filename, unsigned long load_addr, const char* path, struct macho_info* macho_info) { BOOL ret = FALSE; WCHAR *s, *t, *fn; WCHAR* pathW = NULL; unsigned len; TRACE("(%p, %s, 0x%08lx, %s, %p)\n", hProcess, debugstr_w(filename), load_addr, debugstr_a(path), macho_info); if (!path) return FALSE; len = MultiByteToWideChar(CP_UNIXCP, 0, path, -1, NULL, 0); pathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); if (!pathW) return FALSE; MultiByteToWideChar(CP_UNIXCP, 0, path, -1, pathW, len); for (s = pathW; s && *s; s = (t) ? (t+1) : NULL) { t = strchrW(s, ':'); if (t) *t = '\0'; fn = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(filename) + 1 + lstrlenW(s) + 1) * sizeof(WCHAR)); if (!fn) break; strcpyW(fn, s); strcatW(fn, S_SlashW); strcatW(fn, filename); ret = macho_load_file(hProcess, fn, load_addr, macho_info); HeapFree(GetProcessHeap(), 0, fn); if (ret) break; s = (t) ? (t+1) : NULL; } TRACE(" => %d\n", ret); HeapFree(GetProcessHeap(), 0, pathW); return ret; }
HRESULT WINAPI LoadLibraryShim( LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE * phModDll) { HRESULT ret=S_OK; WCHAR dll_filename[MAX_PATH]; WCHAR version[MAX_PATH]; static const WCHAR default_version[] = {'v','1','.','1','.','4','3','2','2',0}; static const WCHAR slash[] = {'\\',0}; DWORD dummy; TRACE("(%p %s, %p, %p, %p)\n", szDllName, debugstr_w(szDllName), szVersion, pvReserved, phModDll); if (!szDllName || !phModDll) return E_POINTER; if (!get_install_root(dll_filename)) { ERR("error reading registry key for installroot\n"); dll_filename[0] = 0; } else { if (!szVersion) { ret = GetCORVersion(version, MAX_PATH, &dummy); if (SUCCEEDED(ret)) szVersion = version; else szVersion = default_version; } strcatW(dll_filename, szVersion); strcatW(dll_filename, slash); } strcatW(dll_filename, szDllName); *phModDll = LoadLibraryW(dll_filename); return *phModDll ? S_OK : E_HANDLE; }