本文整理汇总了C++中std::tstring类的典型用法代码示例。如果您正苦于以下问题:C++ tstring类的具体用法?C++ tstring怎么用?C++ tstring使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了tstring类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TstringToString
ScriptComponent::ScriptComponent(const std::tstring& filename)
{
m_pScript = MyServiceLocator::GetInstance()->GetService<ResourceService>()->Load<LuaScript>(filename);
auto slashIdx = filename.find_last_of(_T('/'));
m_ShortFilename = TstringToString(filename.substr(slashIdx+1, filename.find_last_of(_T('.')) - slashIdx - 1));
}
示例2: RenamePrinter
void RenamePrinter(const std::tstring& currentPrinterName, const std::tstring& newPrinterName)
{
HANDLE printer = 0;
PRINTER_INFO_2 *printerInfo = 0;
DEVMODE *pDevMode = 0;
try
{
// get the printer and it's info structure...
PRINTER_DEFAULTS printerDefaults;
ZeroMemory(&printerDefaults, sizeof(printerDefaults));
printerDefaults.DesiredAccess = PRINTER_ALL_ACCESS;
BOOL result = OpenPrinter((LPTSTR)currentPrinterName.c_str(), &printer, &printerDefaults);
if (!result || (0 == printer))
throw Workshare::Exception(_T("Failed to open printer."));
DWORD bufferSize = 0;
SetLastError(0);
result = GetPrinter(printer, 2, 0, 0, &bufferSize);
if ((!result) && (GetLastError() != ERROR_INSUFFICIENT_BUFFER) || (bufferSize == 0))
throw Workshare::Exception(_T("Failed to get printer info buffer size."));
printerInfo = (PRINTER_INFO_2 *)GlobalAlloc(GPTR, bufferSize);
if (0 == printerInfo)
throw Workshare::System::SystemException(_T("Failed to allocate printer info buffer."));
result = GetPrinter(printer, 2, (LPBYTE)printerInfo, bufferSize, &bufferSize);
if (!result)
throw Workshare::Exception(_T("Failed to get printer info."));
// If GetPrinter didn't fill in the DEVMODE, try to get it by calling DocumentProperties...
LONG lFlag;
if (0 == printerInfo->pDevMode)
{
bufferSize = DocumentProperties(0, printer, (LPTSTR)currentPrinterName.c_str(), 0, 0, 0);
if (bufferSize <= 0)
throw Workshare::Exception(_T("Failed to get document properties buffer size."));
pDevMode = (DEVMODE *)GlobalAlloc(GPTR, bufferSize);
if (0 == pDevMode)
throw Workshare::System::SystemException(_T("Failed to allocate document properties buffer."));
lFlag = DocumentProperties(0, printer, (LPTSTR)currentPrinterName.c_str(), pDevMode, 0, DM_OUT_BUFFER);
if (lFlag != IDOK || 0 == pDevMode)
throw Workshare::Exception(_T("Failed to get document properties."));
printerInfo->pDevMode = pDevMode;
}
if (!(printerInfo->pDevMode->dmFields & DM_ORIENTATION))
throw Workshare::Exception(_T("Printer does not support the required name change."));
// Specify the new printer name...
printerInfo->pPrinterName = (LPTSTR)newPrinterName.c_str() ;
// Do not attempt to set security descriptor...
printerInfo->pSecurityDescriptor = 0;
lFlag = DocumentProperties(0, printer, (LPTSTR)currentPrinterName.c_str(), printerInfo->pDevMode,
printerInfo->pDevMode, DM_IN_BUFFER | DM_OUT_BUFFER);
if (IDOK != lFlag)
throw Workshare::Exception(_T("Failed to update the devmode part of document properties."));
result = SetPrinter(printer, 2, (LPBYTE)printerInfo, 0);
if (!result)
throw Workshare::Exception(_T("Failed to update printer information."));
// Tell other apps that there was a change...
SendMessageTimeout(HWND_BROADCAST, WM_DEVMODECHANGE, 0L,
(LPARAM)(LPCTSTR)(LPTSTR)currentPrinterName.c_str(), SMTO_NORMAL, 1000, 0);
return;
}
catch(...)
{
if (printerInfo)
GlobalFree(printerInfo);
if (printer)
ClosePrinter(printer);
if (pDevMode)
GlobalFree(pDevMode);
throw;
}
}
示例3: ExtractLyrics
BOOL GoogleLyricsProvider::ExtractLyrics(std::tstring& page)
{
UINT maxCharSeqLen = 0;
LPCTSTR maxFirstSeqChar = 0;
LPCTSTR maxLastSeqChar = 0;
UINT curCharSeqLen = 0;
LPCTSTR curFirstSeqChar = 0;
LPCTSTR curChar = page.c_str();
BOOL bInTag = FALSE;
BOOL bBRHasBeenFound = FALSE;
std::tstring ansi;
for (int pass = 0; pass < 2; pass++)
{
if (pass == 1)
{
//SecondPass
if (maxCharSeqLen <= m_MinAllowedLyricsLen)
return FALSE;
curChar = maxFirstSeqChar;
bInTag = FALSE;
}
while (*curChar != 0)
{
if (maxLastSeqChar <= curChar && pass == 1)
{
page = ansi;
return TRUE;
}
switch (*curChar)
{
case '<':
//ASSERT(bInTag == FALSE);
bInTag = TRUE;
if (_tcsnicmp(curChar, _T("<br"), 3) == 0 && curCharSeqLen > 0)
{
bBRHasBeenFound = TRUE;
curCharSeqLen+=2;
if (pass == 1)
ansi += _T("\r\n");
//strcat(ansi, "\r\n");
}
else
{
//Finished...
if (curCharSeqLen > maxCharSeqLen)
{
maxCharSeqLen = curCharSeqLen;
maxFirstSeqChar = curFirstSeqChar;
maxLastSeqChar = curChar;
}
curCharSeqLen = 0;
bBRHasBeenFound = FALSE;
}
break;
case '>':
//ASSERT(bInTag == TRUE);
bInTag = FALSE;
break;
case 10:
if (!bBRHasBeenFound && curCharSeqLen > 0)//This is a lonesome LF. He can t be here if it was CRLF (look 13)
{
curCharSeqLen+=2;
if (pass==1)
ansi += _T("\r\n");
//strcat(ansi, "\r\n");
}
break;
case 13:
if (!bBRHasBeenFound && curCharSeqLen > 0)
{
curCharSeqLen+=2;
if (pass==1)
ansi += _T("\r\n");
if(*curChar == 10)//Handle the case that you get CR without LF following
curChar++;
}
break;
default:
if (bInTag == FALSE)
{
if (curCharSeqLen == 0)
curFirstSeqChar = curChar;
if (pass == 1)
ansi += *curChar;
curCharSeqLen++;
}
}
curChar++;
}
}
return NULL;
}
示例4: SetToxAvatar
bool CToxProto::SetToxAvatar(std::tstring path, bool checkHash)
{
int length;
uint8_t *data;
FILE *hFile = _tfopen(path.c_str(), L"rb");
if (!hFile)
{
debugLogA("CToxProto::SetMyAvatar: failed to open avatar file");
return false;
}
fseek(hFile, 0, SEEK_END);
length = ftell(hFile);
rewind(hFile);
if (length > TOX_AVATAR_MAX_DATA_LENGTH)
{
fclose(hFile);
debugLogA("CToxProto::SetMyAvatar: new avatar size is excessive");
return false;
}
data = (uint8_t*)mir_alloc(length);
size_t readed = fread(data, sizeof(uint8_t), length, hFile);
if (readed != length)
{
fclose(hFile);
debugLogA("CToxProto::SetMyAvatar: failed to read avatar file");
return false;
}
fclose(hFile);
DBVARIANT dbv;
uint8_t hash[TOX_HASH_LENGTH];
tox_hash(hash, data, TOX_HASH_LENGTH);
if (checkHash && !db_get(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv))
{
if (memcmp(hash, dbv.pbVal, TOX_HASH_LENGTH) == 0)
{
db_free(&dbv);
mir_free(data);
debugLogA("CToxProto::SetMyAvatar: new avatar is same with old");
return false;
}
db_free(&dbv);
}
if (tox_set_avatar(tox, TOX_AVATAR_FORMAT_PNG, data, length) == TOX_ERROR)
{
mir_free(data);
debugLogA("CToxProto::SetMyAvatar: failed to set new avatar");
return false;
}
mir_free(data);
if (checkHash)
{
db_set_blob(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, (void*)hash, TOX_HASH_LENGTH);
}
return true;
}
示例5: AddFileToZip
bool ZipWrapper::AddFileToZip(const std::tstring& sFilename)
{
return m_zipArchive.AddNewFile(sFilename.c_str());
}
示例6: DelMediaPath
void MyLib::DelMediaPath(std::tstring &path)
{
m_pFileMonitor->DelDirectory(path.c_str());
mediaPaths.erase( find(mediaPaths.begin(),mediaPaths.end(),path) );
}
示例7: switch
//.........这里部分代码省略.........
case PSN_HELP:
OnHelp( hwndDlg, IDD_PROP_PLUGIN );
return TRUE;
case PSN_KILLACTIVE:
/* ダイアログデータの取得 Plugin */
GetData( hwndDlg );
return TRUE;
case PSN_SETACTIVE:
m_nPageNum = ID_PROPCOM_PAGENUM_PLUGIN;
return TRUE;
}
break;
}
break;
case WM_COMMAND:
wNotifyCode = HIWORD(wParam); /* 通知コード */
wID = LOWORD(wParam); /* 項目ID、 コントロールID、 またはアクセラレータID */
switch( wNotifyCode ) {
/* ボタン/チェックボックスがクリックされた */
case BN_CLICKED:
switch( wID ) {
case IDC_PLUGIN_SearchNew: // 新規プラグインを追加
GetData( hwndDlg );
CPluginManager::getInstance()->SearchNewPlugin( m_Common, hwndDlg );
if( m_bTrayProc ) {
LoadPluginTemp(m_Common, *m_pcMenuDrawer);
}
SetData_LIST( hwndDlg ); //リストの再構築
break;
case IDC_PLUGIN_INST_ZIP: // ZIPプラグインを追加
{
static std::tstring sTrgDir;
CDlgOpenFile cDlgOpenFile;
TCHAR szPath[_MAX_PATH + 1];
_tcscpy( szPath, (sTrgDir.empty() ? CPluginManager::getInstance()->GetBaseDir().c_str() : sTrgDir.c_str()));
// ファイルオープンダイアログの初期化
cDlgOpenFile.Create(
G_AppInstance(),
hwndDlg,
_T("*.zip"),
szPath
);
if( cDlgOpenFile.DoModal_GetOpenFileName( szPath ) ) {
GetData( hwndDlg );
CPluginManager::getInstance()->InstZipPlugin( m_Common, hwndDlg, szPath );
if( m_bTrayProc ) {
LoadPluginTemp(m_Common, *m_pcMenuDrawer);
}
SetData_LIST( hwndDlg ); //リストの再構築
}
// フォルダを記憶
TCHAR szFolder[_MAX_PATH + 1];
TCHAR szFname[_MAX_PATH + 1];
SplitPath_FolderAndFile(szPath, szFolder, szFname);
sTrgDir = szFolder;
}
break;
case IDC_CHECK_PluginEnable: // プラグインを有効にする
EnablePluginPropInput( hwndDlg );
break;
case IDC_PLUGIN_Remove: // プラグインを削除
{
HWND hListView = ::GetDlgItem( hwndDlg, IDC_PLUGINLIST );
int sel = ListView_GetNextItem( hListView, -1, LVNI_SELECTED );
示例8: Convert
//TODO: Another plea for a solid string class
std::wstring Convert(const std::tstring& s)
{
USES_CONVERSION;
return(T2W(const_cast<TCHAR*>(s.c_str())));
}
示例9: TransferDataPost
int CPostData::TransferDataPost()
{
CUrlCrack url;
if (!url.Crack(m_strUrl.c_str()))
return ERR_URLCRACKERROR;
m_hInetSession = ::InternetOpen(MONEYHUB_USERAGENT, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (m_hInetSession == NULL)
return ERR_NETWORKERROR;
//DWORD dwTimeOut = 60000;
InternetSetOptionEx(m_hInetSession, INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT, &m_dwTimeOut, sizeof(DWORD), 0);
InternetSetOptionEx(m_hInetSession, INTERNET_OPTION_CONTROL_SEND_TIMEOUT, &m_dwTimeOut, sizeof(DWORD), 0);
InternetSetOptionEx(m_hInetSession, INTERNET_OPTION_SEND_TIMEOUT, &m_dwTimeOut, sizeof(DWORD), 0);
InternetSetOptionEx(m_hInetSession, INTERNET_OPTION_RECEIVE_TIMEOUT, &m_dwTimeOut, sizeof(DWORD), 0);
InternetSetOptionEx(m_hInetSession, INTERNET_OPTION_CONNECT_TIMEOUT, &m_dwTimeOut, sizeof(DWORD), 0);
m_hInetConnection = ::InternetConnect(m_hInetSession, url.GetHostName(), url.GetPort(), NULL, NULL, INTERNET_SERVICE_HTTP, 0, (DWORD)this);
if (m_hInetConnection == NULL)
{
CloseHandles();
return ERR_NETWORKERROR;
}
LPCTSTR ppszAcceptTypes[2];
ppszAcceptTypes[0] = _T("*/*");
ppszAcceptTypes[1] = NULL;
DWORD dwFlags = 0;
if(INTERNET_DEFAULT_HTTPS_PORT == url.GetPort())
{
dwFlags = INTERNET_FLAG_SECURE;
}
else if(INTERNET_DEFAULT_HTTP_PORT == url.GetPort())
{
dwFlags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_KEEP_CONNECTION ;
}
m_hInetFile = HttpOpenRequest(m_hInetConnection, _T("POST"), url.GetPath(), NULL, NULL, ppszAcceptTypes, dwFlags, (DWORD)this);
if (m_hInetFile == NULL)
{
CloseHandles();
return ERR_NETWORKERROR;
}
if(INTERNET_DEFAULT_HTTPS_PORT == url.GetPort())
{
DWORD dwOptionFlags;
DWORD dwBuffLen = sizeof(dwOptionFlags);
InternetQueryOption (m_hInetFile, INTERNET_OPTION_SECURITY_FLAGS,
(LPVOID)&dwOptionFlags, &dwBuffLen);
dwOptionFlags |= (SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
InternetSetOption (m_hInetFile, INTERNET_OPTION_SECURITY_FLAGS,
&dwOptionFlags, sizeof (dwOptionFlags) );
}
HttpAddRequestHeaders(m_hInetFile, _T("Content-Type: application/x-www-form-urlencoded\r\n"), -1, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE);
HttpAddRequestHeaders(m_hInetFile, _T("User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E)\r\n"), -1, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE);
TCHAR szHeaders[1024];
_stprintf_s(szHeaders, _countof(szHeaders), _T("Moneyhubuid: %s\r\n"), m_strHWID.c_str());
HttpAddRequestHeaders(m_hInetFile, szHeaders, -1, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE);
BOOL bSend = ::HttpSendRequest(m_hInetFile, NULL, 0, m_lpPostData, m_dwPostDataLength);
if (!bSend)
{
CloseHandles();
return ERR_NETWORKERROR;
}
CloseHandles();
return ERR_SUCCESS;
}
示例10: TBigDataPost
int CPostData::TBigDataPost()
{
//CString sTraceBuffer;
CUrlCrack url;
if (!url.Crack(m_strUrl.c_str()))
return ERR_URLCRACKERROR;
m_hInetSession = ::InternetOpen(MONEYHUB_USERAGENT, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (m_hInetSession == NULL)
return ERR_NETWORKERROR;
DWORD dwTimeOut = 10000;
InternetSetOptionEx(m_hInetSession, INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT, &dwTimeOut, sizeof(DWORD), 0);
InternetSetOptionEx(m_hInetSession, INTERNET_OPTION_CONTROL_SEND_TIMEOUT, &dwTimeOut, sizeof(DWORD), 0);
InternetSetOptionEx(m_hInetSession, INTERNET_OPTION_SEND_TIMEOUT, &dwTimeOut, sizeof(DWORD), 0);
InternetSetOptionEx(m_hInetSession, INTERNET_OPTION_RECEIVE_TIMEOUT, &dwTimeOut, 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, (DWORD)this);
if (m_hInetConnection == NULL)
{
CRecordProgram::GetInstance()->RecordWarnInfo(MY_PRO_NAME, MY_COMMON_ERROR, L"HttpSendRequestEx");
CloseHandles();
return ERR_NETWORKERROR;
}
LPCTSTR ppszAcceptTypes[2];
ppszAcceptTypes[0] = _T("*/*");
ppszAcceptTypes[1] = NULL;
DWORD dwFlags = 0;
if( url.GetPort() == 443 )
{
dwFlags = INTERNET_FLAG_SECURE;
//dwFlags = INTERNET_FLAG_NO_CACHE_WRITE |
// INTERNET_FLAG_KEEP_CONNECTION |
// INTERNET_FLAG_PRAGMA_NOCACHE |
// INTERNET_FLAG_SECURE |
// INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
// INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |
// SECURITY_FLAG_IGNORE_UNKNOWN_CA |
// INTERNET_OPTION_SECURITY_FLAGS;
}
else if( url.GetPort() == 80 )
{
//for HTTP
//dwFlags = INTERNET_FLAG_NO_CACHE_WRITE |
// INTERNET_FLAG_KEEP_CONNECTION |
// INTERNET_FLAG_PRAGMA_NOCACHE ;
dwFlags = INTERNET_FLAG_RELOAD |
INTERNET_FLAG_KEEP_CONNECTION |
INTERNET_FLAG_DONT_CACHE ;
}
//m_hInetFile = HttpOpenRequest(m_hInetConnection, _T("POST"), url.GetPath(), NULL, NULL, ppszAcceptTypes, dwFlags, (DWORD)this);
m_hInetFile = HttpOpenRequest(m_hInetConnection, _T("POST"), url.GetPath(), NULL, NULL, ppszAcceptTypes, dwFlags, (DWORD)this);
if (m_hInetFile == NULL)
{
CRecordProgram::GetInstance()->RecordWarnInfo(MY_PRO_NAME, MY_COMMON_ERROR, L"HttpSendRequestEx m_hInetFile");
CloseHandles();
return ERR_NETWORKERROR;
}
//if( url.GetPort() == 443 )
{
DWORD dwBuffLen = sizeof(dwFlags);
InternetQueryOption (m_hInetFile, INTERNET_OPTION_SECURITY_FLAGS,
(LPVOID)&dwFlags, &dwBuffLen);
dwFlags |= (SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
InternetSetOption (m_hInetFile, INTERNET_OPTION_SECURITY_FLAGS,
&dwFlags, sizeof (dwFlags) );
}
HttpAddRequestHeaders(m_hInetFile, _T("Content-Type: application/x-www-form-urlencoded\r\n"), -1, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE);
HttpAddRequestHeaders(m_hInetFile, _T("User-Agent: Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E)\r\n"), -1, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE);
HttpAddRequestHeaders(m_hInetFile, _T("Accept-Language: zh-CN"), -1, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE);
return ERR_SUCCESS;
}