⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.cpp

📁 The following file describes how to use the Bluetooth Headset Audio Gateway.
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//

#include "utils.h"


//==============================================================================

// Name        : OutputMessage
// Description : Outputs to the console or the debug output port
// Parameters  : Variable Number
// Returns     : integer 

//================================================================================

int OutputMessage (TCHAR *pFormat, ...) 
{
    va_list ArgList;
    TCHAR Buffer[2000];
    int RetVal;

    va_start (ArgList, pFormat);
    RetVal = wvsprintf (Buffer, pFormat, ArgList);
    OutputDebugString(Buffer);

    return RetVal; 
}


int GetBA (WCHAR **pp, BT_ADDR *pba) 
{
    while (**pp == ' ')
        ++*pp;

    for (int i = 0 ; i < 4 ; ++i, ++*pp) {
        if (! iswxdigit (**pp))
            return FALSE;

        int c = **pp;
        if (c >= 'a')
            c = c - 'a' + 0xa;
        else if (c >= 'A')
            c = c - 'A' + 0xa;
        else c = c - '0';

        if ((c < 0) || (c > 16))
            return FALSE;

        *pba = *pba * 16 + c;
    }

    for (i = 0 ; i < 8 ; ++i, ++*pp) {
        if (! iswxdigit (**pp))
            return FALSE;

        int c = **pp;
        if (c >= 'a')
            c = c - 'a' + 0xa;
        else if (c >= 'A')
            c = c - 'A' + 0xa;
        else c = c - '0';

        if ((c < 0) || (c > 16))
            return FALSE;

        *pba = *pba * 16 + c;
    }

    if ((**pp != ' ') && (**pp != '\0'))
        return FALSE;

    return TRUE;
}

#define BPR     8


void DumpBuff (WCHAR *szLineHeader, unsigned char *lpBuffer, unsigned int cBuffer) 
{
    WCHAR szLine[5 + 7 + 2 + 4 * BPR];

    for (int i = 0 ; i < (int)cBuffer ; i += BPR) {
        int bpr = cBuffer - i;
        if (bpr > BPR)
            bpr = BPR;

        wsprintf (szLine, L"%04x ", i);
        WCHAR *p = szLine + wcslen (szLine);

        for (int j = 0 ; j < bpr ; ++j) {
            WCHAR c = (lpBuffer[i + j] >> 4) & 0xf;
            if (c > 9) c += L'a' - 10; else c += L'0';
            *p++ = c;
            c = lpBuffer[i + j] & 0xf;
            if (c > 9) c += L'a' - 10; else c += L'0';
            *p++ = c;
            *p++ = L' ';
        }

        for ( ; j < BPR ; ++j) {
            *p++ = L' ';
            *p++ = L' ';
            *p++ = L' ';
        }

        *p++ = L' ';
        *p++ = L' ';
        *p++ = L' ';
        *p++ = L'|';
        *p++ = L' ';
        *p++ = L' ';
        *p++ = L' ';

        for (j = 0 ; j < bpr ; ++j) {
            WCHAR c = lpBuffer[i + j];
            if ((c < L' ') || (c >= 127))
                c = L'.';

            *p++ = c;
        }

        for ( ; j < BPR ; ++j) {
            *p++ = L' ';
        }

        *p++ = L'\n';
        *p++ = L'\0';

        OutputMessage (L"%s %s", szLineHeader ? szLineHeader : L"", szLine);
    }
}

__int64 GetFileTimeMilliseconds()
{
    SYSTEMTIME st;
    FILETIME ft;
    GetLocalTime (&st);
    SystemTimeToFileTime (&st, &ft);
    return *(__int64*)&ft / 10000;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -