/************************************************************************** * CaptureAndConvertAnsiArg [SETUPAPI.@] * * Captures an ANSI string and converts it to a UNICODE string. * * PARAMS * lpSrc [I] ANSI string to be captured * lpDst [O] Pointer to the captured UNICODE string * * RETURNS * Success: ERROR_SUCCESS * Failure: ERROR_INVALID_PARAMETER * * NOTE * Call MyFree to release the captured UNICODE string. */ DWORD WINAPI CaptureAndConvertAnsiArg(LPCSTR pSrc, LPWSTR *pDst) { if (pDst == NULL) return ERROR_INVALID_PARAMETER; *pDst = MultiByteToUnicode(pSrc, CP_ACP); return ERROR_SUCCESS; }
/*********************************************************************** * SetupDecompressOrCopyFileA (SETUPAPI.@) * * See SetupDecompressOrCopyFileW. */ DWORD WINAPI SetupDecompressOrCopyFileA( PCSTR source, PCSTR target, PUINT type ) { DWORD ret = FALSE; WCHAR *sourceW = NULL, *targetW = NULL; if (source && !(sourceW = MultiByteToUnicode( source, CP_ACP ))) return FALSE; if (target && !(targetW = MultiByteToUnicode( target, CP_ACP ))) { MyFree( sourceW ); return ERROR_NOT_ENOUGH_MEMORY; } ret = SetupDecompressOrCopyFileW( sourceW, targetW, type ); MyFree( sourceW ); MyFree( targetW ); return ret; }
PWSTR CopyStr2Unicode( PWSTR pwstr, PSTR pstr, INT maxlen ) /*++ Routine Description: Convert an ANSI string to a UNICODE string. Arguments: pwstr Pointer to buffer for holding Unicode string pstr Pointer to ANSI string maxlen Maximum number of Unicode characters to copy If maxlen is 0 or negative, then there is no limit Return Value: Return a pointer to the destination string. --*/ { INT len = strlen(pstr) + 1; if (maxlen <= 0) maxlen = len; MultiByteToUnicode(pwstr, maxlen*sizeof(WCHAR), NULL, pstr, len); // // Make sure the Unicode string is null-terminated // pwstr[maxlen-1] = NUL; return pwstr; }
/*********************************************************************** * SetupGetFileCompressionInfoExA (SETUPAPI.@) * * See SetupGetFileCompressionInfoExW. */ BOOL WINAPI SetupGetFileCompressionInfoExA( PCSTR source, PSTR name, DWORD len, PDWORD required, PDWORD source_size, PDWORD target_size, PUINT type ) { BOOL ret; WCHAR *nameW = NULL, *sourceW = NULL; DWORD nb_chars = 0; LPSTR nameA; TRACE("%s, %p, %d, %p, %p, %p, %p\n", debugstr_a(source), name, len, required, source_size, target_size, type); if (!source || !(sourceW = MultiByteToUnicode( source, CP_ACP ))) return FALSE; if (name) { ret = SetupGetFileCompressionInfoExW( sourceW, NULL, 0, &nb_chars, NULL, NULL, NULL ); if (!(nameW = HeapAlloc( GetProcessHeap(), 0, nb_chars * sizeof(WCHAR) ))) { MyFree( sourceW ); return FALSE; } } ret = SetupGetFileCompressionInfoExW( sourceW, nameW, nb_chars, &nb_chars, source_size, target_size, type ); if (ret) { if ((nameA = UnicodeToMultiByte( nameW, CP_ACP ))) { if (name && len >= nb_chars) lstrcpyA( name, nameA ); else { SetLastError( ERROR_INSUFFICIENT_BUFFER ); ret = FALSE; } MyFree( nameA ); } } if (required) *required = nb_chars; HeapFree( GetProcessHeap(), 0, nameW ); MyFree( sourceW ); return ret; }
std::wstring a2w(LPCSTR arg, size_t length) { return MultiByteToUnicode(arg, length, CP_ACP); }
std::wstring utf82w(LPCSTR arg, size_t length) { return MultiByteToUnicode(arg, length, CP_UTF8); }