Exemple #1
0
                    used to fill all of the destination buffer, and it will
                    be null terminated. This will overwrite any truncated 
                    string returned when the failure is
                    STRSAFE_E_INSUFFICIENT_BUFFER

        STRSAFE_NO_TRUNCATION /
        STRSAFE_NULL_ON_FAILURE
                    if the function fails, the destination buffer will be set
                    to the empty string. This will overwrite any truncated string
                    returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.


*/
///////////////////////////////////////////////////////////////////////////

int __cdecl BufPrintArgs(DWORD dwFlags, _Out_z_cap_(cchBuf) LPWSTR pwszBuf, size_t cchBuf, _In_z_ LPCWSTR pwszFormat, va_list argList)
{
    int nRet = 0;

    if (cchBuf <= STRSAFE_MAX_CCH)
    {
        WCHAR* pwszLast = NULL;
        size_t cchLeft = 0;
        HRESULT hr = StringCchVPrintfExW(
                                    pwszBuf,
                                    cchBuf,
                                    &pwszLast,   // LPCWSTR* pointer the pointer to the last character copied
                                    &cchLeft,        // size_t*  size left in the buffer after the copy
                                    dwFlags,
                                    pwszFormat, 
                                    argList);
#include <wininet.h>

#include "ietab.h"
#include "scriptableobject.h"

#define SET_VAR_BOOL(npvariant, val) { npvariant->type = NPVariantType_Bool; npvariant->value.boolValue = val; }
#define SET_VAR_INT32(npvariant, val) { npvariant->type = NPVariantType_Int32; npvariant->value.intValue = val; }

#define STRZ_OUT_TO_NPVARIANT(pszIn, npvar) { \
	int nLen = strlen(pszIn); \
	char *pszOut = (char *) NPN_MemAlloc(nLen+1); \
	strcpy_s(pszOut, nLen+1, pszIn); \
	STRINGZ_TO_NPVARIANT(pszOut, npvar); }


_Ret_opt_z_cap_(nChars) inline LPSTR WINAPI W2Utf8Helper(_Out_z_cap_(nChars) LPSTR lpa, _In_z_ LPCWSTR lpw, _In_ int nChars) throw()
{
	ATLASSERT(lpw != NULL);
	ATLASSERT(lpa != NULL);
	if (lpa == NULL || lpw == NULL)
		return NULL;
	// verify that no illegal character present
	// since lpa was allocated based on the size of lpw
	// don't worry about the number of chars
	*lpa = '\0';
	int ret = WideCharToMultiByte(CP_UTF8, 0, lpw, -1, lpa, nChars, NULL, NULL);
	if(ret == 0)
	{
		ATLASSERT(FALSE);
		return NULL;
	}
Exemple #3
0
	LPCTSTR lpszFileName /* = NULL */)
{
	if (lOsError != 0)
		AfxThrowFileException(CFileException::OsErrorToException(lOsError),
			lOsError, lpszFileName);
}

void PASCAL CFileException::ThrowErrno(int nErrno,
	LPCTSTR lpszFileName /* = NULL */)
{
	if (nErrno != 0)
		AfxThrowFileException(CFileException::ErrnoToException(nErrno),
			_doserrno, lpszFileName);
}

BOOL CFileException::GetErrorMessage(_Out_z_cap_(nMaxError) LPTSTR lpszError, _In_ UINT nMaxError,
		_Out_opt_ PUINT pnHelpContext) const
{
	ASSERT(lpszError != NULL && AfxIsValidString(lpszError, nMaxError));

	if (lpszError == NULL || nMaxError == 0)
	{
		return FALSE;
	}

	if (pnHelpContext != NULL)
		*pnHelpContext = m_cause + AFX_IDP_FILE_NONE;

	CString strMessage;
	CString strFileName = m_strFileName;
	if (strFileName.IsEmpty())
Exemple #4
0
//-------------------------------------------------------------------------------------------------

#include "StdAfx.h"

HINSTANCE g_hinstDll;

//---------------------------------------------------------------------------
// Cover for LoadString that loads from either the main DLL, or the
// international dll based on the resource ID value.
//---------------------------------------------------------------------------
// 


HRESULT ResLoadString(
    RESID resid,
    _Out_z_cap_(cchBuf)WCHAR * wszBuf,
    unsigned cchBuf)
{
    VB_ENTRY();

    // VS 523071
    // Exceptions should not escape this function (callers expect an HRESULT return value)
   wszBuf[0] = NULL;

    HINSTANCE hinst = FLOCALIZEDRESID(resid) ? Compiler::GetResourceDll() : g_hinstDll;

    int cchCopied = LoadString(hinst, resid, wszBuf, cchBuf);

    if (cchCopied == 0)
    {
        return GetLastHResultError();
Exemple #5
0
	UINT TinyMenu::GetMenuItemCount() const
	{
		ASSERT(::IsMenu(m_hMENU));
		return ::GetMenuItemCount(m_hMENU);
	}
	UINT TinyMenu::GetMenuItemID(INT nPos) const
	{
		ASSERT(::IsMenu(m_hMENU));
		return ::GetMenuItemID(m_hMENU, nPos);
	}
	UINT TinyMenu::GetMenuState(UINT nID, UINT nFlags) const
	{
		ASSERT(::IsMenu(m_hMENU));
		return ::GetMenuState(m_hMENU, nID, nFlags);
	}
	INT TinyMenu::GetMenuString(_In_ UINT nIDItem, _Out_z_cap_(nMaxCount) LPTSTR lpString, _In_ INT nMaxCount, _In_ UINT nFlags) const
	{
		ASSERT(::IsMenu(m_hMENU));
		return ::GetMenuString(m_hMENU, nIDItem, lpString, nMaxCount, nFlags);
	}
	BOOL TinyMenu::GetMenuItemInfo(UINT uItem, LPMENUITEMINFO lpMenuItemInfo, BOOL fByPos)
	{
		ASSERT(::IsMenu(m_hMENU));
		return ::GetMenuItemInfo(m_hMENU, uItem, fByPos, lpMenuItemInfo);
	}
	BOOL TinyMenu::SetMenuItemInfo(UINT uItem, LPMENUITEMINFO lpMenuItemInfo, BOOL fByPos)
	{
		ASSERT(::IsMenu(m_hMENU));
		return ::SetMenuItemInfo(m_hMENU, uItem, fByPos, lpMenuItemInfo);
	}
	BOOL TinyMenu::InsertMenu(UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem, LPCTSTR lpszNewItem)
Exemple #6
0
    }
    
    SafeStrCopy(wszSrc, cchSrc, wszDest, cchDest);
    _wcslwr_s((WCHAR*)wszDest, cchDest);
    return wcslen(wszDest);
}

inline int HexValue (WCHAR c)
{
    return (c >= '0' && c <= '9') ? c - '0' : (c & 0xdf) - 'A' + 10;
}

#ifndef PLATFORM_UNIX
//  Get canonical file path from a user specified path.  wszSrcfileName can include relative paths, etc.
//  Much of this function was taken from csc.exe.
DWORD GetCanonFilePath(_In_z_ LPCWSTR wszSrcFileName, _Out_z_cap_(cchDestFileName) LPWSTR wszDestFileName, _In_ DWORD cchDestFileName, _In_ bool fPreserveSrcCasing)
{
    DWORD full_len;
    WCHAR * full_path = new WCHAR[cchDestFileName]; // an intermediate buffer
    WCHAR * temp_path = new WCHAR[cchDestFileName]; // Used if FindFile fails
    WCHAR * full_cur;
    WCHAR * out_cur;
    WCHAR * out_end;
    bool hasDrive = false;

    memset(full_path, 0, cchDestFileName * sizeof(WCHAR));
    out_cur = wszDestFileName;
    out_end = out_cur + cchDestFileName;
    if (wszSrcFileName != wszDestFileName)
        *out_cur = L'\0';
    full_cur = full_path;