387 count = WideCharToMultiByte(CP_UTF8, 0, value, -1, NULL, 0, NULL, NULL); 388 389 if (count > 0) { 390 result.data = new char[count + 1]; 391 result.length = WideCharToMultiByte(CP_UTF8, 0, value, -1, 392 result.data, (int)count, NULL, NULL); 393 } 394 395 return result; 396 } 397 398 // Owner must free the return value. 399 WideString Platform::MultibyteStringToWideString(const char* value) { 400 WideString result; 401 size_t count = 0; 402 403 if (value == NULL) { 404 return result; 405 } 406 407 count = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, 408 value, -1, NULL, 0); 409 410 if (count > 0) { 411 result.data = new wchar_t[count]; 412 result.length = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, 413 value, -1, result.data, (int)count); 414 if (result.length == 0) { 415 delete[] result.data; 416 result.data = NULL; 417 } 418 } 419 420 return result; 421 } 422 423 FileHandle::FileHandle(std::wstring FileName) { 424 FHandle = ::CreateFile(FileName.data(), GENERIC_READ, FILE_SHARE_READ, 425 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 426 } 427 428 FileHandle::~FileHandle() { 429 if (IsValid() == true) { 430 ::CloseHandle(FHandle); 431 } 432 } | 387 count = WideCharToMultiByte(CP_UTF8, 0, value, -1, NULL, 0, NULL, NULL); 388 389 if (count > 0) { 390 result.data = new char[count + 1]; 391 result.length = WideCharToMultiByte(CP_UTF8, 0, value, -1, 392 result.data, (int)count, NULL, NULL); 393 } 394 395 return result; 396 } 397 398 // Owner must free the return value. 399 WideString Platform::MultibyteStringToWideString(const char* value) { 400 WideString result; 401 size_t count = 0; 402 403 if (value == NULL) { 404 return result; 405 } 406 407 count = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, 408 value, -1, NULL, 0); 409 410 if (count > 0) { 411 result.data = new wchar_t[count]; 412 result.length = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, 413 value, -1, result.data, (int)count); 414 if (result.length == 0) { 415 delete[] result.data; 416 result.data = NULL; 417 } 418 } 419 420 return result; 421 } 422 423 FileHandle::FileHandle(std::wstring FileName) { 424 FHandle = ::CreateFile(FileName.data(), GENERIC_READ, FILE_SHARE_READ, 425 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 426 } 427 428 FileHandle::~FileHandle() { 429 if (IsValid() == true) { 430 ::CloseHandle(FHandle); 431 } 432 } |