Esempio n. 1
0
//
// SetFileName
//
// Implemented for IFileSinkFilter support
//
STDMETHODIMP CDump::SetFileName(LPCOLESTR pszFileName,const AM_MEDIA_TYPE *pmt)
{
    // Is this a valid filename supplied

    CheckPointer(pszFileName,E_POINTER);
    if(wcslen(pszFileName) > MAX_PATH)
        return ERROR_FILENAME_EXCED_RANGE;

    // Take a copy of the filename

    size_t len = 1+lstrlenW(pszFileName);
    m_pFileName = new WCHAR[len];
    if (m_pFileName == 0)
        return E_OUTOFMEMORY;

    HRESULT hr = StringCchCopyW(m_pFileName, len, pszFileName);

    // Clear the global 'write error' flag that would be set
    // if we had encountered a problem writing the previous dump file.
    // (eg. running out of disk space).
    m_fWriteError = FALSE;

    // Create the file then close it

    hr = OpenFile();
    CloseFile();

    return hr;

} // SetFileName
Esempio n. 2
0
DWORD GetFormattedErrorMessage(__out PWSTR * pwszErrorMessage, DWORD dwMessageId, va_list* arguments)
{
    DWORD dwLength = 0;
    LPWSTR wszSystemErrorMessage = NULL;

    do
    {
        if (NULL == pwszErrorMessage)
        {
            break;
        }
        *pwszErrorMessage = NULL;

        if (NULL == g_hResourceInstance)
        {
#ifdef CORECLR
            g_hResourceInstance = LoadLibraryEx(g_MAIN_BINARY_NAME, 0, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE);
#else
            g_hResourceInstance = LoadMUILibraryW(g_MAIN_BINARY_NAME, MUI_LANGUAGE_NAME, 0);
#endif
        }

        dwLength = FormatMessageW(
            FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER,
            g_hResourceInstance,
            dwMessageId,
            0,
            (LPWSTR)&wszSystemErrorMessage,
            0,
            arguments);

        if (dwLength == 0)
        {
            break;
        }

        *pwszErrorMessage = new WCHAR[dwLength + 1];
        if (*pwszErrorMessage == NULL)
        {
            dwLength = 0;
            break;
        }

        if (FAILED(StringCchCopyW(*pwszErrorMessage, dwLength + 1, wszSystemErrorMessage)))
        {
            dwLength = 0;
            delete [] (*pwszErrorMessage);
            *pwszErrorMessage = NULL;
        }

    }while(false);

    if (NULL != wszSystemErrorMessage)
    {
        LocalFree(wszSystemErrorMessage);
    }

    return dwLength;
}
int __cdecl 
fwprintfEntry( 
	FILE *stream,
	const wchar_t *format,
	...
	)
{
	PDBG_OUTPUTW Filter;
	PBTR_FILTER_RECORD Record;
	BTR_PROBE_CONTEXT Context;
	FWPRINTF Routine;
	size_t Length;
	ULONG UserLength;
	va_list argptr;
	PULONG_PTR Sp;
	ULONG Result;
	WCHAR buffer[512];
	
	BtrFltGetContext(&Context);
	Routine = Context.Destine;

	//
	// N.B. Maximum support 16 arguments
	//

	Sp = (PULONG_PTR)&format + 1;
	Result = (*Routine)(stream, format, Sp[0], Sp[1], Sp[2], Sp[3], Sp[4],
			   Sp[5], Sp[6], Sp[7], Sp[8], Sp[9], 
			   Sp[10], Sp[11], Sp[12], Sp[13]);

	BtrFltSetContext(&Context);

	__try {

		va_start(argptr, format);
		StringCchVPrintfW(buffer, 512, format, argptr);
		Length = wcslen(buffer) + 1;
		va_end(argptr);

		UserLength = FIELD_OFFSET(DBG_OUTPUTW, Text[Length]);
		Record = BtrFltAllocateRecord(UserLength, DbgUuid, _fwprintf);
		if (!Record) {
			return Result;
		}

		Filter = FILTER_RECORD_POINTER(Record, DBG_OUTPUTW);
		Filter->Length = Length;
		StringCchCopyW(Filter->Text, Length, buffer);

		BtrFltQueueRecord(Record);
	}
	__except (EXCEPTION_EXECUTE_HANDLER) {
		if (Record) {
			BtrFltFreeRecord(Record);
		}		
	}

	return Result;
}
HRESULT OnRender(HDC hdc, const RECT &rcPaint)
{
    WCHAR wzText[512];

    FillRect(hdc, &rcPaint, (HBRUSH)GetStockObject(WHITE_BRUSH));

    StringCchCopyW(wzText, ARRAYSIZE(wzText), L"Source: ");

    switch(g_inputSource.deviceType)
    {
        case IMDT_UNAVAILABLE:
            StringCchCatW(wzText, ARRAYSIZE(wzText), L"Unavailable\n");
            break;

        case IMDT_KEYBOARD:
            StringCchCatW(wzText, ARRAYSIZE(wzText), L"Keyboard\n");
            break;

        case IMDT_MOUSE:
            StringCchCatW(wzText, ARRAYSIZE(wzText), L"Mouse\n");
            break;

        case IMDT_TOUCH:
            StringCchCatW(wzText, ARRAYSIZE(wzText), L"Touch\n");
            break;

        case IMDT_PEN:
            StringCchCatW(wzText, ARRAYSIZE(wzText), L"Pen\n");
            break;

    }

    StringCchCatW(wzText, ARRAYSIZE(wzText), L"Origin: ");

    switch(g_inputSource.originId)
    {
        case IMO_UNAVAILABLE:
            StringCchCatW(wzText, ARRAYSIZE(wzText), L"Unavailable\n");
            break;

        case IMO_HARDWARE:
            StringCchCatW(wzText, ARRAYSIZE(wzText), L"Hardware\n");
            break;

        case IMO_INJECTED:
            StringCchCatW(wzText, ARRAYSIZE(wzText), L"Injected\n");
            break;

        case IMO_SYSTEM:
            StringCchCatW(wzText, ARRAYSIZE(wzText), L"System\n");
            break;
    }

    DrawText(hdc, wzText, (int)wcslen(wzText), (LPRECT)&rcPaint, DT_TOP | DT_LEFT);

    return S_OK;
}
//-----------------------------------------------------------------------------------
// CImpICommandText::GetCommandText 
//
// @mfunc Echos the current command as text, including all post-processing 
//		  operations added.
//
// @rdesc HResult
//		@flag S_OK 					| Method Succeeded
//		@flag DB_S_DIALECTIGNORED	| Method succeeded, but dialect ignored
//		@flag E_INVALIDARG			| ppwszCommand was a null pointer
//		@flag E_OUTOFMEMORY			| Out of Memory
//
STDMETHODIMP CImpICommandText::GetCommandText
	(								 
	GUID		*pguidDialect,	//@parm INOUT | Guid denoting the dialect of sql
	LPOLESTR	*ppwszCommand	//@parm OUT   | Pointer for the command text
	)
{
	HRESULT		hr;

	// Check Function Arguments
	if( ppwszCommand == NULL )
	{
		hr = ResultFromScode(E_INVALIDARG);
		goto exit;
	}

	*ppwszCommand = NULL;

	// If the command has not been set, make sure the buffer
	// contains an empty stringt to return to the consumer
	if( !m_pObj->IsCommandSet() )
	{
		hr = ResultFromScode(DB_E_NOCOMMAND);
		goto exit;
	}

	assert( m_pObj->m_strCmdText );

	hr = NOERROR;

	if(  pguidDialect != NULL && 
		*pguidDialect != DBGUID_DEFAULT &&
		*pguidDialect != DBGUID_SAMPLEDIALECT )
	{
		hr = DB_S_DIALECTIGNORED;
		*pguidDialect = DBGUID_DEFAULT;
	}

	// Allocate memory for the string we're going to return to the caller
	*ppwszCommand = (LPWSTR) PROVIDER_ALLOC(
					(wcslen(m_pObj->m_strCmdText) + 1) * sizeof(WCHAR));
	
	if( !(*ppwszCommand) )
	{
		hr = ResultFromScode(E_OUTOFMEMORY);
		goto exit;
	}
	
	// Copy our saved text into the newly allocated string
	StringCchCopyW(*ppwszCommand,wcslen(m_pObj->m_strCmdText) + 1,m_pObj->m_strCmdText);

exit:

	if( FAILED(hr) && pguidDialect )
		memset(pguidDialect, 0, sizeof(GUID));

	return hr;
}
PEVENT_TRACE_PROPERTIES
AllocateTraceProperties (
    _In_opt_ PWSTR LoggerName,
    _In_opt_ PWSTR LogFileName
    )
{
    PEVENT_TRACE_PROPERTIES TraceProperties = NULL;
    ULONG BufferSize;

    BufferSize = sizeof(EVENT_TRACE_PROPERTIES) + 
        (MAXIMUM_SESSION_NAME + MAX_PATH) * sizeof(WCHAR);

    TraceProperties = (PEVENT_TRACE_PROPERTIES)malloc(BufferSize);  
    if (TraceProperties == NULL) {
        wprintf(L"Unable to allocate %d bytes for properties structure.\n", BufferSize);
        goto Exit;
    }

    //
    // Set the session properties.
    //

    ZeroMemory(TraceProperties, BufferSize);
    TraceProperties->Wnode.BufferSize = BufferSize;
    TraceProperties->Wnode.Flags = WNODE_FLAG_TRACED_GUID;
    TraceProperties->LoggerNameOffset = sizeof(EVENT_TRACE_PROPERTIES);
    TraceProperties->LogFileNameOffset = sizeof(EVENT_TRACE_PROPERTIES) + 
        (MAXIMUM_SESSION_NAME * sizeof(WCHAR)); 

    if (LoggerName != NULL) {
        StringCchCopyW((LPWSTR)((PCHAR)TraceProperties + TraceProperties->LoggerNameOffset), 
                      MAXIMUM_SESSION_NAME,
                      LoggerName);
    }

    if (LogFileName != NULL) {
        StringCchCopyW((LPWSTR)((PCHAR)TraceProperties + TraceProperties->LogFileNameOffset), 
                      MAX_PATH, 
                      LogFileName);
    }

Exit:
    return TraceProperties;
}
Esempio n. 7
0
HRESULT CpiReadPropertyList(
	LPWSTR* ppwzData,
	CPI_PROPERTY** ppPropList
	)
{
	HRESULT hr = S_OK;

	CPI_PROPERTY* pItm = NULL;
	LPWSTR pwzName = NULL;

	// clear list if it already contains items
	if (*ppPropList)
		CpiFreePropertyList(*ppPropList);
	*ppPropList = NULL;

	// read property count
	int iPropCnt = 0;
	hr = WcaReadIntegerFromCaData(ppwzData, &iPropCnt);
	ExitOnFailure(hr, "Failed to read property count");

	for (int i = 0; i < iPropCnt; i++)
	{
		// allocate new element
		pItm = (CPI_PROPERTY*)::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CPI_PROPERTY));
		if (!pItm)
			ExitFunction1(hr = E_OUTOFMEMORY);

		// Name
		hr = WcaReadStringFromCaData(ppwzData, &pwzName);
		ExitOnFailure(hr, "Failed to read name");
		StringCchCopyW(pItm->wzName, countof(pItm->wzName), pwzName);

		// Value
		hr = WcaReadStringFromCaData(ppwzData, &pItm->pwzValue);
		ExitOnFailure(hr, "Failed to read property value");

		// add to list
		if (*ppPropList)
			pItm->pNext = *ppPropList;
		*ppPropList = pItm;
		pItm = NULL;
	}

	hr = S_OK;

LExit:
	// clean up
	ReleaseStr(pwzName);

	if (pItm)
		CpiFreePropertyList(pItm);

	return hr;
}
Esempio n. 8
0
wchar_t* lstrdup(const wchar_t* asText)
{
    int nLen = asText ? lstrlenW(asText) : 0;
    wchar_t* psz = (wchar_t*)malloc((nLen+1) * sizeof(*psz));

    if (nLen)
        StringCchCopyW(psz, nLen+1, asText);
    else
        psz[0] = 0;

    return psz;
}
Esempio n. 9
0
//============================================================================
// Set the process-wide behavior of Watson. Default is to prompt.
//============================================================================
void SetWatsonType(WATSON_TYPE WatsonType, LCID WatsonLcid, _In_opt_z_ WCHAR *wszAdditionalFiles)
{
    g_WatsonType = WatsonType;
    g_WatsonLcid = WatsonLcid;

    if (wszAdditionalFiles)
    {
        g_wszAdditionalFiles[0] = '\0';
        g_fAdditionalFiles = true;
        StringCchCopyW(g_wszAdditionalFiles, DIM(g_wszAdditionalFiles), wszAdditionalFiles);
    }
}
Esempio n. 10
0
/*
 * Allocate (duplicate) a wide char string.
 */
PWSTR MEMHEAP::AllocStr(PCWSTR str)
{
    if (str == NULL)
        return NULL;

    size_t str_len = wcslen(str) + 1;
    PWSTR strNew = (PWSTR) Alloc(str_len * sizeof(WCHAR));
    HRESULT hr;
    hr = StringCchCopyW(strNew, str_len, str);
    ASSERT (SUCCEEDED (hr));
    return strNew;
}
Esempio n. 11
0
//------------------------------------------------------------
//描述: 
void CCommonFunc::GetFileNoExt(wchar_t* strPathName, wchar_t* strName, int iNameLen)
{
	wchar_t strTempPathName[256] = L"\0";
	SafeWStringPrintf(strTempPathName, _countof(strTempPathName),  L"%s", strPathName);
	wchar_t* pChar = strTempPathName;
	while(*pChar != L'.')
	{
		pChar++;
	}
	*pChar = L'\0';
	StringCchCopyW(strName, iNameLen, strTempPathName);
}
Esempio n. 12
0
BOOL
GetEventCategory(IN LPCWSTR KeyName,
                 IN LPCWSTR SourceName,
                 IN EVENTLOGRECORD *pevlr,
                 OUT PWCHAR CategoryName)
{
    HANDLE hLibrary = NULL;
    WCHAR szMessageDLL[MAX_PATH];
    LPVOID lpMsgBuf = NULL;

    if (GetEventMessageFileDLL (KeyName, SourceName, EVENT_CATEGORY_MESSAGE_FILE , szMessageDLL))
    {
        hLibrary = LoadLibraryExW(szMessageDLL,
                                 NULL,
                                 DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
        if (hLibrary != NULL)
        {
            /* Retrieve the message string. */
            if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
                              hLibrary,
                              pevlr->EventCategory,
                              MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                              (LPWSTR)&lpMsgBuf,
                              EVENT_MESSAGE_FILE_BUFFER,
                              NULL) != 0)
            {
                /* Trim the string */
                TrimNulls(lpMsgBuf);

                /* Copy the category name */
                StringCchCopyW(CategoryName, MAX_PATH, lpMsgBuf);
            }
            else
            {
                LoadStringW(hInst, IDS_NONE, CategoryName, MAX_PATH);
            }

            if (hLibrary != NULL)
                FreeLibrary(hLibrary);

            /* Free the buffer allocated by FormatMessage */
            if (lpMsgBuf)
                LocalFree(lpMsgBuf);

            return TRUE;
        }
    }

    LoadStringW(hInst, IDS_NONE, CategoryName, MAX_PATH);

    return FALSE;
}
Esempio n. 13
0
void
HippoIcon::updateTip(const WCHAR *tip)
{
    NOTIFYICONDATA notifyIconData = { 0 };
    notifyIconData.uID = 0;
    notifyIconData.hWnd = window_;
    notifyIconData.uFlags = NIF_TIP;
    StringCchCopyW(notifyIconData.szTip, 
                   sizeof(notifyIconData.szTip) / sizeof(notifyIconData.szTip[0]),
                   tip);
    notifyIconData.szTip;
    Shell_NotifyIcon(NIM_MODIFY, &notifyIconData);
}
Esempio n. 14
0
IFACEMETHODIMP OCContextMenu::GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT *pwReserved, LPSTR pszName, UINT cchMax)
{
	HRESULT hr = E_INVALIDARG;

	if (idCmd == IDM_SHARE)
	{
		switch (uFlags)
		{
		case GCS_HELPTEXTW:
			hr = StringCchCopyW(reinterpret_cast<PWSTR>(pszName), cchMax, L"Shares file or directory with ownCloud");
			break;

		case GCS_VERBW:
			// GCS_VERBW is an optional feature that enables a caller
			// to discover the canonical name for the verb that is passed in
			// through idCommand.
			hr = StringCchCopyW(reinterpret_cast<PWSTR>(pszName), cchMax, L"ownCloudShare");
			break;
		}
	}
	return hr;
}
Esempio n. 15
0
wchar_t* lstrdup(const wchar_t* asText, size_t cchExtraSizeAdd /* = 0 */)
{
	size_t nLen = asText ? lstrlenW(asText) : 0;
	wchar_t* psz = (wchar_t*)malloc((nLen+1+cchExtraSizeAdd) * sizeof(*psz));

	if (nLen)
		StringCchCopyW(psz, nLen+1, asText);

	// Ensure AsciiZ
	psz[nLen] = 0;

	return psz;
}
Esempio n. 16
0
HRESULT WINAPI GetImmFileName(PWSTR lpBuffer, UINT uSize)
{
  UINT length;
  STRSAFE_LPWSTR Safe = lpBuffer;

  length = GetSystemDirectoryW(lpBuffer, uSize);
  if ( length && length < uSize )
  {
    StringCchCatW(Safe, uSize, L"\\");
    return StringCchCatW(Safe, uSize, L"imm32.dll");
  }
  return StringCchCopyW(Safe, uSize, L"imm32.dll");
}  
Esempio n. 17
0
HRESULT ScaWebAppExtensionsWrite(IMSAdminBase* piMetabase, LPCWSTR wzRootOfWeb,
                                 SCA_WEB_APPLICATION_EXTENSION* pswappextList
                                )
{
    HRESULT hr = S_OK;

    LPWSTR wzAppExt = NULL;
    DWORD cchAppExt;
    WCHAR wzAppExtension[1024];
    WCHAR wzAppExtensions[65536];
    SCA_WEB_APPLICATION_EXTENSION* pswappext = NULL;

    if (!pswappextList)
        ExitFunction();

    ::ZeroMemory(wzAppExtensions, sizeof(wzAppExtensions));
    wzAppExt = wzAppExtensions;
    cchAppExt = countof(wzAppExtensions);
    pswappext = pswappextList;

    while (pswappext)
    {
        if (0 == lstrcmpW(wzAppExtension, L"*"))
            StringCchPrintfW(wzAppExtension, countof(wzAppExtension), L"*,%s,%d", pswappext->wzExecutable, pswappext->iAttributes);
        else if (*pswappext->wzExtension)
            StringCchPrintfW(wzAppExtension, countof(wzAppExtension), L".%s,%s,%d", pswappext->wzExtension, pswappext->wzExecutable, pswappext->iAttributes);
        else   // blank means "*" (all)
            StringCchPrintfW(wzAppExtension, countof(wzAppExtension), L"*,%s,%d", pswappext->wzExecutable, pswappext->iAttributes);

        // if verbs were specified and not the keyword "all"
        if (pswappext->wzVerbs[0] && CSTR_EQUAL != CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pswappext->wzVerbs, -1, L"all", -1))
        {
            StringCchCatW(wzAppExtension, countof(wzAppExtension), L",");
            StringCchCatW(wzAppExtension, countof(wzAppExtension), pswappext->wzVerbs);
        }

        StringCchCopyW(wzAppExt, cchAppExt, wzAppExtension);
        wzAppExt += lstrlenW(wzAppExtension) + 1;
        cchAppExt -= lstrlenW(wzAppExtension) + 1;
        pswappext = pswappext->pswappextNext;
    }

    if (*wzAppExtensions)
    {
        hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_SCRIPT_MAPS, METADATA_INHERIT, IIS_MD_UT_FILE, MULTISZ_METADATA, wzAppExtensions);
        ExitOnFailure1(hr, "Failed to write AppExtension: '%S'", wzAppExtension);
    }

LExit:
    return hr;
}
Esempio n. 18
0
/**************************************************************************
*        CNetFolder::BindToObject
*/
HRESULT WINAPI CNetFolder::BindToObject(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
{
#ifdef HACKY_UNC_PATHS
    /* Create the target folder info */
    PERSIST_FOLDER_TARGET_INFO pfti = {0};
    pfti.dwAttributes = -1;
    pfti.csidl = -1;
    StringCchCopyW(pfti.szTargetParsingName, MAX_PATH, (WCHAR*)pidl->mkid.abID);

    return SHELL32_BindToSF(pidlRoot, &pfti, pidl, &CLSID_ShellFSFolder, riid, ppvOut);
#else
    return E_NOTIMPL;
#endif
}
Esempio n. 19
0
static HKEY GetKeyW(LPCWSTR appname, BOOL * closekey, BOOL fCreate) {

    HKEY key = 0;
    WCHAR achName[MAX_PATH];
#if !MMPROFILECACHE
    *closekey = TRUE;
#else
    UINT n;
    ATOM atm;

    *closekey = FALSE;
    //
    // See if we have already used this key
    //
    atm = FindAtomW(appname);

    if (atm != 0) {
	// Atom exists... search the table for it.
        for (n=0; n<keyscached; ++n) {
            if (akeyatoms[n] == atm) {
                DPF2(("(W)Found existing key for %ls\n", appname));
                return ahkey[n];
            }
        }
    }
    DPF2(("(W)No key found for %ls\n", appname));
#endif

    StringCchCopyW(achName, MAX_PATH, KEYNAME );
    StrCchCatW(achName, MAX_PATH, appname);

    if ((!fCreate && RegOpenKeyW(ROOTKEY, achName, &key) == ERROR_SUCCESS)
        || (fCreate && RegCreateKeyW(ROOTKEY, achName, &key) == ERROR_SUCCESS)) {
#if MMPROFILECACHE
        if (keyscached < KEYSCACHED
	  && (atm = AddAtomW(appname))) {
            // Add this key to the cache array
            akeyatoms[keyscached] = atm;
            ahkey[keyscached] = key;
            DPF1(("Adding key %ls to cache array in position %d\n", appname, keyscached));
            ++keyscached;
        } else {
            DPF2(("Not adding key to cache array\n"));
            *closekey = TRUE;
        }
#endif
    }

    return(key);
}
bool ConsoleArgs::GetFullFileName(LPCWSTR szSource, const WCBuffer filenameBuffer, bool fOutputFilename)
{
    if (0 == GetCanonFilePath( szSource, filenameBuffer, fOutputFilename)) {
        if (filenameBuffer[0] == L'\0') {
            // This could easily fail because of an overflow, but that's OK
            // we only want what will fit in the output buffer so we can print
            // a good error message
            StringCchCopyW(filenameBuffer.GetData(), filenameBuffer.Count() - 4, szSource);
            // Don't cat on the ..., only stick it in the last 4 characters
            // to indicate truncation (if the string is short than this it just won't print)
            StringCchCopyW(filenameBuffer.GetData() + filenameBuffer.Count() - 4, 4, L"...");
        }
        if (GetLastError() == ERROR_FILE_EXISTS) {
            ASSERT(fOutputFilename);
            m_output->ShowErrorIdString(FTL_OutputFileExists, ERROR_FATAL, filenameBuffer.Str());
        }
        else {
            m_output->ShowErrorIdString(FTL_InputFileNameTooLong, ERROR_FATAL, filenameBuffer.Str());
        }
        return false;
    }
    return true;
}
Esempio n. 21
0
bool  CCommonFunc::SearchFile(wchar_t* strDir, wchar_t* strExt,FileNameSet& Set)
{
	Set.iItemNum = 0;
	WIN32_FIND_DATA FindFileData;
	//int iFileNum = 0;
	HANDLE hFind;
	wchar_t strSearchPath[256];
	SafeWStringPrintf(strSearchPath,  _countof(strSearchPath), L"%s\\*.*", strDir); 
	hFind = ::FindFirstFileW(strSearchPath,(LPWIN32_FIND_DATAW)&FindFileData);
    wchar_t strUppExt[20];
	wcscpy_s(strUppExt,_countof(strUppExt), strExt);
	_wcsupr_s(strUppExt, _countof(strUppExt));
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			if((FindFileData.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
			{
				size_t iLength = wcslen((wchar_t*)FindFileData.cFileName);

				//wsprintfW(Set.Items[Set.iItemNum], FindFileData.cFileName);
				StringCchCopyW(Set.Items[Set.iItemNum], _countof(Set.Items[Set.iItemNum]), FindFileData.cFileName);
				if(iLength > 1)
				{
					int lastLen = 0;
					wchar_t* pEndChar = (wchar_t*)FindFileData.cFileName + iLength;
					while(*pEndChar != L'.')
					{
						pEndChar--;
						lastLen++;
					}
					pEndChar++;
					_wcsupr_s(pEndChar, lastLen);
					 if(wcscmp(pEndChar, strUppExt) == 0)
					{
						Set.iItemNum++;
						if(Set.iItemNum >= Set.MAX_ITEM_NUM)
						{
							break;
						}
					}
				}
			}
		}
		while(FindNextFile(hFind, &FindFileData));
		FindClose(hFind);
	}

	return (Set.iItemNum != 0);
}
Esempio n. 22
0
STDMETHODIMP
CEapCfg::Initialize(
    LPCOLESTR   pwszMachineName,
    DWORD       dwEapTypeId,
    ULONG_PTR*  puConnectionParam
)
{
    DWORD       cch;
    WCHAR*      pwsz    = NULL;
    DWORD       dwErr   = NO_ERROR;

    *puConnectionParam = NULL;

    //
    // Save machine name as connection param.
    //

    //
    // How many chars are there in the name?
    //
    if ( NULL == pwszMachineName )
    {
        dwErr = ERROR_INVALID_PARAMETER;
        goto LDone;
    }
    cch = wcslen(pwszMachineName);

    pwsz = (WCHAR*) LocalAlloc(LPTR, (cch + 1) * sizeof(WCHAR));

    if (NULL == pwsz)
    {
        dwErr = GetLastError();
        goto LDone;
    }

    //
    // Copy machine name
    //

    StringCchCopyW(pwsz, cch+1,pwszMachineName);
    *puConnectionParam = (ULONG_PTR)pwsz;
    pwsz = NULL;

LDone:

    LocalFree(pwsz);

    return(HRESULT_FROM_WIN32(dwErr));
}
// Function returns S_OK and *ppszValue = NULL if retrieved string property is
//  actually a NULL variant
HRESULT WpcuWmiStringFromInstance(IWbemClassObject* piInstance, PCWSTR pcszProperty, 
                                  PWSTR* ppszValue)
{
    HRESULT hr = E_INVALIDARG;
    if (piInstance && pcszProperty && ppszValue)
    {
        *ppszValue = NULL;
        VARIANT var;
        VariantInit(&var);
        hr = piInstance->Get(pcszProperty, 0, &var, NULL, NULL);
        if (SUCCEEDED(hr))
        {
            // Only allow BSTR and NULL states
            if (var.vt != VT_BSTR)
            {  
                if (var.vt != VT_NULL)
                {
                    hr = E_FAIL;
                }
				else
				{
					hr = S_OK;
				}
            }
            else
            {
                size_t cch;
                hr = StringCchLengthW(var.bstrVal, STRSAFE_MAX_CCH, &cch);
                if (SUCCEEDED(hr))
                {
					// Allocate with null terminator
					*ppszValue = new WCHAR[++cch];
					if (!(*ppszValue))
					{
						hr = E_OUTOFMEMORY;
					}
					else
					{
						hr = StringCchCopyW(*ppszValue, cch, var.bstrVal);
					}
                }
            }
        }
        VariantClear(&var);
    }

    return hr;
}
Esempio n. 24
0
inline HRESULT StringCchCatW(
  LPWSTR  pszDest,
  size_t  cchDest,
  LPCWSTR pszSrc)
{
  HRESULT hr = S_OK;
  if(cchDest==0||pszDest==nullptr)
    return STRSAFE_E_INVALID_PARAMETER;
  size_t lengthDest;
  if(StringCchLengthW(pszDest,cchDest,&lengthDest)!=S_OK){
    hr=STRSAFE_E_INVALID_PARAMETER;
  }else{
    hr=StringCchCopyW(pszDest+lengthDest,cchDest-lengthDest,pszSrc);
  }
  return hr;
}
Esempio n. 25
0
STDMETHODIMP
BaseFilter::QueryFilterInfo(FILTER_INFO* aInfo)
{
  if (!aInfo)
    return E_POINTER;

  if (!mName.empty()) {
    StringCchCopyW(aInfo->achName, NUMELMS(aInfo->achName), mName.data());
  } else {
    aInfo->achName[0] = L'\0';
  }
  aInfo->pGraph = mGraph;
  NS_IF_ADDREF(mGraph);

  return S_OK;
}
HRESULT ContentStudioProperties::GetStringW(LPCSTR id, LPWSTR pvalue, size_t cch)
{
    HRESULT hr = S_OK;
    _variant_t v;
    _bstr_t bstr;

    hr = Get(id, v);
    if (SUCCEEDED(hr))
    {
        bstr = v;
        std::wstring s = stde::to_wstring(bstr);
        hr = StringCchCopyW(pvalue, cch, s.c_str());
    }

    return hr;
}
Esempio n. 27
0
HRESULT GetGUIDNameNew(const GUID& guid, WCHAR **ppwsz)
{
    HRESULT hr = S_OK;
    WCHAR *pName = NULL;

    LPCWSTR pcwsz = GetGUIDNameConstNew(guid);
    if (pcwsz)
    {
        size_t cchLength = 0;

        hr = StringCchLengthW(pcwsz, STRSAFE_MAX_CCH, &cchLength);
        if (FAILED(hr))
        {
            goto done;
        }

        pName = (WCHAR*)CoTaskMemAlloc((cchLength + 1) * sizeof(WCHAR));

        if (pName == NULL)
        {
            hr = E_OUTOFMEMORY;
            goto done;
        }

        hr = StringCchCopyW(pName, cchLength + 1, pcwsz);
        if (FAILED(hr))
        {
            goto done;
        }
    }
    else
    {
        hr = StringFromCLSID(guid, &pName);
    }

done:
    if (FAILED(hr))
    {
        *ppwsz = NULL;
        CoTaskMemFree(pName);
    }
    else
    {
        *ppwsz = pName;
    }
    return hr;
}
Esempio n. 28
0
//----------------------------------------------------------------------------
std::wstring FormatReader::StringFromGUID( const GUID& aGuid )
{
    HRESULT hr = S_OK;
    WCHAR *pName = NULL;

    LPCWSTR pcwsz = GetGUIDNameConstNew(aGuid);
    if (pcwsz)
    {
        size_t cchLength = 0;

        hr = StringCchLengthW(pcwsz, STRSAFE_MAX_CCH, &cchLength);
        if (FAILED(hr))
        {
            goto done;
        }

        pName = (WCHAR*)CoTaskMemAlloc((cchLength + 1) * sizeof(WCHAR));

        if (pName == NULL)
        {
            hr = E_OUTOFMEMORY;
            goto done;
        }

        hr = StringCchCopyW(pName, cchLength + 1, pcwsz);
        if (FAILED(hr))
        {
            goto done;
        }
    }
    else
    {
        hr = StringFromCLSID(aGuid, &pName);
    }

done:
    std::wstring result;
    if (FAILED(hr))
    {
        CoTaskMemFree(pName);
    }
    else
    {
        result = std::wstring(pName);
    }
    return result;
}
static void set_buffer(LPWSTR *buffer, LPCWSTR string)
{
    static const WCHAR empty_string[] = {0};
    ULONG len;

    if (string == NULL)
        string = empty_string;
    len = (wcslen(string) + 1)*sizeof(WCHAR);

    LPWSTR tmp = (LPWSTR) heap_realloc(*buffer, len);
    if (tmp)
        *buffer = tmp;
    else
        len = wcslen(*buffer) + 1;

    StringCchCopyW(*buffer, len, string);
}
Esempio n. 30
0
//------------------------------------------------------------
//描述: 
void CCommonFunc::GetFileExt(wchar_t* strPathName, wchar_t* strExt, size_t iStrExtLen)
{
	wchar_t strTempPathName[256] = L"\0";
	SafeWStringPrintf(strTempPathName, _countof(strTempPathName),  L"%s", strPathName);
	//wsprintfW(strTempPathName, L"%s", strPathName);
	wchar_t* pChar = strTempPathName;
	while(*pChar != L'\0')
	{
		pChar++;
	}
    while(*pChar != L'.')
	{
		pChar--;
	}
	pChar++;
	StringCchCopyW(strExt, iStrExtLen, pChar);
}