本文整理汇总了C++中CStr::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ CStr::GetLength方法的具体用法?C++ CStr::GetLength怎么用?C++ CStr::GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CStr
的用法示例。
在下文中一共展示了CStr::GetLength方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetVariable
BOOL SetVariable( CStr &varName, CValue value )
{
VarError.Empty();
int pos;
CValue *val;
if ( varName.GetLength() > 0 && varName.GetAt(0) == L'[' )
{
CStr expression = varName.Mid( 1 );
CInterpreter parser;
CValue result = parser.EvaluateExpression( expression, FALSE );
int subPos = parser.GetErrorPosition();
if ( parser.GetError() != 0 )
{
VarError = CStr( L"Error in variable reference: " ) + parser.GetErrorMessage();
return FALSE;
}
if ( expression[subPos] != L']' )
{
VarError = L"Variable reference not closed (missing ']')";
return FALSE;
}
val = GetVariable( (CStr)result, TRUE, &pos );
}
else{
val = GetVariable( varName, TRUE, &pos );
}
val->CopyFrom( value );
return (pos != -1);
}
示例2: InitInstance
BOOL CMortScriptApp::InitInstance()
{
SetRegistryKey( L"Mort" );
CParseCmdLine myCmdLine;
myCmdLine.ParseCmdLine( m_lpCmdLine );
TCHAR exe[MAX_PATH];
::GetModuleFileName(NULL,exe,MAX_PATH);
ExecuteFileName = exe;
CStr file = myCmdLine.Filename; // m_lpCmdLine;
// file.TrimLeft( '\"' ); file.TrimRight( '\"' );
if ( myCmdLine.RegOnly || file.IsEmpty() )
{
RegisterFileClass();
RegisterFileType( L".jscr", L"JScripts" );
RegisterFileType( L".mscr", L"JScripts" );
if ( !myCmdLine.RegOnly )
{
MessageBox( NULL
, L".jscr and .mscr extensions registered.\nPlease run any .jscr/.mscr file or read the manual.\n\n"
L"(c) Mirko Schenk 2005-2007"
, L"JScripts V" + CStr( VERSION_INFO )
, MB_OK|MB_SETFOREGROUND );
}
}
else
{
if ( file.GetLength() >= 4
/* file.GetLength() >= 8 && file.Right(8).CompareNoCase( L".mortrun" ) == 0
|| file.GetLength() >= 5 && file.Right(5).CompareNoCase( L".mscr" ) == 0 */
)
{
CStr mutexName = file;
mutexName.MakeLower();
#ifdef DESKTOP
// Windows XP doesn't like some path characters in the mutex' name
mutexName.Replace( ':', '_' );
mutexName.Replace( '\\', '/' );
#endif
MutexName = (LPCTSTR)mutexName;
HANDLE mutex = ::CreateMutex(NULL, FALSE, MutexName);
if ( mutex!=NULL )
{
int exists = ::GetLastError();
if ( exists == ERROR_ALREADY_EXISTS)
{
DWORD procId = GetRunningScriptProcId( file );
if ( procId != NULL )
{
/*
CString msg;
msg.Format( L"Process ID: %08x", procId );
MessageBox( NULL, msg, L"Debug", MB_SETFOREGROUND );
*/
FindAppT findApp;
findApp.procId = procId;
findApp.hWnd = NULL;
::EnumWindows( FindApplicationWindowProc, (LPARAM)&findApp );
if ( findApp.hWnd != NULL )
{
// msg.Format( L"Set foreground window: %08x", findApp.hWnd );
// MessageBox( NULL, msg, L"Debug", MB_SETFOREGROUND );
::SetForegroundWindow( findApp.hWnd );
}
}
else
exists = 0;
//MessageBox( NULL, L"Process opened", L"Debug", MB_SETFOREGROUND );
/*
TCHAR procName[256];
::GetModuleFileName((HMODULE)procId,procName,256);
//MessageBox( NULL, procName, L"Debug", MB_SETFOREGROUND );
if ( CString(procName).Right(14).CompareNoCase( L"MortScript.exe" ) == 0 )
{
int aw = MessageBox( NULL
, L"Script seems to be running. Cancel old script?"
, L"Script already running"
, MB_YESNO|MB_SETFOREGROUND
);
if ( aw == IDYES )
{
RegWriteDW( HKEY_CURRENT_USER, L"Software\\JScripts\\Abort", MutexName, 1 );
DWORD exitCode = 0;
SetCursor(LoadStandardCursor(IDC_WAIT));
for ( int i=0; i<=10; i++ )
{
Sleep(1000);
if ( GetExitCodeProcess( hProc, &exitCode ) == FALSE )
{
//MessageBox( NULL, L"GetExitCode failed", L"Debug", MB_SETFOREGROUND );
exitCode = 0;
//.........这里部分代码省略.........
示例3: CreateFile
BOOL
CIniFile::WriteFile( LPCTSTR filename, CStr &content, BOOL append, UINT cp )
{
HANDLE file;
char *buffer = NULL;
char *tmpStr = NULL;
ULONG iLen, feLen;
BOOL rc = TRUE, comPort = FALSE;
if ( filename[wcslen(filename)-1] == ':' )
{
file = CreateFile( filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
if ( file != INVALID_HANDLE_VALUE )
SetComPort( filename, file );
comPort = TRUE;
}
else
{
CStr fileWithPath;
fileWithPath = filename;
if ( CurrentInterpreter != NULL && ( fileWithPath.GetLength() < 2 || ( fileWithPath.GetAt(0) != '\\' && fileWithPath.GetAt(1) != ':' ) ) )
{
int len = CurrentInterpreter->ScriptFile.ReverseFind('\\');
if ( len == -1 )
fileWithPath = L"\\" + fileWithPath;
else
fileWithPath = CurrentInterpreter->ScriptFile.Left( len+1 ) + fileWithPath;
}
if ( append )
{
file = CreateFile( fileWithPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
if ( SetFilePointer( file, 0, NULL, FILE_END ) == 0 )
append = FALSE;
}
else
file = CreateFile( fileWithPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
}
if ( file == INVALID_HANDLE_VALUE ) rc = FALSE;
if ( rc == TRUE )
{
iLen = content.GetLength();
if ( cp != CP_UNICODE )
{
tmpStr = new char[iLen*2+1]; // special characters might use 2 bytes!
if ( tmpStr == NULL ) rc = FALSE;
}
else
tmpStr = NULL;
}
if ( rc == TRUE )
{
ULONG written;
int stat;
if ( cp != CP_UNICODE && cp != CP_UNICODE_PREFIX )
{
if ( cp == CP_UTF8_PREFIX )
{
if ( ! comPort && ! append )
::WriteFile( file, (void*)"\xEF\xBB\xBF", 3, &written, NULL ); // omit the \0!
cp = CP_UTF8;
}
feLen = WideCharToMultiByte( cp, 0, (LPCTSTR)content, -1, tmpStr, iLen*2+1, NULL, NULL );
if ( !comPort )
stat = ::WriteFile( file, (void*)tmpStr, feLen-1, &written, NULL ); // omit the \0!
else
{
stat = 1, written = 1;
for ( ULONG i=0; i<feLen-1 && stat != 0 && written == 1; i++ )
{
stat = ::WriteFile( file, (void*)&(tmpStr[i]), 1, &written, NULL ); // omit the \0!
}
}
}
else
{
if ( cp == CP_UNICODE_PREFIX )
{
if ( ! comPort && ! append )
::WriteFile( file, (void*)"\xFF\xFE", 2, &written, NULL ); // omit the \0!
}
stat = ::WriteFile( file, (void*)(LPCTSTR)content, (content.GetLength())*2, &written, NULL ); // omit the \0!
}
if ( stat == 0 ) rc = FALSE;
}
if ( file != NULL ) CloseHandle( file );
if ( buffer != NULL ) content.ReleaseBuffer();
if ( tmpStr != NULL ) delete[] tmpStr;
return rc;
}
示例4: CMapStrToString
void
CIniFile::Parse( LPCTSTR cont )
{
CStr content = cont;
CStr sectionName, key, value;
CMapStrToString *section = NULL;
BOOL hasEmptySection = FALSE;
Sections.RemoveAll();
while ( content.GetLength() > 0 )
{
CStr line;
int pos = content.Find( _T("\n") );
if ( pos != -1 )
{
line = content.Left( pos );
content = content.Mid( pos+1 );
}
else
{
line = content;
content = _T("");
}
line.TrimLeft(); line.TrimRight();
if ( line.GetLength() > 0 && line.GetAt(0) != '#' && line.GetAt(0) != ';' )
{
if ( line.GetAt(0) == '[' && line.Right(1) == L"]" )
{
sectionName = line.Mid( 1, line.GetLength()-2 );
sectionName.MakeLower();
section = new CMapStrToString();
Sections.SetAt( sectionName, section );
}
else
{
int eqPos = line.Find( '=' );
if ( eqPos != -1 )
{
key = line.Left( eqPos );
key.TrimLeft(); key.TrimRight();
value = line.Mid( eqPos+1 );
value.TrimLeft(); value.TrimRight();
if ( value.Left(1) == L"\"" && value.Right(1) == L"\"" )
{
value = value.Mid( 1, value.GetLength()-2 );
}
key.MakeLower();
if ( section == NULL && hasEmptySection == FALSE )
{
section = new CMapStrToString();
Sections.SetAt( L"", section );
hasEmptySection = TRUE;
}
section->SetAt( key, value );
}
}
}
}
}
示例5: if
int
CIniFile::ReadFile( LPCTSTR filename, CStr &content, int size, int cp )
{
HANDLE file = NULL;
char *buffer = NULL;
char *tmpStr = NULL;
ULONG fileSize, readSize;
ULONG bufSize;
BOOL rc = 0, com;
int timeout;
if ( wcsnicmp( filename, L"COM", 3 ) == 0 && filename[wcslen(filename)-1] == ':' )
{
file = CreateFile( filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
if ( file != INVALID_HANDLE_VALUE )
{
timeout = SetComPort( filename, file );
}
com = TRUE;
}
else
{
CStr fileWithPath;
fileWithPath = filename;
if ( CurrentInterpreter != NULL && ( fileWithPath.GetLength() < 2 || ( fileWithPath.GetAt(0) != '\\' && fileWithPath.GetAt(1) != ':' ) ) )
{
int len = CurrentInterpreter->ScriptFile.ReverseFind('\\');
if ( len == -1 )
fileWithPath = L"\\" + fileWithPath;
else
fileWithPath = CurrentInterpreter->ScriptFile.Left( len+1 ) + fileWithPath;
}
file = CreateFile( fileWithPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
com = FALSE;
}
if ( file == INVALID_HANDLE_VALUE )
{
int error = GetLastError();
rc = -2;
}
if ( rc == 0 )
{
if ( size <= 0 )
{
fileSize = GetFileSize( file, NULL );
}
else
{
fileSize = size;
}
if ( fileSize > 1024 * 1024 || fileSize == -1 )
{
// Too big
rc = -3;
}
}
if ( rc == 0 )
{
bufSize = (fileSize+1)*sizeof(TCHAR);
buffer = (char*)content.GetBufferSetLength( bufSize );
if ( buffer == NULL ) rc = -4;
}
if ( rc == 0 )
{
tmpStr = new char[fileSize+2]; // if it's unicode, two binary zeroes are required at the end
if ( tmpStr == NULL ) rc = -4;
}
if ( rc == 0 )
{
if ( ! com )
{
int stat = ::ReadFile( file, (void*)tmpStr, fileSize, &readSize, NULL );
if ( stat == 0 )
{
int error = GetLastError();
rc = -5;
}
}
else
{
comPort = &file;
comTargetSize = fileSize+1;
comTargetBuffer = tmpStr;
DWORD dwThreadID;
HANDLE readThread = CreateThread( NULL, 0, PortReadThread, 0, 0, &dwThreadID );
if ( readThread != NULL )
{
WaitForSingleObject( readThread, timeout );
TerminateThread( readThread, 0 );
CloseHandle( readThread );
SetCommMask( file, 0 );
readSize = comReadSize;
//.........这里部分代码省略.........