本文整理汇总了C++中wstring::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::c_str方法的具体用法?C++ wstring::c_str怎么用?C++ wstring::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wstring
的用法示例。
在下文中一共展示了wstring::c_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseFileType
/// <summary>Get file-type from name</summary>
/// <exception cref="Logic::ArgumentException">Unrecognised file type</exception>
UtilExport FileType ParseFileType(const wstring& type)
{
// Case insensitive comparison
if (StrCmpI(type.c_str(), L"Unknown") == 0)
return FileType::Unknown;
else if (StrCmpI(type.c_str(), L"Universe") == 0)
return FileType::Universe;
else if (StrCmpI(type.c_str(), L"Project") == 0)
return FileType::Project;
else if (StrCmpI(type.c_str(), L"Mission") == 0)
return FileType::Mission;
else if (StrCmpI(type.c_str(), L"Language") == 0)
return FileType::Language;
else if (StrCmpI(type.c_str(), L"Script") == 0)
return FileType::Script;
// Unrecognised:
throw ArgumentException(HERE, L"t", VString(L"Unrecognised fileType '%s'", type.c_str()));
}
示例2: Write
void Registry::Write(const wstring keyName, const wstring value)
{
if (!good) return;
RegSetValueEx(key, keyName.c_str(), 0, REG_SZ, (LPBYTE)value.c_str(), (DWORD)( (value.length()+1)*2 ));
}
示例3: ToDouble
double ToDouble(const wstring& str) {
return _wtof(str.c_str());
}
示例4: OAuthWebRequestSignedSubmit
wstring OAuthWebRequestSignedSubmit(
const HTTPParameters& oauthParameters,
const wstring& url,
const wstring& httpMethod,
const HTTPParameters* postParameters
)
{
_TRACE("OAuthWebRequestSignedSubmit(%s)", url.c_str());
wstring oauthHeader = L"Authorization: OAuth ";
oauthHeader += OAuthBuildHeader(oauthParameters);
oauthHeader += L"\r\n";
_TRACE("%s", oauthHeader.c_str());
wchar_t host[1024*4] = {};
wchar_t path[1024*4] = {};
URL_COMPONENTS components = { sizeof(URL_COMPONENTS) };
components.lpszHostName = host;
components.dwHostNameLength = SIZEOF(host);
components.lpszUrlPath = path;
components.dwUrlPathLength = SIZEOF(path);
wstring normalUrl = url;
BOOL crackUrlOk = InternetCrackUrl(url.c_str(), url.size(), 0, &components);
_ASSERTE(crackUrlOk);
wstring result;
// TODO you'd probably want to InternetOpen only once at app initialization
HINTERNET hINet = InternetOpen(L"tc2/1.0",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
0 );
_ASSERTE( hINet != NULL );
if ( hINet != NULL )
{
// TODO add support for HTTPS requests
HINTERNET hConnection = InternetConnect(
hINet,
host,
components.nPort,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0, 0 );
_ASSERTE(hConnection != NULL);
if ( hConnection != NULL)
{
HINTERNET hData = HttpOpenRequest( hConnection,
httpMethod.c_str(),
path,
NULL,
NULL,
NULL,
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_AUTH | INTERNET_FLAG_RELOAD,
0 );
_ASSERTE(hData != NULL);
if ( hData != NULL )
{
BOOL oauthHeaderOk = HttpAddRequestHeaders(hData,
oauthHeader.c_str(),
oauthHeader.size(),
0);
_ASSERTE(oauthHeaderOk);
// NOTE POST requests are supported, but the MIME type is hardcoded to application/x-www-form-urlencoded (aka. form data)
// TODO implement support for posting image, raw or other data types
string postDataUTF8;
if(Compare(httpMethod, L"POST", false) && postParameters)
{
wstring contentHeader = L"Content-Type: application/x-www-form-urlencoded\r\n";
BOOL contentHeaderOk = HttpAddRequestHeaders(hData,
contentHeader.c_str(),
contentHeader.size(),
0);
_ASSERTE(contentHeaderOk);
postDataUTF8 = WideToUTF8(BuildQueryString(*postParameters));
_TRACE("POST DATA: %S", postDataUTF8.c_str());
}
BOOL sendOk = HttpSendRequest( hData, NULL, 0, (LPVOID)(postDataUTF8.size() > 0 ? postDataUTF8.c_str() : NULL), postDataUTF8.size());
_ASSERTE(sendOk);
// TODO dynamically allocate return buffer
BYTE buffer[1024*32] = {};
DWORD dwRead = 0;
while(
InternetReadFile( hData, buffer, SIZEOF(buffer) - 1, &dwRead ) &&
dwRead > 0
)
{
buffer[dwRead] = 0;
result += UTF8ToWide((char*)buffer);
//.........这里部分代码省略.........
示例5: cacheFile
static ID3DBlob* CompileShader(const wchar* path, const char* functionName, const char* profile,
const D3D_SHADER_MACRO* defines, bool forceOptimization,
vector<wstring>& filePaths)
{
// Make a hash off the expanded shader code
string shaderCode = GetExpandedShaderCode(path, filePaths);
wstring cacheName = MakeShaderCacheName(shaderCode, functionName, profile, defines);
if(FileExists(cacheName.c_str()))
{
File cacheFile(cacheName.c_str(), File::OpenRead);
const uint64 shaderSize = cacheFile.Size();
vector<uint8> compressedShader;
compressedShader.resize(shaderSize);
cacheFile.Read(shaderSize, compressedShader.data());
ID3DBlob* decompressedShader[1] = { nullptr };
uint32 indices[1] = { 0 };
DXCall(D3DDecompressShaders(compressedShader.data(), shaderSize, 1, 0,
indices, 0, decompressedShader, nullptr));
return decompressedShader[0];
}
std::printf("Compiling shader %s %s %s\n", WStringToAnsi(GetFileName(path).c_str()).c_str(),
profile, MakeDefinesString(defines).c_str());
// Loop until we succeed, or an exception is thrown
while(true)
{
UINT flags = D3DCOMPILE_WARNINGS_ARE_ERRORS;
#ifdef _DEBUG
flags |= D3DCOMPILE_DEBUG;
if(forceOptimization == false)
flags |= D3DCOMPILE_SKIP_OPTIMIZATION;
#endif
ID3DBlob* compiledShader;
ID3DBlobPtr errorMessages;
HRESULT hr = D3DCompileFromFile(path, defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, functionName,
profile, flags, 0, &compiledShader, &errorMessages);
if(FAILED(hr))
{
if(errorMessages)
{
wchar message[1024] = { 0 };
char* blobdata = reinterpret_cast<char*>(errorMessages->GetBufferPointer());
MultiByteToWideChar(CP_ACP, 0, blobdata, static_cast<int>(errorMessages->GetBufferSize()), message, 1024);
std::wstring fullMessage = L"Error compiling shader file \"";
fullMessage += path;
fullMessage += L"\" - ";
fullMessage += message;
// Pop up a message box allowing user to retry compilation
int retVal = MessageBoxW(nullptr, fullMessage.c_str(), L"Shader Compilation Error", MB_RETRYCANCEL);
if(retVal != IDRETRY)
throw DXException(hr, fullMessage.c_str());
#if EnableShaderCaching_
shaderCode = GetExpandedShaderCode(path);
cacheName = MakeShaderCacheName(shaderCode, functionName, profile, defines);
#endif
}
else
{
_ASSERT(false);
throw DXException(hr);
}
}
else
{
// Compress the shader
D3D_SHADER_DATA shaderData;
shaderData.pBytecode = compiledShader->GetBufferPointer();
shaderData.BytecodeLength = compiledShader->GetBufferSize();
ID3DBlobPtr compressedShader;
DXCall(D3DCompressShaders(1, &shaderData, D3D_COMPRESS_SHADER_KEEP_ALL_PARTS, &compressedShader));
// Create the cache directory if it doesn't exist
if(DirectoryExists(baseCacheDir.c_str()) == false)
Win32Call(CreateDirectory(baseCacheDir.c_str(), nullptr));
if(DirectoryExists(cacheDir.c_str()) == false)
Win32Call(CreateDirectory(cacheDir.c_str(), nullptr));
File cacheFile(cacheName.c_str(), File::OpenWrite);
// Write the compiled shader to disk
uint64 shaderSize = compressedShader->GetBufferSize();
cacheFile.Write(shaderSize, compressedShader->GetBufferPointer());
return compiledShader;
}
}
}
示例6: IsFolder
bool install_util::IsFolder(const wstring& path) {
return PathExists(path) && ((GetFileAttributes(path.c_str()) & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
}
示例7: Identify
bool AudioQualityIdent::Identify(const wstring& fullPathName, int* sampleRate,
int* bitrate, int* channels, int* cutoff,
int64* duration, wstring* format)
{
assert(mediaInfo_);
assert(spectrumSource_);
assert(sampleRate);
assert(bitrate);
assert(channels);
assert(cutoff);
assert(duration);
assert(format);
if (!mediaInfo_ || !spectrumSource_ || !sampleRate || !bitrate ||
!channels || !cutoff || !duration || !format)
return false;
const wchar_t* unknownFormat = L"[Unknown]";
*sampleRate = 0;
*bitrate = 0;
*channels = 0;
*cutoff = 0;
*duration = 0;
*format = unknownFormat;
ifstream audioFile(fullPathName.c_str(), std::ios::binary);
audioFile.seekg(0, std::ios::end);
int fileSize = static_cast<int>(audioFile.tellg());
if (fileSize > 0) {
unique_ptr<int8[]> buf(new int8[fileSize]);
audioFile.seekg(0);
audioFile.read(reinterpret_cast<char*>(buf.get()), fileSize);
// Retrieve all necessary media information.
PassString ps(format);
if (!mediaInfo_->GetInstantMediaInfo(buf.get(), fileSize, duration,
bitrate, &ps, NULL, sampleRate,
channels, NULL)) {
// Return true and mark this file as an unrecognized format.
return true;
}
if (format->empty())
*format = unknownFormat;
// Retrieve the average cutoff frequency.
scoped_refptr<MySpectrumReceiver> receiver(
new MySpectrumReceiver(*sampleRate, cancelFlag_));
if (!spectrumSource_->Open(fullPathName.c_str())) {
// Return true and mark this file as an unrecognized format.
return true;
}
// Exclude the first 10 sec data.
if (!spectrumSource_->Seek(10.0)) {
// Return true so that we know it is a short-duration music.
return true;
}
int channel = 0;
IAudioSpectrumReceiver* r = receiver.get();
spectrumSource_->ExtractSpectrum(&channel, 1, 1024, &r);
if (cancelFlag_ && cancelFlag_->IsSet())
return false;
*cutoff = receiver->GetAverageFreq();
return true;
}
return false;
}
示例8: DownloadCurrency
DWORD DownloadCurrency(DWORD dwSendTimeOut, wstring& tUrl, string& info)
{
CUrlCrack url;
if (!url.Crack(tUrl.c_str()))
return 1000;
HINTERNET m_hInetSession; // 会话句柄
HINTERNET m_hInetConnection; // 连接句柄
HINTERNET m_hInetFile; //
m_hInetSession = ::InternetOpen(L"Moneyhub4.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (m_hInetSession == NULL)
{
return 3000;
}
DWORD dwTimeOut = 60000;//初始化为5s
//DWORD dwSendTimeOut = 5000;
InternetSetOptionEx(m_hInetSession, INTERNET_OPTION_SEND_TIMEOUT, &dwSendTimeOut, sizeof(DWORD), 0);
InternetSetOptionEx(m_hInetSession, INTERNET_OPTION_RECEIVE_TIMEOUT, &dwSendTimeOut, sizeof(DWORD), 0);
InternetSetOptionEx(m_hInetSession, INTERNET_OPTION_CONNECT_TIMEOUT, &dwTimeOut, sizeof(DWORD), 0);
m_hInetConnection = ::InternetConnect(m_hInetSession, url.GetHostName(), url.GetPort(), NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if (m_hInetConnection == NULL)
{
InternetCloseHandle(m_hInetSession);
return 3001;
}
LPCTSTR ppszAcceptTypes[2];
ppszAcceptTypes[0] = _T("*/*");
ppszAcceptTypes[1] = NULL;
USES_CONVERSION;
m_hInetFile = HttpOpenRequestW(m_hInetConnection, _T("GET"), url.GetPath(), NULL, NULL, ppszAcceptTypes, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_KEEP_CONNECTION, 0);
if (m_hInetFile == NULL)
{
InternetCloseHandle(m_hInetConnection);
InternetCloseHandle(m_hInetSession);
return 3002;
}
BOOL bSend = ::HttpSendRequestW(m_hInetFile, NULL, 0, NULL, 0);
if (!bSend)
{
int Error = GetLastError();
InternetCloseHandle(m_hInetConnection);
InternetCloseHandle(m_hInetFile);
InternetCloseHandle(m_hInetSession);
return Error;
}
TCHAR szStatusCode[32];
DWORD dwInfoSize = sizeof(szStatusCode);
if (!HttpQueryInfo(m_hInetFile, HTTP_QUERY_STATUS_CODE, szStatusCode, &dwInfoSize, NULL))
{
InternetCloseHandle(m_hInetConnection);
InternetCloseHandle(m_hInetFile);
InternetCloseHandle(m_hInetSession);
return 3004;
}
else
{
long nStatusCode = _ttol(szStatusCode);
if (nStatusCode != HTTP_STATUS_PARTIAL_CONTENT && nStatusCode != HTTP_STATUS_OK)
{
InternetCloseHandle(m_hInetConnection);
InternetCloseHandle(m_hInetFile);
InternetCloseHandle(m_hInetSession);
return 3005;
}
}
DWORD dwBytesRead = 0;
char szReadBuf[1024];
DWORD dwBytesToRead = sizeof(szReadBuf);
bool sucess = true;
do
{
memset(szReadBuf, 0 , 1024);
if (!::InternetReadFile(m_hInetFile, szReadBuf, dwBytesToRead, &dwBytesRead))
{
sucess = false;
break;
}
else if (dwBytesRead)
{
info += szReadBuf;
}
}while (dwBytesRead);
InternetCloseHandle(m_hInetConnection);
InternetCloseHandle(m_hInetFile);
InternetCloseHandle(m_hInetSession);
if(sucess != true)
return 3007;
return 0;
}
示例9: HandleNonFatalException
void ExceptionHelper::HandleNonFatalException(Logger* logger, ErrorHandler* errorHandler, wstring message)
{
logger->LogFormatted(LogLevels::Error, L"%ls\n%ls", message.c_str(), GetCurrentExceptionMessage().c_str());
errorHandler->ShowError(message);
}
示例10: LoadFontPageSettings
void Font::LoadFontPageSettings( FontPageSettings &cfg, IniFile &ini, const RString &sTexturePath, const RString &sPageName, RString sChars )
{
cfg.m_sTexturePath = sTexturePath;
/* If we have any characters to map, add them. */
for( unsigned n=0; n<sChars.size(); n++ )
{
char c = sChars[n];
cfg.CharToGlyphNo[c] = n;
}
int iNumFramesWide, iNumFramesHigh;
RageTexture::GetFrameDimensionsFromFileName( sTexturePath, &iNumFramesWide, &iNumFramesHigh );
int iNumFrames = iNumFramesWide * iNumFramesHigh;
ini.RenameKey("Char Widths", "main");
// LOG->Trace("Loading font page '%s' settings from page name '%s'",
// TexturePath.c_str(), sPageName.c_str());
ini.GetValue( sPageName, "DrawExtraPixelsLeft", cfg.m_iDrawExtraPixelsLeft );
ini.GetValue( sPageName, "DrawExtraPixelsRight", cfg.m_iDrawExtraPixelsRight );
ini.GetValue( sPageName, "AddToAllWidths", cfg.m_iAddToAllWidths );
ini.GetValue( sPageName, "ScaleAllWidthsBy", cfg.m_fScaleAllWidthsBy );
ini.GetValue( sPageName, "LineSpacing", cfg.m_iLineSpacing );
ini.GetValue( sPageName, "Top", cfg.m_iTop );
ini.GetValue( sPageName, "Baseline", cfg.m_iBaseline );
ini.GetValue( sPageName, "DefaultWidth", cfg.m_iDefaultWidth );
ini.GetValue( sPageName, "AdvanceExtraPixels", cfg.m_iAdvanceExtraPixels );
ini.GetValue( sPageName, "TextureHints", cfg.m_sTextureHints );
/* Iterate over all keys. */
const XNode* pNode = ini.GetChild( sPageName );
if( pNode )
{
FOREACH_CONST_Attr( pNode, pAttr )
{
RString sName = pAttr->first;
const XNodeValue *pValue = pAttr->second;
sName.MakeUpper();
/* If val is an integer, it's a width, eg. "10=27". */
if( IsAnInt(sName) )
{
cfg.m_mapGlyphWidths[atoi(sName)] = pValue->GetValue<int>();
continue;
}
/* "map codepoint=frame" maps a char to a frame. */
if( sName.substr(0, 4) == "MAP " )
{
/*
* map CODEPOINT=frame. CODEPOINT can be
* 1. U+hexval
* 2. an alias ("oq")
* 3. a character in quotes ("X")
*
* map 1=2 is the same as
* range unicode #1-1=2
*/
RString sCodepoint = sName.substr(4); /* "CODEPOINT" */
wchar_t c;
if( sCodepoint.substr(0, 2) == "U+" && IsHexVal(sCodepoint.substr(2)) )
sscanf( sCodepoint.substr(2).c_str(), "%x", &c );
else if( sCodepoint.size() > 0 &&
utf8_get_char_len(sCodepoint[0]) == int(sCodepoint.size()) )
{
c = utf8_get_char( sCodepoint.c_str() );
if(c == wchar_t(-1))
LOG->Warn("Font definition '%s' has an invalid value '%s'.",
ini.GetPath().c_str(), sName.c_str() );
}
else if( !FontCharAliases::GetChar(sCodepoint, c) )
{
LOG->Warn("Font definition '%s' has an invalid value '%s'.",
ini.GetPath().c_str(), sName.c_str() );
continue;
}
cfg.CharToGlyphNo[c] = pValue->GetValue<int>();
continue;
}
if( sName.substr(0, 6) == "RANGE " )
{
/*
* range CODESET=first_frame or
* range CODESET #start-end=first_frame
* eg
* range CP1252=0 (default for 256-frame fonts)
* range ASCII=0 (default for 128-frame fonts)
*
* (Start and end are in hex.)
*
* Map two high-bit portions of ISO-8859- to one font:
* range ISO-8859-2 #80-FF=0
* range ISO-8859-3 #80-FF=128
*
//.........这里部分代码省略.........
示例11:
Url::Url(wstring string)
{
_extractpath((wchar_t *)string.c_str());
}
示例12: write_wstring
void write_wstring(byte*& w, wstring v) {
int l = v.length();
write_int(w, l);
memcpy(w, v.c_str(), l << 1);
w += l << 1;
}
示例13: parse
//
// Parse a vNote string and fills the propertyMap.
//
int WinNote::parse(const wstring dataString) {
WCHAR* element = NULL;
//
// Parse the vNote and fill the VObject.
// -----------------------------------------
//
VObject* vo = VConverter::parse(dataString.c_str());
if (!vo) {
setError(1, ERR_ITEM_VOBJ_PARSE);
LOG.error("%s", getLastErrorMsg());
return 1;
}
// Check if VObject type and version are the correct ones.
if (!checkVNoteTypeAndVersion(vo)) {
if (vo) delete vo;
return 1;
}
//
// Conversion: vObject -> WinNote.
// -------------------------------
// Note: properties found are added to the propertyMap, so that the
// map will contain only parsed properties after this process.
//
if (element = getVObjectPropertyValue(vo, L"SUMMARY")) {
setProperty(L"Subject", element);
}
if (element = getVObjectPropertyValue(vo, L"BODY")) {
setProperty(L"Body", element);
}
if (element = getVObjectPropertyValue(vo, L"CATEGORIES")) {
setProperty(L"Categories", element);
}
if (element = getVObjectPropertyValue(vo, L"X-FUNAMBOL-FOLDER")) {
setProperty(L"Folder", element);
}
//
// ---- Other Funambol defined properties ----
// Support for other fields that don't have a
// specific correspondence in vNote.
if (element = getVObjectPropertyValue(vo, L"X-FUNAMBOL-COLOR")) {
WCHAR tmp[10];
int i=0;
for (i=0; i<NUM_NOTE_COLOR; i++) {
if (!wcscmp(colorName[i], element)) { break; }
}
if (i == NUM_NOTE_COLOR) {
i = 1; // Default = yellow
}
wsprintf(tmp, TEXT("%i"), i);
setProperty(L"Color", tmp);
}
if (element = getVObjectPropertyValue(vo, L"X-FUNAMBOL-POSITION")) {
VProperty* vp = vo->getProperty(TEXT("X-FUNAMBOL-POSITION"));
element = vp->getPropComponent(1);
if (element && wcslen(element)>0) { setProperty(L"Top", element); }
element = vp->getPropComponent(2);
if (element && wcslen(element)>0) { setProperty(L"Left", element); }
element = vp->getPropComponent(3);
if (element && wcslen(element)>0) { setProperty(L"Height", element); }
element = vp->getPropComponent(4);
if (element && wcslen(element)>0) { setProperty(L"Width", element); }
}
return 0;
}
示例14: ChangeText
void CPicDlgQuery::ChangeText(int IDC, wstring text){
::SendMessage(GetDlgItem(IDC)->m_hWnd, WM_SETTEXT, 0, (LPARAM)text.c_str());
}
示例15: SetWindowTextEx
HWND SetWindowTextEx(wstring text) {
HWND hWnd = GetConsoleWindow();
SetWindowText(hWnd, text.c_str());
return hWnd;
}