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

📄 errhndlr.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
//
//-----------------------------------------------------------------------------
#if !defined(UNDER_CE) || defined(DESKTOP_BUILD)
DWORD WINAPI W95FormatMsg
    (
    DWORD	dwFlags,		// source and processing options
    LPCVOID	lpSource,		// pointer to message source
    DWORD	dwMessageId,	// requested message identifier
    DWORD	dwLanguageId,	// language identifier for requested message
    LPWSTR	lpBuffer,		// pointer to message buffer
    DWORD	nSize,			// maximum size of message buffer
    va_list	*Arguments		// address of array of message inserts
    )
    {
#ifdef _WIN64
    //
    // This should only get called on Win9x, which is not 64 bit
    //
    ASSERT(FALSE);
    return 0;
#else

    WCHAR	rgwchFmt[20];
    WCHAR	*pwchTmp;
    char	*pchMsg;
    char	*pchTmp;
    char	*pchSave;
    int		cChars;
    DWORD	rdwArgs[99+2];	// Arguments
    DWORD	cArgs;
    DWORD	nArg;
    int		cStars;
    UINT	cp;

    nSize --;	// For terminating zero
    rgwchFmt[0] = '%';

    // Use system ANSI codepage.
    cp = CP_ACP;

    // If necessary, allocate buffer for message
    if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER)
    	{
    	nSize = ONEK;
    	pwchTmp = (WCHAR *) LocalAlloc (LMEM_FIXED, nSize * sizeof(WCHAR));
    	* (WCHAR**) lpBuffer = pwchTmp;
    	lpBuffer = pwchTmp;
    	if (!lpBuffer)
    	    return 0;
    	}

    // Allocate temporary buffer
    pchMsg = (char*) _alloca (nSize*2 + 1);	// Can be 2-bytes sequences

    // Get message
    if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)
    {
    	cChars = LoadStringA((HINSTANCE)lpSource, dwMessageId, pchMsg, nSize);
    }
    else
    {
    	cChars = FormatMessageA(dwFlags | FORMAT_MESSAGE_IGNORE_INSERTS,
    						lpSource,
    						dwMessageId,
    						dwLanguageId,
    						pchMsg,
    						nSize,
    						NULL);
    	pchMsg[cChars] = 0;
    }

    // If there is no need to format it, return immediatelly
    if ((0 == cChars) || (Arguments == NULL) || (dwFlags & FORMAT_MESSAGE_IGNORE_INSERTS))
    	{
    	cChars = CwchMultiByteToWideChar(cp, pchMsg, -1, lpBuffer, nSize);
    	ASSERT (cChars <= (int) nSize);
    	if (cChars >= (int) nSize)
    		cChars = nSize-1;
    	lpBuffer[cChars] = 0;
    	return cChars;
    	}

    // Ok, we have to format it.
    for (cArgs = 0, pwchTmp = lpBuffer, pchTmp = pchSave = pchMsg; nSize && * pchTmp; pchTmp ++)
    	{
    	if ('%' == *pchTmp)
    		{
    		// Write the previous portion of the string
    		if (pchTmp != pchSave)
    			{
    			*pchTmp = 0;
    			cChars = CwchMultiByteToWideChar(cp, pchSave, -1, pwchTmp, nSize);
    			pwchTmp += cChars;
    			nSize -= cChars;
    			if (0 == nSize)
    				break;
    			}
    		pchTmp ++;
    		// Check for special sequences
    		if ('n' == * pchTmp)
    			{
    			* pwchTmp ++ = L'\n';
    			nSize --;
    			}
    		else if ('0' == * pchTmp)
    			{
    			* pwchTmp ++ = 0;
    			nSize --;
    			}
    		// Is it argument? If so, handle it
    		else if (FIsAsciiDigit (* pchTmp))
    			{
    			// First, get arg #
    			nArg = (* pchTmp) - '0';
    			pchTmp ++;
    			if (FIsAsciiDigit (* pchTmp))
    				{
    				nArg = nArg * 10 + (* pchTmp) - '0';
    				pchTmp ++;
    				}
    			cStars = 0;
    			// Get format specifier, if any
    			if ('!' == * pchTmp)
    				{
    				pchSave = ++ pchTmp;
    				while ('!' != * pchTmp)
    					{
    					if ('*' == * pchTmp)
    						cStars ++;
    					pchTmp ++;
    					}
    				* pchTmp = 0;

    				MultiByteToWideChar(cp, 0, pchSave, -1, rgwchFmt+1, sizeof(rgwchFmt)/sizeof(WCHAR));
    				}
    			else
    				{
    				rgwchFmt[1] = L's';
    				rgwchFmt[2] = 0;
    				pchTmp --;
    				}
    			// Copy arguments to local array
    			while (cArgs < nArg + cStars)
    				{
    				rdwArgs [cArgs] = (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY) ?
    									((DWORD*) Arguments)[cArgs] :
    									va_arg (* Arguments, DWORD);
    				cArgs ++;
    				}
    			// Now print that argument. Pass 3 parameters, as there can be 2 stars
    			cChars = _snwprintf (pwchTmp, nSize, rgwchFmt, rdwArgs[nArg-1], rdwArgs[nArg], rdwArgs[nArg+1]);
    			if (0 > cChars)
    				cChars = nSize;
    			pwchTmp += cChars;
    			nSize -= cChars;
    			}
    		else
    			pchTmp --;
    		pchSave = pchTmp + 1;
    		}
    	}
    // Write last portion of the string
    if (nSize && pchTmp != pchSave)
    	{
    	cChars = CwchMultiByteToWideChar(cp, pchSave, -1, pwchTmp, nSize);
    	pwchTmp += cChars;
    	nSize -= cChars;
    	}
    * pwchTmp = 0;
    return pwchTmp - lpBuffer;
#endif
    }
#endif

#if !defined(UNDER_CE) || defined(DESKTOP_BUILD)
//-----------------------------------------------------------------------------
// FormatMsg -- Version of FormatMessage that works on all platforms
//-----------------------------------------------------------------------------
DWORD WINAPI FormatMsg
    (
    DWORD    dwFlags,        // source and processing options
    LPCVOID    lpSource,        // pointer to message source
    DWORD    dwMessageId,    // requested message identifier
    DWORD    dwLanguageId,    // language identifier for requested message
    LPWSTR    lpBuffer,        // pointer to message buffer
    DWORD    nSize,            // maximum size of message buffer
    va_list    *Arguments        // address of array of message inserts
    )
{
    WCHAR    *pwchMsg;
    int        cChars;
    if (g_fIsWin9x)
    {
        return W95FormatMsg(dwFlags,
                    lpSource,
                    dwMessageId,
                    dwLanguageId,
                    lpBuffer,
                    nSize,
                    Arguments);
    }

    // Otherwise we use the os version of FormatMessage 
    // Allocate temporary buffer

    // Get message
    if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)
    {
        __try {
           pwchMsg = (WCHAR*) _alloca (nSize*2 + 1);  
        } 
        __except(1)
        {
            //an error occured with _alloca (out of mem)
            return 0;   
        }
        cChars = LoadStringW((HINSTANCE)lpSource, dwMessageId, pwchMsg, nSize);
		dwFlags = (dwFlags & ~FORMAT_MESSAGE_FROM_HMODULE) | FORMAT_MESSAGE_FROM_STRING;
    }
    else
    {
        pwchMsg = (WCHAR *)lpSource;
    }

    return FormatMessage(dwFlags,
                    pwchMsg,
                    dwMessageId,
                    dwLanguageId,
                    lpBuffer,
                    nSize,
                    Arguments);
}
#endif 




//-----------------------------------------------------------------------------
// ForwardToBackslash -- Converts all forward slashes to back slashes in a string
//-----------------------------------------------------------------------------
void ForwardToBackslash(char *pstr)
{

    if(pstr)
    {
        while (*pstr)
        {
            if (*pstr == '/')
                *pstr = '\\';
            pstr++;
        }
    }    

}


void ForwardToBackslashW(WCHAR *pwstr)
{
    if(pwstr)
    {
        while (*pwstr)
        {
            if (*pwstr == '/')
                *pwstr = '\\';
            pwstr++;
        }
    }    
}


⌨️ 快捷键说明

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