BOOL FileMap_truncate(FileMap *pfm, int offset, wchar_t **pErrMsgBuf) { // This function will fail if file was opened as read-only. _ASSERT(pfm->hFile && pfm->hMap && pfm->pMem); if(!offset) // because it fails at zero offset = 1; else if(offset > 0 && offset > pfm->size) // cannot truncate beyond file offset = pfm->size; else if(offset < 0 && abs(offset) > pfm->size) // cannot truncate before first byte offset = 1; // Unmap file, but keep it open. UnmapViewOfFile(pfm->pMem); CloseHandle(pfm->hMap); // Truncate file; negative offset cuts from end to beginning. if(SetFilePointer(pfm->hFile, offset, NULL, offset > 0 ? FILE_BEGIN : FILE_END) == INVALID_SET_FILE_POINTER) { FileMap_close(pfm); if(pErrMsgBuf) *pErrMsgBuf = _wcsdup(L"Could not set file pointer position."); // user must free buf return FALSE; } if(!SetEndOfFile(pfm->hFile)) { FileMap_close(pfm); if(pErrMsgBuf) *pErrMsgBuf = _wcsdup(L"Could not set new end of file."); // user must free buf return FALSE; } SetFilePointer(pfm->hFile, 0, NULL, FILE_BEGIN); // rewind // Remapping into memory. pfm->hMap = CreateFileMapping(pfm->hFile, NULL, PAGE_READWRITE, 0, 0, NULL); if(!pfm->hMap) { FileMap_close(pfm); if(pErrMsgBuf) *pErrMsgBuf = _wcsdup(L"Could not recreate file mapping."); // user must free buf return FALSE; } // Get new pointer to data block, old one just became invalid! pfm->pMem = MapViewOfFile(pfm->hMap, FILE_MAP_WRITE, 0, 0, 0); if(!pfm->pMem) { FileMap_close(pfm); if(pErrMsgBuf) *pErrMsgBuf = _wcsdup(L"Could not remap view of file."); // user must free buf return FALSE; } // Calculate new file size. if(offset > 0) pfm->size = offset; else pfm->size += offset; return TRUE; }
BOOL CNewMenu::LoadAllItems() { DWORD dwIndex = 0; WCHAR wszName[MAX_PATH]; SHELLNEW_ITEM *pNewItem; SHELLNEW_ITEM *pCurItem = NULL; /* If there are any unload them */ UnloadAllItems(); /* Enumerate all extesions */ while (RegEnumKeyW(HKEY_CLASSES_ROOT, dwIndex++, wszName, _countof(wszName)) == ERROR_SUCCESS) { if (wszName[0] != L'.') continue; pNewItem = LoadItem(wszName); if (pNewItem) { if (wcsicmp(pNewItem->pwszExt, L".lnk") == 0) { /* Link handler */ m_pLinkItem = pNewItem; } else { /* Add at the end of list */ if (pCurItem) { pCurItem->pNext = pNewItem; pCurItem = pNewItem; } else pCurItem = m_pItems = pNewItem; } } } if (!m_pLinkItem) { m_pLinkItem = static_cast<SHELLNEW_ITEM *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SHELLNEW_ITEM))); if (m_pLinkItem) { m_pLinkItem->Type = SHELLNEW_TYPE_NULLFILE; m_pLinkItem->pwszDesc = _wcsdup(L"Link"); m_pLinkItem->pwszExt = _wcsdup(L".lnk"); } } if (m_pItems == NULL) return FALSE; else return TRUE; }
void CFb2EpubConverterPaths::ReadTargets(LPTSTR strINILocation) { ReleaseTargets(); WCHAR temp[PATH_SIZE+1]; ::ZeroMemory(temp,sizeof(WCHAR)*PATH_SIZE); UINT count = ::GetPrivateProfileInt(TARGETS_SECTION,L"TargetsCount",0,strINILocation); if ( count <= 0 ) { return; } target* pTempTargets = new target[count]; ::ZeroMemory(pTempTargets,count*sizeof(target)); WCHAR section[1024]; for (UINT i=1; i <= count; i ++ ) { ::ZeroMemory(section,sizeof(WCHAR)*1024); wsprintf(section,L"Target%d",i); ::ZeroMemory(temp,sizeof(WCHAR)*PATH_SIZE); target tempTarget; bool bAdd = (::GetPrivateProfileInt(section,L"ShowInShell",1,strINILocation) == 1); if ( bAdd ) { DWORD dwRes = ::GetPrivateProfileString(section,L"TargetPath",NULL,temp,1024,strINILocation); if (dwRes != 0) { tempTarget.path = _wcsdup(temp); ::ZeroMemory(temp,sizeof(WCHAR)*PATH_SIZE); DWORD dwRes = ::GetPrivateProfileString(section,L"TargetName",NULL,temp,1024,strINILocation); if (dwRes == 0) { tempTarget.name = L""; } else { tempTarget.name = _wcsdup(temp); } pTempTargets[m_uiTargetsCount++] = tempTarget; } } } if ( m_uiTargetsCount > 0 ) // if at least one target detected { m_pTargetsArray = new target[m_uiTargetsCount]; for(UINT32 i=0; i < m_uiTargetsCount; i++ ) { m_pTargetsArray[i] = pTempTargets[i]; } } ::ZeroMemory(pTempTargets,count*sizeof(target)); delete []pTempTargets; }
BOOL OOG_SelectCharacter(const wchar_t* szCharacter) { if (ClientState() != ClientStateMenu) return NULL; // Select the first control on the character selection screen. Control* pControl = findControl(CONTROL_TEXTBOX, (const wchar_t*)NULL, -1, 237, 178, 72, 93); ControlText* cText; while (pControl != NULL) { if (pControl->dwType == CONTROL_TEXTBOX && pControl->pFirstText != NULL && pControl->pFirstText->pNext != NULL) cText = pControl->pFirstText->pNext; else cText = NULL; if (cText != NULL) { if (!cText->wText[0]) return FALSE; wchar_t* cLine = _wcsdup(cText->wText[0]); wchar_t* cCharacter = _wcsdup(szCharacter); StringToLower(cLine); StringToLower(cCharacter); if (wcslen(cLine) == wcslen(cCharacter) && wcsstr(cLine, cCharacter) != NULL) { free(cLine); free(cCharacter); if (!clickControl(pControl)) return FALSE; // OK Button // Bobode Sleep(7000); pControl = findControl(CONTROL_BUTTON, (const wchar_t*)NULL, -1, 627, 572, 128, 35); if (pControl) { if (!clickControl(pControl)) return FALSE; return TRUE; } else return FALSE; } else { free(cLine); free(cCharacter); } } pControl = pControl->pNext; } return FALSE; }
dlgWndPinpadInfo::dlgWndPinpadInfo( unsigned long ulHandle, DlgPinUsage PinPusage, DlgPinOperation operation, const std::wstring & csReader, const std::wstring & PinName, const std::wstring & Message, HWND Parent) :Win32Dialog(L"WndPinpadInfo") { m_szHeader=NULL; m_szMessage=NULL; m_ModalHold = false; m_szMessage = _wcsdup( Message.c_str() ); m_ulHandle = ulHandle; std::wstring tmpTitle = L""; tmpTitle += GETSTRING_DLG(PinpadInfo); if (PinPusage == DLG_PIN_AUTH) m_szHeader = _wcsdup( L"Pin da Autenticação" ); else m_szHeader = _wcsdup( PinName.c_str() ); if(!csReader.empty()) { tmpTitle += L" - "; tmpTitle += csReader; } if( CreateWnd( tmpTitle.c_str() , 420, 280, 0, Parent ) ) { if( PinPusage == DLG_PIN_SIGN ) ImagePIN = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_BITMAP2) ); else ImagePIN = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_BITMAP1) ); CreateBitapMask( ImagePIN, ImagePIN_Mask ); TextFont = CreateFont( 16, 0, 0, 0, FW_DONTCARE, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Arial" ); SendMessage( Parent, WM_SETFONT, (WPARAM)TextFont, 0 ); } }
static void ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(thread_set_nameW),_init))(const wchar_t* name) { TIDT tid = __itt_thread_id(); __itt_thread_info *h_tail, *h; if (!__itt_ittapi_global.api_initialized && __itt_ittapi_global.thread_list->tid == 0) { __itt_init_ittlib_name(NULL, __itt_group_all); if (ITTNOTIFY_NAME(thread_set_nameW) && ITTNOTIFY_NAME(thread_set_nameW) != ITT_VERSIONIZE(ITT_JOIN(_N_(thread_set_nameW),_init))) { ITTNOTIFY_NAME(thread_set_nameW)(name); return; } } __itt_mutex_lock(&__itt_ittapi_global.mutex); for (h_tail = NULL, h = __itt_ittapi_global.thread_list; h != NULL; h_tail = h, h = h->next) if (h->tid == tid) break; if (h == NULL) { NEW_THREAD_INFO_W(&__itt_ittapi_global, h, h_tail, tid, __itt_thread_normal, name); } else { h->nameW = name ? _wcsdup(name) : NULL; } __itt_mutex_unlock(&__itt_ittapi_global.mutex); }
DWORD exec(const wchar_t *cmdLine) { SECURITY_ATTRIBUTES sa = { 0 }; STARTUPINFO si = { 0 }; wchar_t *cmdLine2 = NULL; PROCESS_INFORMATION pi = { 0 }; DWORD dwExitCode = 1; // returned by executed program sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_SHOW; // Avoid eventual crash under Unicode compiling. cmdLine2 = _wcsdup(cmdLine); if(CreateProcess(0, cmdLine2, &sa, 0, FALSE, 0, 0, 0, &si, &pi)) { WaitForSingleObject(pi.hProcess, INFINITE); // the program flow is stopped here to wait GetExitCodeProcess(pi.hProcess, &dwExitCode); CloseHandle(pi.hThread); CloseHandle(pi.hProcess); } free(cmdLine2); return dwExitCode; }
/* * Code to figure out the user's home directory using the registry */ static WCHAR* getHomeFromRegistry() { HKEY key; int rc; DWORD type; WCHAR *p; WCHAR path[MAX_PATH+1]; int size = MAX_PATH+1; rc = RegOpenKeyEx(HKEY_CURRENT_USER, SHELL_KEY, 0, KEY_READ, &key); if (rc != ERROR_SUCCESS) { // Shell folder doesn't exist??!! return NULL; } path[0] = 0; rc = RegQueryValueExW(key, L"Desktop", 0, &type, (LPBYTE)path, &size); if (rc != ERROR_SUCCESS || type != REG_SZ) { return NULL; } RegCloseKey(key); /* Get the parent of Desktop directory */ p = wcsrchr(path, L'\\'); if (p == NULL) { return NULL; } *p = L'\0'; return _wcsdup(path); }
BOOL ParseProxyList() { WCHAR * tmpProxyString = _wcsdup(szProxyString); ExpandEnvironmentStrings(tmpProxyString, szProxyString, sizeof(szProxyString)/sizeof(szProxyString[0])); free(tmpProxyString); WCHAR *sep = L"\n"; WCHAR *pos = wcstok(szProxyString, sep); INT i = 0; lpProxyList[i++] = L""; while (pos && i < sizeof(lpProxyList)/sizeof(lpProxyList[0])) { lpProxyList[i++] = pos; pos = wcstok(NULL, sep); } lpProxyList[i] = 0; for (LPSTR ptr = szRasPbk; *ptr; ptr++) { if (*ptr == '\n') { *ptr++ = 0; } } return TRUE; }
/*--------------------------------------------------------------------------*/ wchar_t *getProcessorNameString(void) { wchar_t *ProcessorNameString = NULL; HKEY key; DWORD result; ULONG length = LenMaxLine; ULONG Type = 0; result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, KeyCentralProcessor, 0, KEY_QUERY_VALUE , &key); if (result == ERROR_SUCCESS) { wchar_t LineResult[LenMaxLine]; if ( RegQueryValueExW(key, KeyProcessorNameString, 0, &Type, (LPBYTE)LineResult, &length) == ERROR_SUCCESS ) { if( Type == REG_SZ ) { ProcessorNameString = _wcsdup(LineResult); } } RegCloseKey(key); } return ProcessorNameString; }
wchar_t * StrToUnicode( const char *buf ) { wchar_t unibuf[1024]; ASCIIToUnicode( buf, unibuf, sizeof(unibuf) ); return _wcsdup( unibuf ); }
L2ItemTemplate::L2ItemTemplate( L2ItemType itemType, L2ItemSubType subType, StatsSet& set ) { m_type = itemType; m_subType = subType; int temp_i; // id set.getInt( "item_id", &m_itemId ); // name std::wstring wstr_name; set.getWString( "name", wstr_name ); m_name = NULL; if( wstr_name.length() > 0 ) m_name = _wcsdup( wstr_name.c_str() ); set.getInt( "type1", &m_type1, 0 ); set.getInt( "type2", &m_type2, 0 ); set.getInt( "weight", &m_weight, 0 ); set.getBool( "crystallizable", &m_crystallizable, false ); set.getBool( "stackable", &m_stackable, false ); set.getInt( "material", (int *)&m_materialType ); set.getInt( "crystal_type", (int *)&m_crystalType, (int)CRYSTAL_NONE ); // default to none-grade set.getInt( "duration", &m_duration ); // default 0 or -1? set.getInt( "time", &m_time ); // default seems to be -1 set.getInt( "bodypart", &temp_i ); m_bodyPart = (L2ItemSlot)temp_i; set.getInt( "price", &m_referencePrice ); set.getInt( "crystal_count", &m_crystalCount, 0 ); set.getBool( "sellable", &m_sellable, true ); set.getBool( "dropable", &m_dropable, true ); set.getBool( "destroyable", &m_destroyable, true ); set.getBool( "tradeable", &m_tradeable, true ); // checks by item id m_common = (m_itemId >= 12006 && m_itemId <= 12361) || (m_itemId >= 11605 && m_itemId <= 12308); m_heroItem = (m_itemId >= 6611 && m_itemId <= 6621) || (m_itemId >= 9388 && m_itemId <= 9390) || m_itemId == 6842; m_pvpItem = (m_itemId >= 10667 && m_itemId <= 10792) || (m_itemId >= 10793 && m_itemId <= 10835) || (m_itemId >= 12852 && m_itemId <= 12977) || (m_itemId >= 14363 && m_itemId <= 14519) || (m_itemId >= 14520 && m_itemId <= 14525) || m_itemId == 14528 || m_itemId == 14529 || m_itemId == 14558; }
/*--------------------------------------------------------------------------*/ wchar_t *getCpuArchitecture(void) { wchar_t *CpuArchitecture = NULL; wchar_t *Identifier = getCpuIdentifier(); if (Identifier) { wchar_t wArch[LenMaxLine]; wchar_t wFamily[LenMaxLine]; wchar_t wFamilyValue[LenMaxLine]; wchar_t wModel[LenMaxLine]; wchar_t wModelValue[LenMaxLine]; wchar_t wStepping[LenMaxLine]; wchar_t wSteppingValue[LenMaxLine]; swscanf(Identifier, L"%s %s %s %s %s %s %s", wArch, wFamily, wFamilyValue, wModel, wModelValue, wStepping, wSteppingValue); CpuArchitecture = _wcsdup(wArch); free(Identifier); Identifier = NULL; } return CpuArchitecture; }
wchar_t *ExciteWindow::GetTranslationPath(Language src, Language dst, const wchar_t *text) { if (src != LANGUAGE_Japanese && dst != LANGUAGE_Japanese || src == dst) return NULL; const wchar_t *p; switch (dst != LANGUAGE_Japanese ? dst : src) { case LANGUAGE_English: p = L"/world/english_japanese/"; break; case LANGUAGE_Chinese_Simplified: case LANGUAGE_Chinese_Traditional: p = L"/world/chinese/"; break; case LANGUAGE_Korean: p = L"/world/korean/"; break; case LANGUAGE_French: p = L"/world/french/"; break; case LANGUAGE_German: p = L"/world/german/"; break; case LANGUAGE_Italian: p = L"/world/italian/"; break; case LANGUAGE_Spanish: p = L"/world/spanish/"; break; case LANGUAGE_Portuguese: p = L"/world/portuguese/"; break; case LANGUAGE_Russian: p = L"/world/russian/"; break; default: return NULL; } return _wcsdup(p); }
void PropertyPageHandler_BaseReloc::OnInitDialog() { // Insert Tabs TCITEM item; for (int i = 0; i < m_PEReaderWriter.getNoOfBaseRelocationTables(); ++i) { item.mask = TCIF_TEXT; item.pszText = LPWSTR(_wcsdup(wstring(L"Table " + DWORD_toString(i + 1)).c_str())); TabCtrl_InsertItem(m_hTabsBaseReloc, i, &item); free(item.pszText); } // Insert ListView columns LV_COLUMN column; ZeroMemory(&column, sizeof(LV_COLUMN)); for (size_t i = 0; i < ARRAYSIZE(szGenericColumnText); ++i) { column.mask = LVCF_TEXT; column.pszText = szGenericColumnText[i]; ListView_InsertColumn(m_hListViewBaseRelocTable, i, &column); } tabsBaseRelocations_OnTabChanged(m_hWnd, 0); }
/* * Code to figure out the user's home directory using shell32.dll */ WCHAR* getHomeFromShell32() { HRESULT rc; LPITEMIDLIST item_list = 0; WCHAR *p; WCHAR path[MAX_PATH+1]; int size = MAX_PATH+1; rc = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOPDIRECTORY, &item_list); if (!SUCCEEDED(rc)) { // we can't find the shell folder. return NULL; } path[0] = 0; SHGetPathFromIDListW(item_list, (LPWSTR)path); /* Get the parent of Desktop directory */ p = wcsrchr(path, L'\\'); if (p) { *p = 0; } /* * We've been successful. Note that we don't free the memory allocated * by ShGetSpecialFolderLocation. We only ever come through here once, * and only if the registry lookup failed, so it's just not worth it. * * We also don't unload the SHELL32 DLL. We've paid the hit for loading * it and we may need it again later. */ return _wcsdup(path); }
/**获取当前模块所在的完整路径*/ const wchar_t* PathHelper::GetModulePath(HINSTANCE hInstance) { WCHAR szModulePath[MAX_PATH + 1]; ::GetModuleFileName(hInstance, szModulePath, MAX_PATH); return _wcsdup(szModulePath); }
WatchData::WatchData(const WCHAR* path, int mask, bool watchSubtree, HANDLE completionPort) : _watchId(++_counter), _mask(mask), _watchSubtree(watchSubtree), _byteReturned(0), _completionPort(completionPort) { _path = _wcsdup(path); _hDir = CreateFileW(_path, FILE_LIST_DIRECTORY | GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, //security attributes OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL); if(_hDir == INVALID_HANDLE_VALUE ) { throw GetLastError(); } if (NULL == CreateIoCompletionPort(_hDir, _completionPort, (ULONG_PTR)_watchId, 0)) { throw GetLastError(); } }
VOID CALLBACK XDbgProxy::LdrDllNotification(ULONG NotificationReason, PCLDR_DLL_NOTIFICATION_DATA NotificationData, PVOID Context) { if (!_attached) return; DebugEventPacket event; memset(&event, 0, sizeof(event)); DEBUG_EVENT& msg = event.event; msg.dwProcessId = XDbgGetCurrentProcessId(); msg.dwThreadId = XDbgGetCurrentThreadId(); if (NotificationReason == LDR_DLL_NOTIFICATION_REASON_LOADED) { msg.dwDebugEventCode = LOAD_DLL_DEBUG_EVENT; msg.u.LoadDll.dwDebugInfoFileOffset = 0; msg.u.LoadDll.fUnicode = 1; msg.u.LoadDll.hFile = NULL; msg.u.LoadDll.lpBaseOfDll = NotificationData->Loaded.DllBase; msg.u.LoadDll.lpImageName = _wcsdup(NotificationData->Loaded.FullDllName->Buffer); msg.u.LoadDll.nDebugInfoSize = 0; } else if (NotificationReason == LDR_DLL_NOTIFICATION_REASON_UNLOADED) { msg.dwDebugEventCode = UNLOAD_DLL_DEBUG_EVENT; msg.u.UnloadDll.lpBaseOfDll = NotificationData->Unloaded.DllBase; } else return; pushDbgEvent(event); }
status_t PortCreateFile(fsd_t *fsd, vnode_id_t dir, const wchar_t *name, void **cookie) { port_fsd_t *pfsd; port_t *server; pfsd = (port_fsd_t*) fsd; assert(dir == VNODE_ROOT); //wprintf(L"PortCreateFile(%s)\n", name); server = malloc(sizeof(port_t)); if (server == NULL) return errno; memset(server, 0, sizeof(port_t)); server->is_server = true; server->u.server.name = _wcsdup(name); *cookie = server; SpinAcquire(&pfsd->sem); LIST_ADD(pfsd->server, server); SpinRelease(&pfsd->sem); return 0; }
wchar_t * _wgetcwd(wchar_t *buffer, int maxlen) { wchar_t *result; WCHAR wszPath[MAX_PATH + 1]; WCHAR *p; if(!GetModuleFileNameW(NULL, wszPath, MAX_PATH + 1)) { errno = GetLastError(); return NULL; } /* Remove the filename part of the path to leave the directory */ p = wcsrchr(wszPath, L'\\'); if(p) *p = L'\0'; if(buffer == NULL) result = _wcsdup(wszPath); else if(wcslen(wszPath) + 1 > (size_t)maxlen) { result = NULL; errno = ERROR_INSUFFICIENT_BUFFER; } else { wcsncpy(buffer, wszPath, maxlen); buffer[maxlen - 1] = L'\0'; result = buffer; } return result; }
void CommonUtility::OnNPPDocumentModified() { // Tell the WakaTime backend that a document has been modified in Notepad++. std::wstring pythonpath = GetPythonPath(); std::wstring filepath = GetCurrentNPPDocument(); /* std::wstring configpath = GetNPPConfigDirectory() + L"\\wakatime\\"; std::wstring wakatimecmd = L"wakatime-cli.py"; std::wstring pluginver = L" --plugin \"notepadpp notepadpp-wakatime/1.0.0\" ";*/ std::wstring fileinvoke = L" --file "; std::wstring command = GetCommandPrefix() + fileinvoke + filepath; PROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo; ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION)); ZeroMemory(&siStartInfo, sizeof(STARTUPINFO)); siStartInfo.cb = sizeof(STARTUPINFO); siStartInfo.dwFlags |= STARTF_USESHOWWINDOW; siStartInfo.wShowWindow = SW_HIDE; LPTSTR commanddup = _wcsdup(command.c_str()); if (CreateProcess(pythonpath.c_str(), commanddup, NULL, NULL, true, CREATE_NO_WINDOW, NULL, NULL, &siStartInfo, &piProcInfo)) { CloseHandle(piProcInfo.hProcess); CloseHandle(piProcInfo.hThread); } delete commanddup; }
/*--------------------------------------------------------------------------*/ wchar_t *getCpuVendor(void) { wchar_t *CpuManufacturer = NULL; HKEY key; DWORD result; ULONG length = LenMaxLine; ULONG Type = 0; result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, KeyCentralProcessor, 0, KEY_QUERY_VALUE , &key); if (result == ERROR_SUCCESS) { wchar_t LineResult[LenMaxLine]; if ( RegQueryValueExW(key, KeyVendorIdentifier, 0, &Type, (LPBYTE)LineResult, &length) == ERROR_SUCCESS ) { if( Type == REG_SZ ) { CpuManufacturer = _wcsdup(LineResult); } } RegCloseKey(key); } return CpuManufacturer; }
static void _ignoreAll(HWND hwnd){ int index, count, len; wchar_t *pText, *pWord; BOOL fFound = FALSE; PSUGGESTION ps; index = SendDlgItemMessageW(hwnd, IDC_LST_MISPRINTS, LB_GETCURSEL, 0, 0); ps = (PSUGGESTION)SendDlgItemMessageW(hwnd, IDC_LST_MISPRINTS, LB_GETITEMDATA, index, 0); pWord = _wcsdup(ps->word); while(TRUE){ count = SendDlgItemMessageW(hwnd, IDC_LST_MISPRINTS, LB_GETCOUNT, 0, 0); fFound = FALSE; for(int i = 0; i < count; i++){ len = SendDlgItemMessageW(hwnd, IDC_LST_MISPRINTS, LB_GETTEXTLEN, i, 0); pText = calloc(len + 1, sizeof(wchar_t)); SendDlgItemMessageW(hwnd, IDC_LST_MISPRINTS, LB_GETTEXT, i, (LPARAM)pText); if(wcscmp(pText, pWord) == 0){ SendDlgItemMessageW(hwnd, IDC_LST_MISPRINTS, LB_SETCURSEL, i, 0); _ignoreOnce(hwnd); fFound = TRUE; } free(pText); if(fFound) break; } if(!fFound) break; } free(pWord); }
/*! * @brief Creates a new named pipe transport instance. * @param config The Named Pipe configuration block. * @param size Pointer to the size of the parsed config block. * @return Pointer to the newly configured/created Named Pipe transport instance. */ Transport* transport_create_named_pipe(MetsrvTransportNamedPipe* config, LPDWORD size) { Transport* transport = (Transport*)calloc(1, sizeof(Transport)); NamedPipeTransportContext* ctx = (NamedPipeTransportContext*)calloc(1, sizeof(NamedPipeTransportContext)); if (size) { *size = sizeof(MetsrvTransportNamedPipe); } // Lock used to synchronise writes ctx->write_lock = lock_create(); dprintf("[TRANS NP] Creating pipe transport for url %S", config->common.url); transport->type = METERPRETER_TRANSPORT_PIPE; transport->timeouts.comms = config->common.comms_timeout; transport->timeouts.retry_total = config->common.retry_total; transport->timeouts.retry_wait = config->common.retry_wait; transport->url = _wcsdup(config->common.url); transport->packet_transmit = packet_transmit_named_pipe; transport->transport_init = configure_named_pipe_connection; transport->transport_destroy = transport_destroy_named_pipe; transport->transport_reset = transport_reset_named_pipe; transport->server_dispatch = server_dispatch_named_pipe; transport->get_handle = transport_get_handle_named_pipe; transport->set_handle = transport_set_handle_named_pipe; transport->ctx = ctx; transport->comms_last_packet = current_unix_timestamp(); transport->get_migrate_context = get_migrate_context_named_pipe; transport->get_config_size = transport_get_config_size_named_pipe; return transport; }
bool LOCATOR::FSaveFileNames(const wchar_t *wszFilename) { m_wszExePath = _wcsdup(wszFilename); if (m_wszExePath == NULL) { SetError(EC_OUT_OF_MEMORY); return false; } _wsplitpath_s(m_wszExePath, NULL, 0, NULL, 0, m_wszExeFName, _countof(m_wszExeFName), m_wszExeExt, _countof(m_wszExeExt)); if ((m_wszExeExt[0] != L'\0') && (m_wszExeExt[1] != L'\0')) { // The executable filename includes a file extension m_wszExt = m_wszExeExt + 1; } else { // The executable filename does not include a file extension m_wszExt = NULL; } return true; }
int GetStreamName(IStorage* storage, int index, wchar_t** out) { int res; ULONG count; LPENUMSTATSTG enumstatstg; STATSTG stat; assert(storage != NULL); assert(out != NULL); *out = NULL; res = storage->lpVtbl->EnumElements(storage, 0, NULL, 0, &enumstatstg); if (res != S_OK) return 0; while (index >= 0) { res = enumstatstg->lpVtbl->Next(enumstatstg, 1, &stat, &count); if (res != S_OK) return 0; index--; } *out = _wcsdup(stat.pwcsName); enumstatstg->lpVtbl->Release(enumstatstg); return (*out == NULL)? 0 : 1; }
/*! * \brief Installs a new device * * This function will ask the specified driver for the given device; * the driver is loaded if not already present. * * \param driver Name of the device driver * \param name Name of the new device * \param cfg Configuration list to assign to the new device * \param profile_key Path to the device's profile key * \return \p true if the driver could be loaded (or was already present), * \p false otherwise */ bool DevInstallDevice(const wchar_t *driver, const wchar_t *name, dev_config_t *cfg) { driver_t *drv; drv = DevInstallNewDriver(driver); if (drv == NULL) { wprintf(L"%s.%s: driver not loaded\n", driver, name); return false; } if (drv->add_device != NULL) { load_request_t load = { 0 }; load.action = LOAD_ACTION_ADD_DEVICE; load.u.add_device.driver = drv; load.u.add_device.name = _wcsdup(name); load.u.add_device.config = cfg; DevCallLoader(&load); free(load.u.add_device.name); } return true; }
void Method_init(LPCOLESTR _name, DISPID dispid) { name= _wcsdup(_name); this->dispid=dispid; putJavaIndex= getJavaIndex= methodJavaIndex=0; };
/********************************************************************* * _wgetdcwd (MSVCRT.@) * * Unicode version of _wgetdcwd. */ MSVCRT_wchar_t* CDECL _wgetdcwd(int drive, MSVCRT_wchar_t * buf, int size) { static MSVCRT_wchar_t* dummy; TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size); if (!drive || drive == _getdrive()) return _wgetcwd(buf,size); /* current */ else { MSVCRT_wchar_t dir[MAX_PATH]; MSVCRT_wchar_t drivespec[4] = {'A', ':', '\\', 0}; int dir_len; drivespec[0] += drive - 1; if (GetDriveTypeW(drivespec) < DRIVE_REMOVABLE) { *MSVCRT__errno() = MSVCRT_EACCES; return NULL; } dir_len = GetFullPathNameW(drivespec,MAX_PATH,dir,&dummy); if (dir_len >= size || dir_len < 1) { *MSVCRT__errno() = MSVCRT_ERANGE; return NULL; /* buf too small */ } TRACE(":returning %s\n", debugstr_w(dir)); if (!buf) return _wcsdup(dir); /* allocate */ strcpyW(buf,dir); } return buf; }