示例#1
0
PSTR
CopyUnicode2Str(
    PSTR    pstr,
    PWSTR   pwstr,
    INT     maxlen
    )

/*++

Routine Description:

    Convert a Unicde string to an ANSI string.

Arguments:

    pstr    Pointer to buffer for holding ANSI string
    pwstr   Pointer to Unicode string
    maxlen  Maximum number of ANSI 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 = wcslen(pwstr) + 1;
    
    if (maxlen <= 0)
        maxlen = len;

    UnicodeToMultiByte(pstr, maxlen, NULL, pwstr, len*sizeof(WCHAR));

    //
    // Make sure the ANSI string is null-terminated
    //

    pstr[maxlen-1] = NUL;

    return pstr;
}
示例#2
0
/***********************************************************************
 *      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;
}
示例#3
0
文件: NIconv.cpp 项目: 3rdexp/nui
 std::string w2a(LPCWSTR arg, size_t length)
 {
     return UnicodeToMultiByte(arg, length, CP_ACP);
 }
示例#4
0
文件: pnpapi.c 项目: shuowen/OpenNT
BOOL
GetCurrentHwProfileA (
    OUT LPHW_PROFILE_INFOA  lpHwProfileInfo
)

/*++

Routine Description:


Arguments:

    lpHwProfileInfo  Points to a HW_PROFILE_INFO structure that will receive
                     the information for the current hardware profile.

Return Value:

    If the function succeeds, the return value is TRUE.  If the function
    fails, the return value is FALSE.  To get extended error information,
    call GetLastError.

--*/

{
    BOOL              Status = TRUE;
    HW_PROFILE_INFOW  HwProfileInfoW;
    LPSTR             pAnsiString;


    try {
        //
        // validate parameter
        //
        if (lpHwProfileInfo == NULL) {
            SetLastError(ERROR_INVALID_PARAMETER);
            Status = FALSE;
            goto Clean0;
        }

        //
        // call the Unicode version
        //
        if (!GetCurrentHwProfileW(&HwProfileInfoW)) {
            Status = FALSE;
            goto Clean0;
        }

        //
        // on successful return, convert unicode form of struct
        // to ANSI and copy struct members to callers struct
        //
        lpHwProfileInfo->dwDockInfo = HwProfileInfoW.dwDockInfo;

        pAnsiString = UnicodeToMultiByte(
                          HwProfileInfoW.szHwProfileGuid, CP_ACP);
        lstrcpyA(lpHwProfileInfo->szHwProfileGuid, pAnsiString);
        LocalFree(pAnsiString);

        pAnsiString = UnicodeToMultiByte(
                          HwProfileInfoW.szHwProfileName, CP_ACP);
        lstrcpyA(lpHwProfileInfo->szHwProfileName, pAnsiString);
        LocalFree(pAnsiString);


Clean0:
        ;

    }
    except(EXCEPTION_EXECUTE_HANDLER) {
        SetLastError(ERROR_INTERNAL_ERROR);
        Status = FALSE;
    }

    return Status;

} // GetCurrentHwProfileA
示例#5
0
文件: NIconv.cpp 项目: 3rdexp/nui
 std::string w2utf8(LPCWSTR arg, size_t length)
 {
     return UnicodeToMultiByte(arg, length, CP_UTF8);
 }