void CCalc::OnEnChangeEdit2() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialogEx::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. CString szRVA; wchar_t *endPoint; CEdit* edit_value = (CEdit*)this->GetDlgItem(IDC_EDIT2); if (!edit_value->IsWindowEnabled()) { return; } edit_value->GetWindowTextW(szRVA); ULONGLONG ullRVA = wcstol(szRVA, &endPoint, 16); if (ullRVA == 0) { return; } ULONGLONG ullOffset = RVA2Offset(ullRVA, lpFileImage, dwSize); ULONGLONG ullVA = rVA2VA(ullRVA, lpFileImage, dwSize); wchar_t szOffset[MAX_PATH] = { 0 }; wchar_t szVA[MAX_PATH] = { 0 }; _ui64tow_s(ullOffset, szOffset, MAX_PATH, 16); _ui64tow_s(ullVA, szVA, MAX_PATH, 16); this->SetDlgItemTextW(IDC_EDIT1, szVA); this->SetDlgItemTextW(IDC_EDIT3, szOffset); // TODO: Add your control notification handler code here }
VOID ConditionGetValue( IN PCONDITION_ENTRY Entry, OUT PWCHAR Buffer, IN ULONG Length ) { switch (Entry->Type) { case ConditionDataUlong: _ultow_s(Entry->UlongValue, Buffer, Length, 16); break; case ConditionDataUlong64: _ui64tow_s(Entry->UlongValue, Buffer, Length, 16); break; // // N.B. double is encoded as string // case ConditionDataDouble: case ConditionDataString: StringCchCopy(Buffer, Length, Entry->StringValue); break; default: StringCchCopy(Buffer, Length, Entry->StringValue); } }
wstring format_data_size(unsigned __int64 value, const wchar_t* suffixes[5]) { unsigned f = 0; unsigned __int64 div = 1; while ((value / div >= 1000) && (f < 4)) { f++; div *= 1024; } unsigned __int64 v1 = value / div; unsigned __int64 mul; if (v1 < 10) mul = 100; else if (v1 < 100) mul = 10; else mul = 1; unsigned __int64 v2 = value % div; unsigned __int64 d = v2 * mul * 10 / div % 10; v2 = v2 * mul / div; if (d >= 5) { if (v2 + 1 == mul) { v2 = 0; if ((v1 == 999) && (f < 4)) { v1 = 0; v2 = 98; f += 1; } else v1 += 1; } else v2 += 1; } wstring result; wchar_t buf[30]; _ui64tow_s(v1, buf, ARRAYSIZE(buf), 10); result += buf; if (v2 != 0) { result += L'.'; if ((v1 < 10) && (v2 < 10)) result += L'0'; _ui64tow_s(v2, buf, ARRAYSIZE(buf), 10); result += buf; } if (*suffixes[f]) { result += L' '; result += suffixes[f]; } return result; }
JavascriptString* JavascriptTypedNumber<unsigned __int64>::ToString(Var value, ScriptContext* scriptContext) { char16 szBuffer[30]; unsigned __int64 val = JavascriptUInt64Number::FromVar(value)->GetValue(); errno_t err = _ui64tow_s(val, szBuffer, 30, 10); AssertMsg(err == 0, "convert int64 to string failed"); return JavascriptString::NewCopySz(szBuffer, scriptContext); }
// Output formatting for numbers ("#,##0"). const std::tstring format_number(const unsigned long long size) { if (size == 0) { return _T(""); } std::tstring text(128, '\0'); _ui64tow_s(size, &*text.begin(), text.size() - 1, 10); text.resize(text.find(_T('\0'))); return text; }
//----------------------------------------------------------------------------- void MGStrOp::toString( U64 src,std::wstring& dest ) { Char16 buff[21] = {0}; _ui64tow_s(src,buff,20,10); dest = buff; }
//------------------------------------------------------------------------------ // Name: PrintAttribute() // Desc: Display the specified attribute. //------------------------------------------------------------------------------ HRESULT PrintAttribute( WORD wIndex, WORD wStream, __in LPWSTR wszName, WMT_ATTR_DATATYPE AttribDataType, WORD wLangID, BYTE * pbValue, DWORD dwValueLen ) { WCHAR pwszValue[256]; WCHAR wszNum[256]; ZeroMemory( pwszValue, sizeof( pwszValue ) ); ZeroMemory( wszNum, sizeof( wszNum ) ); // // Make the data type string // WCHAR * pwszType = L"Unknown"; WCHAR * pTypes[] = { L"DWORD", L"STRING", L"BINARY", L"BOOL", L"QWORD", L"WORD", L"GUID" }; if( ( sizeof( pTypes ) / sizeof( pTypes[0] ) ) > AttribDataType ) { pwszType = pTypes[AttribDataType]; } // // The attribute value. // switch ( AttribDataType ) { // // string // case WMT_TYPE_STRING: if( 0 == dwValueLen ) { StringCbCatW( pwszValue, sizeof( pwszValue ), L"***** NULL *****" ); } else { if( 0xFEFF == *(WCHAR*)pbValue ) { StringCbCatW( pwszValue, sizeof( pwszValue ), L"UTF-16LE BOM+" ); StringCbCatW( pwszValue, sizeof( pwszValue ), L"\"" ); if( 4 <= dwValueLen ) { StringCbCatW( pwszValue, sizeof( pwszValue ), (WCHAR *)pbValue + 1 ); } StringCbCatW( pwszValue, sizeof( pwszValue ), L"\"" ); } else if( 0xFFFE == *(WCHAR*)pbValue ) { StringCbCatW( pwszValue, sizeof( pwszValue ), L"UTF-16BE BOM+" ); StringCbCatW( pwszValue, sizeof( pwszValue ), L"\"" ); if( 4 <= dwValueLen ) { StringCbCatW( pwszValue, sizeof( pwszValue ), (WCHAR *)pbValue + 1 ); } StringCbCatW( pwszValue, sizeof( pwszValue ), L"\"" ); } else { StringCbCatW( pwszValue, sizeof( pwszValue ), L"\"" ); if( 2 <= dwValueLen ) { StringCbCatW( pwszValue, sizeof( pwszValue ), (WCHAR *)pbValue ); } StringCbCatW( pwszValue, sizeof( pwszValue ), L"\"" ); } } break; // // Binary // case WMT_TYPE_BINARY: StringCbCatW( pwszValue, sizeof( pwszValue ), L"[" ); _itow_s( dwValueLen, wszNum, 10 ); StringCbCatW( pwszValue, sizeof( pwszValue ), wszNum ); StringCbCatW( pwszValue, sizeof( pwszValue ), L" bytes]" ); break; // // Boolean // case WMT_TYPE_BOOL: if( *( (BOOL* )pbValue ) == FALSE ) { StringCbCatW( pwszValue, sizeof( pwszValue ), L"False" ); } else { StringCbCatW( pwszValue, sizeof( pwszValue ), L"True" ); } break; // // DWORD // case WMT_TYPE_DWORD: StringCbPrintfW( wszNum, sizeof(wszNum), L"%ld, 0x%08lx", ( (DWORD *)pbValue )[0], ( (DWORD *)pbValue )[0] ); StringCbCatW( pwszValue, sizeof( pwszValue ), wszNum ); break; // // QWORD // case WMT_TYPE_QWORD: _ui64tow_s( *( (QWORD* )pbValue ), wszNum, sizeof(wszNum) / sizeof(wszNum[0]), 10 ); StringCbCatW( pwszValue, sizeof( pwszValue ), wszNum ); StringCbPrintfW( wszNum, sizeof( wszNum ), L", 0x%08lx%08lx", ( (DWORD *)pbValue )[1], ( (DWORD *)pbValue )[0] ); StringCbCatW( pwszValue, sizeof( pwszValue ), wszNum ); break; // // WORD // case WMT_TYPE_WORD: StringCbPrintfW( wszNum, sizeof( wszNum ), L"%d, 0x%04x", ( ( WORD* )pbValue )[0], ( ( WORD* )pbValue )[0] ); StringCbCatW( pwszValue, sizeof( pwszValue ), wszNum ); break; // // GUID // case WMT_TYPE_GUID: if( !StringFromGUID2( *(GUID *)pbValue, pwszValue, 256 ) ) { StringCbCatW( pwszValue, sizeof( pwszValue ), L"ERROR" ); } break; default: StringCbPrintfW( pwszValue, sizeof( pwszValue ), L"Bad data type (%hu): value not displayed", AttribDataType ); break; } // // Dump the string to the screen. // _tprintf( _T( "* %3u %-25ls %3hu %3hu %7ls %ls\n" ), wIndex, wszName, wStream, wLangID, pwszType, pwszValue ); return( S_OK ); }