/** * Converts a descriptor of type HBufc16 to Wstring * * @param aSrc is the descriptor to be converted , aDes is the * reference to the Wstring array where the result of conversion * is stored * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, * -4 is EInvalidPointer , -5 is EDescriptorNoData) */ EXPORT_C int Hbufc16ToWstring(HBufC16* aSrc, wstring& aDes) { unsigned int ilen = 0; if (!aSrc) { return EInvalidPointer; } else { ilen = aSrc->Length(); if (0 == ilen ) { return EDescriptorNoData; } } wchar_t* wcharString = new wchar_t[ilen+1]; if (!wcharString) { return EInsufficientSystemMemory; } wmemcpy((wchar_t*)wcharString, (const wchar_t*)aSrc->Ptr(), ilen); wcharString[ilen] = L'\0'; aDes.assign(wcharString); delete []wcharString; return ESuccess; }
// Load a string from the registry // bool WebCam::LoadSetting(const WCHAR* name, wstring& value) { HKEY hkey; if (RegOpenKeyEx(HKEY_CURRENT_USER, sRegKey.c_str(), 0, KEY_EXECUTE, &hkey) != ERROR_SUCCESS) return false; // Determine length of string // TCHAR szValue[8193]; DWORD keysize = sizeof(szValue); LONG l = RegQueryValueEx(hkey, name, NULL, NULL, reinterpret_cast<BYTE*>(szValue), &keysize); RegCloseKey(hkey); if (ERROR_SUCCESS != l) return false; if (keysize < sizeof(TCHAR)) return false; value.assign(szValue, keysize/sizeof(TCHAR) - 1); return true; }
OSErr HandleToString(const Handle h, wstring & outString) { OSErr error = kNoErr; const wstring sEmptyWString; outString = sEmptyWString; int32 s = sPSHandle->GetSize(h); if (s > 0) { Boolean oldLock = FALSE; uint16 * p = NULL; sPSHandle->SetLock(h, true, reinterpret_cast<char**>(&p), &oldLock); if (p != NULL) { outString.assign(p, p + ( s / sizeof(uint16) )); sPSHandle->SetLock(h, false, reinterpret_cast<char**>(&p), &oldLock); } else { error = errPlugInHostInsufficient; } } else { error = errPlugInHostInsufficient; } return error; }
bool winRegistry::TryGetRegistryValue(HKEY hkeyParent, const wstring& path, const wstring& valueName, wstring& value) { DWORD valueType; if (!TryGetRegistryValue(hkeyParent, path, valueName, value, valueType)) { return false; } if (valueType == REG_EXPAND_SZ) { DWORD n = ExpandEnvironmentStringsW(value.c_str(), nullptr, 0); if (n == 0) { MIKTEX_FATAL_WINDOWS_ERROR_2("ExpandEnvironmentStringsW", "str", WU_(path)); } vector<wchar_t> buf; buf.reserve(n); DWORD n2 = ExpandEnvironmentStringsW(value.c_str(), buf.data(), n); if (n2 == 0) { MIKTEX_FATAL_WINDOWS_ERROR_2("ExpandEnvironmentStringsW", "str", WU_(path)); } MIKTEX_ASSERT(n2 == n); value.assign(buf.data(), n2); } return true; }
bool input_dlg(const GUID& id, const wstring& title, const wstring& msg, wstring& text, INPUTBOXFLAGS flags) { Buffer<wchar_t> buf(1024); if (g_far.InputBox(&c_plugin_guid, &id, title.c_str(), msg.c_str(), nullptr, text.c_str(), buf.data(), static_cast<int>(buf.size()), nullptr, flags)) { text.assign(buf.data()); return true; } return false; }
bool WONCommon::ConvertRawBytesToWideString(const WONCommon::RawBuffer& theRawBytes, wstring& theStringR) { if(theRawBytes.length() % 2) return false; theStringR.assign(reinterpret_cast<const wchar_t*>(theRawBytes.data()), theRawBytes.length()/2); makeLittleEndianWString(theStringR); return true; }
bool get_volume_guid_path( const wstring& volume_mount_point, wstring& volume_guid_path ) { unsigned buf_size = MAX_PATH; unique_ptr<wchar_t[ ]> buffer( new wchar_t[ buf_size ] ); if ( !::GetVolumeNameForVolumeMountPointW( add_trailing_slash( volume_mount_point ).c_str( ), buffer.get( ), buf_size ) ) { return false; } volume_guid_path.assign( buffer.get( ) ); return true; }
static int split_next(const wstring &src, wstring &des, char ch, int start){ int pos = 0; pos = src.find(ch, start); des.clear(); if(pos < start){ pos = src.length(); } if(pos > start){ des.assign(src, start, pos - start); } return pos; }
//--------------------------------------------------------------------- void StrToWstr(const char* str, wstring& dstr) { CryStackStringT<wchar_t, 64> tmp; tmp.resize(strlen(str)); tmp.clear(); while (const wchar_t c=(wchar_t)(*str++)) { tmp.append(1, c); } dstr.assign(tmp.data(), tmp.length()); }
bool get_device_path( const wstring& volume_guid_path, wstring& volume_dev_path ) { const wstring c_prefix( L"\\\\?\\" ); if ( volume_guid_path.size( ) < c_prefix.size( ) || volume_guid_path.substr( 0, c_prefix.size( ) ) != c_prefix ) { return false; } unsigned buf_size = MAX_PATH; unique_ptr<wchar_t[ ]> buffer( new wchar_t[ buf_size ] ); SetLastError( NO_ERROR ); DWORD len = QueryDosDeviceW( del_trailing_slash( volume_guid_path ).substr( 4 ).c_str( ), buffer.get( ), buf_size ); if ( len == 0 || GetLastError( ) != NO_ERROR ) { return false; } volume_dev_path.assign( buffer.get( ) ); return true; }
DWORD getPluginDirectory(wstring& directory) { DWORD result; HINSTANCE hinst = (HINSTANCE)GetModuleHandleW(PLUGIN_NAME L".dll"); wchar_t* p; wchar_t buffer[TEXTLEN] = {0}; result = GetModuleFileNameW(hinst, buffer, TEXTLEN); p = wcsrchr(buffer, '\\'); if (p) { *p = '\0'; directory.assign(buffer); return 1; } else return 0; }
bool Key::query_str_nt(wstring& value, const wchar_t* name) { DWORD type = REG_SZ; DWORD data_size; LONG res = RegQueryValueExW(h_key, name, nullptr, &type, nullptr, &data_size); if (res != ERROR_SUCCESS) { SetLastError(res); return false; } Buffer<wchar_t> buf(data_size / sizeof(wchar_t)); res = RegQueryValueExW(h_key, name, nullptr, &type, reinterpret_cast<LPBYTE>(buf.data()), &data_size); if (res != ERROR_SUCCESS) { SetLastError(res); return false; } value.assign(buf.data(), buf.size() - 1); return true; }
/** * Converts a descriptor of type RBuf16 to Wstring * * @param aSrc is the descriptor to be converted , aDes is the * reference to the Wstring array where the result of conversion * is stored * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, * -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData) */ EXPORT_C int Rbuf16ToWstring(TDes16& aSrc, wstring& aDes) { unsigned int ilen = aSrc.Length(); if (0 == ilen) { return EDescriptorNoData; } wchar_t* buf = new wchar_t[ilen+1]; if(!buf) { return EInsufficientSystemMemory; } wmemcpy (buf,(wchar_t *)aSrc.Ptr(), ilen); buf[ilen]=L'\0'; aDes.assign(buf); delete[] buf; return ESuccess; }
EXPORT_C int Tbuf16ToWstring(TDes16& aSrc, wstring& aDes) { unsigned int ilen = aSrc.Length(); if (0 == ilen) { return EDescriptorNoData; } wchar_t* wcharString = new wchar_t[ilen+1]; if (!wcharString) { return EInsufficientSystemMemory; } wmemcpy((wchar_t*)wcharString, (const wchar_t*)aSrc.Ptr(), ilen); wcharString[ilen] = L'\0'; aDes.assign(wcharString); delete []wcharString; return ESuccess; }