本文整理汇总了C++中StringCchPrintfW函数的典型用法代码示例。如果您正苦于以下问题:C++ StringCchPrintfW函数的具体用法?C++ StringCchPrintfW怎么用?C++ StringCchPrintfW使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringCchPrintfW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetFileName
HRESULT GetFileName(wchar_t *FileName, UINT FileNameSize, WCHAR* instanceName, SensorType senserID)
{
wchar_t DevIdOut[20];
HRESULT hr;
GetDevIdforFile(instanceName, DevIdOut);
// Get the time
wchar_t timeString[MAX_PATH];
wchar_t dateString[MAX_PATH];
GetTimeFormatEx(NULL, TIME_FORCE24HOURFORMAT, NULL, L"hh'-'mm'-'ss", timeString, _countof(timeString));
GetDateFormatEx(NULL, 0, NULL, L"yyyy'-'MMM'-'dd", dateString, _countof(dateString), NULL);
// File name will be DeviceConnectID-KinectAudio-HH-MM-SS.wav
switch (senserID)
{
case AudioSensor:
hr=StringCchPrintfW(FileName, FileNameSize, L"%s\\KinectAudio\\Audio-%s-%s-%s.wav", knownPath, DevIdOut, dateString, timeString);
break;
case RGBSensor:
hr=StringCchPrintfW(FileName, FileNameSize, L"%s\\KinectRGB\\RGB-%s-%s-%s.avi", knownPath, DevIdOut, dateString, timeString);
break;
case DepthSensor:
hr=StringCchPrintfW(FileName, FileNameSize, L"%s\\KinectDepth\\Depth-%s-%s-%s.avi", knownPath, DevIdOut, dateString, timeString);
break;
case SpeechRecog:
hr=StringCchPrintfW(FileName, FileNameSize, L"%s\\KinectSpeechRecog\\SpeechRecog-%s-%s-%s.txt", knownPath, DevIdOut, dateString, timeString);
break;
default:
break;
}
return hr;
}
示例2: ScaWebAppExtensionsWrite
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;
}
示例3: SvcReportEvent
//
// Purpose:
// Logs messages to the event log
//
// Parameters:
// szFunction - name of function that failed
//
// Return value:
// None
//
// Remarks:
// The service must have an entry in the Application event log.
//
VOID SvcReportEvent(LPTSTR szFunction)
{
HANDLE hEventSource;
LPCWSTR lpszStrings[2];
WCHAR Buffer[80];
hEventSource = RegisterEventSourceW(NULL, SVCNAME);
if( NULL != hEventSource )
{
StringCchPrintfW(Buffer, 80, L"%s failed with %d", szFunction, GetLastError());
lpszStrings[0] = SVCNAME;
lpszStrings[1] = Buffer;
ReportEventW(hEventSource, // event log handle
EVENTLOG_ERROR_TYPE, // event type
0, // event category
EVENTLOG_ERROR_TYPE, // event identifier
NULL, // no security identifier
2, // size of lpszStrings array
0, // no binary data
lpszStrings, // array of strings
NULL); // no binary data
DeregisterEventSource(hEventSource);
}
}
示例4: HRESULT_exception
_Use_decl_annotations_
DX9_exception::DX9_exception(HRESULT hr, const char* file_name, int line) noexcept : HRESULT_exception(hr, file_name, line)
{
try
{
WCHAR wide_error_string[1024];
PCWSTR dx_message = DXGetErrorStringW(m_hr);
if(CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, dx_message, -1, TEXT("Unknown"), -1) == CSTR_EQUAL)
{
assert(!"DX error string could not be found. Was check_hr intended?");
dx_message = L"Unknown error.";
}
StringCchPrintfW(wide_error_string, ARRAYSIZE(wide_error_string), L"Error: %08x: %s", m_hr, dx_message);
const auto error_string = PortableRuntime::utf8_from_utf16(wide_error_string);
PortableRuntime::dprintf("!%s(%d): %s\n", file_name, line, error_string.c_str());
// Just save off the message now, but do the full formatting in what(), to allow exception unwind to free up some resources.
m_what = std::make_shared<std::string>(std::move(error_string));
}
catch(const std::bad_alloc& ex)
{
(void)ex; // Unreferenced parameter.
PortableRuntime::dprintf("!Failed creation of exception object.\n");
}
}
示例5: UpdateReadmePage
static
void UpdateReadmePage(HWND hDlg)
{
HWND TextBox = GetDlgItem(hDlg, IDC_README_TEXT);
if( SendDlgItemMessage(hDlg, IDC_COMMANDLINE, BM_GETCHECK, 0, 0) == BST_CHECKED)
{
size_t Length = wcslen(g_CommandlineUsage) + 1;
for (size_t n = 0; n < g_FlagCount; ++n)
{
Length += wcslen(g_Flags[n].szAbbr);
Length += wcslen(g_Flags[n].szDesc);
Length += (7 + 3 + 2); /* whitespace + ' - ' + newline */
}
WCHAR* Commandline = (WCHAR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Length * sizeof(WCHAR));
StringCchCopy(Commandline, Length, g_CommandlineUsage);
WCHAR Buffer[260];
for (size_t n = 0; n < g_FlagCount; ++n)
{
StringCchPrintfW(Buffer, 260, L" %s - %s\r\n", g_Flags[n].szAbbr, g_Flags[n].szDesc);
StringCchCat(Commandline, Length, Buffer);
}
SetWindowText(TextBox, Commandline);
HeapFree(GetProcessHeap(), 0, Commandline);
}
else if( SendDlgItemMessage(hDlg, IDC_LICENSE, BM_GETCHECK, 0, 0) == BST_CHECKED)
{
SetWindowText(TextBox, g_License);
}
else
{
SetWindowText(TextBox, L"Well hello there, you hacker :)");
}
}
示例6: ModuleFromAddress
void CAPIHook::FixupNewlyLoadedModule(HMODULE hmod, DWORD dwFlags) {
// If a new module is loaded, hook the hooked functions
if ((hmod != NULL) && // Do not hook our own module
(hmod != ModuleFromAddress(FixupNewlyLoadedModule)) &&
((dwFlags & LOAD_LIBRARY_AS_DATAFILE) == 0) &&
((dwFlags & LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE) == 0) &&
((dwFlags & LOAD_LIBRARY_AS_IMAGE_RESOURCE) == 0)
) {
for (CAPIHook* p = sm_pHead; p != NULL; p = p->m_pNext) {
if (p->m_pfnOrig != NULL) {
ReplaceIATEntryInAllMods(p->m_pszCalleeModName,
p->m_pfnOrig, p->m_pfnHook);
} else {
#ifdef _DEBUG
// We should never end up here
wchar_t szPathname[MAX_PATH];
GetModuleFileNameW(NULL, szPathname, _countof(szPathname));
wchar_t sz[1024];
StringCchPrintfW(sz, _countof(sz),
TEXT("[%4u - %s] impossible to find %S\r\n"),
GetCurrentProcessId(), szPathname, p->m_pszCalleeModName);
OutputDebugString(sz);
#endif
}
}
}
}
示例7: StringCchPrintfW
//
// FUNCTION: CServiceBase::WriteErrorLogEntry(PWSTR, DWORD)
//
// PURPOSE: Log an error message to the Application event log.
//
// PARAMETERS:
// * pszFunction - the function that gives the error
// * dwError - the error code
//
void CServiceBase::WriteErrorLogEntry(const PWSTR pszFunction, DWORD dwError)
{
wchar_t szMessage[260];
StringCchPrintfW(szMessage, ARRAYSIZE(szMessage),
L"%s failed w/err 0x%08lx", pszFunction, dwError);
WriteEventLogEntry(szMessage, EVENTLOG_ERROR_TYPE);
}
示例8: addGraphToRot
HRESULT addGraphToRot(IUnknown *pUnkGraph, DWORD *pdwRegister)
{
IMoniker * pMoniker;
IRunningObjectTable *pROT;
WCHAR wsz[128];
HRESULT hr;
if (!pUnkGraph || !pdwRegister)
return E_POINTER;
if (FAILED(GetRunningObjectTable(0, &pROT)))
return E_FAIL;
hr = StringCchPrintfW(wsz, NUMELMS(wsz), L"FilterGraph %08x pid %08x\0", (DWORD_PTR)pUnkGraph,
GetCurrentProcessId());
hr = CreateItemMoniker(L"!", wsz, &pMoniker);
if (SUCCEEDED(hr))
{
// Use the ROTFLAGS_REGISTRATIONKEEPSALIVE to ensure a strong reference
// to the object. Using this flag will cause the object to remain
// registered until it is explicitly revoked with the Revoke() method.
//
// Not using this flag means that if GraphEdit remotely connects
// to this graph and then GraphEdit exits, this object registration
// will be deleted, causing future attempts by GraphEdit to fail until
// this application is restarted or until the graph is registered again.
hr = pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, pUnkGraph,
pMoniker, pdwRegister);
pMoniker->Release();
}
pROT->Release();
return hr;
}
示例9: AddGraphToRunningObjectTable
HRESULT
AddGraphToRunningObjectTable(IUnknown *aUnkGraph, DWORD *aOutRotRegister)
{
HRESULT hr;
nsRefPtr<IMoniker> moniker;
nsRefPtr<IRunningObjectTable> runningObjectTable;
hr = GetRunningObjectTable(0, getter_AddRefs(runningObjectTable));
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
const size_t STRING_LENGTH = 256;
WCHAR wsz[STRING_LENGTH];
StringCchPrintfW(wsz,
STRING_LENGTH,
L"FilterGraph %08x pid %08x",
(DWORD_PTR)aUnkGraph,
GetCurrentProcessId());
hr = CreateItemMoniker(L"!", wsz, getter_AddRefs(moniker));
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
hr = runningObjectTable->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE,
aUnkGraph,
moniker,
aOutRotRegister);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
return S_OK;
}
示例10: DllUnregisterServer
STDAPI DllUnregisterServer()
{
LPOLESTR psz;
WCHAR szCLSID[MAX_PATH];
HRESULT hr = StringFromCLSID(CLSID_OVDeskBand, &psz);
if (SUCCEEDED(hr))
{
hr = StringCchCopyW(szCLSID, ARRAYSIZE(szCLSID), psz);
CoTaskMemFree(psz);
}
if (SUCCEEDED(hr))
{
WCHAR szSubkey[MAX_PATH];
hr = StringCchPrintfW(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s", szCLSID);
if (SUCCEEDED(hr))
{
if (ERROR_SUCCESS != RegDeleteTreeW(HKEY_CLASSES_ROOT, szSubkey))
{
hr = E_FAIL;
}
}
}
return SUCCEEDED(hr) ? S_OK : SELFREG_E_CLASS;
}
示例11: ReadImageGlobalFlagsFromRegistry
BOOL ReadImageGlobalFlagsFromRegistry( _In_z_ PCWSTR ImageName, _Out_ ULONG* Flag )
{
HKEY hKey;
WCHAR FullKey[260];
if(!ImageName || !ImageName[0])
{
*Flag = 0;
return TRUE;
}
StringCchPrintfW(FullKey, 260, IMAGE_FILE_OPTIONS, ImageName);
if(EnableDebug())
{
LONG lRet = RegOpenKeyExW( HKEY_LOCAL_MACHINE, FullKey, 0, KEY_READ, &hKey );
if( ERROR_SUCCESS == lRet )
{
AutoCloseReg raii(hKey);
DWORD Type = 0, cbData = sizeof(*Flag);
if( ERROR_SUCCESS == RegQueryValueExW( hKey, GLOBALFLAG_VALUENAME, NULL, &Type, (LPBYTE)Flag, &cbData ) && Type == REG_DWORD )
{
return TRUE;
}
}
else if(ERROR_FILE_NOT_FOUND == lRet)
{
*Flag = 0;
return TRUE;
}
}
return FALSE;
}
示例12: TRACE
HRESULT WINAPI CRecycleBin::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, LPSHELLDETAILS pDetails)
{
PIDLRecycleStruct * pFileDetails;
WCHAR buffer[MAX_PATH];
WCHAR szTypeName[100];
LPWSTR pszBackslash;
UINT Length;
TRACE("(%p, %p, %d, %p)\n", this, pidl, iColumn, pDetails);
if (iColumn >= COLUMNS_COUNT)
return E_FAIL;
pDetails->fmt = RecycleBinColumns[iColumn].fmt;
pDetails->cxChar = RecycleBinColumns[iColumn].cxChars;
if (pidl == NULL)
return SHSetStrRet(&pDetails->str, RecycleBinColumns[iColumn].column_name_id);
if (iColumn == COLUMN_NAME)
return GetDisplayNameOf(pidl, SHGDN_NORMAL, &pDetails->str);
pFileDetails = _ILGetRecycleStruct(pidl);
switch (iColumn)
{
case COLUMN_DATEDEL:
FormatDateTime(buffer, MAX_PATH, &pFileDetails->DeletionTime);
break;
case COLUMN_DELFROM:
pszBackslash = wcsrchr(pFileDetails->szName, L'\\');
Length = (pszBackslash - pFileDetails->szName);
memcpy((LPVOID)buffer, pFileDetails->szName, Length * sizeof(WCHAR));
buffer[Length] = L'\0';
break;
case COLUMN_SIZE:
StrFormatKBSizeW(pFileDetails->FileSize.QuadPart, buffer, MAX_PATH);
break;
case COLUMN_MTIME:
FormatDateTime(buffer, MAX_PATH, &pFileDetails->LastModification);
break;
case COLUMN_TYPE:
// FIXME: We should in fact use a UNICODE version of _ILGetFileType
szTypeName[0] = L'\0';
wcscpy(buffer, PathFindExtensionW(pFileDetails->szName));
if (!( HCR_MapTypeToValueW(buffer, buffer, _countof(buffer), TRUE) &&
HCR_MapTypeToValueW(buffer, szTypeName, _countof(szTypeName), FALSE )))
{
/* load localized file string */
szTypeName[0] = '\0';
if(LoadStringW(shell32_hInstance, IDS_ANY_FILE, szTypeName, _countof(szTypeName)))
{
szTypeName[63] = '\0';
StringCchPrintfW(buffer, _countof(buffer), szTypeName, PathFindExtensionW(pFileDetails->szName));
}
}
return SHSetStrRet(&pDetails->str, szTypeName);
default:
return E_FAIL;
}
return SHSetStrRet(&pDetails->str, buffer);
}
示例13: ShowError
void ShowError(HWND hwnd, PCWSTR szMessage, HRESULT hr)
{
wchar_t msg[256];
if (SUCCEEDED(StringCchPrintfW(msg, ARRAYSIZE(msg), L"%s (hr = 0x%X)", szMessage, hr)))
{
MessageBox(hwnd, msg, NULL, MB_OK | MB_ICONERROR);
}
}
示例14: DestroyMenu
HRESULT CBandSiteMenu::_CreateMenuPart()
{
WCHAR wszBandName[MAX_PATH];
WCHAR wszBandGUID[MAX_PATH];
WCHAR wRegKey[MAX_PATH];
UINT cBands;
DWORD dwDataSize;
CATID category = CATID_DeskBand;
HMENU hmenuToolbars;
DWORD dwRead;
CComPtr<IEnumGUID> pEnumGUID;
HRESULT hr;
if (m_hmenu)
DestroyMenu(m_hmenu);
/* Load the template we will fill in */
m_hmenu = LoadMenuW(GetModuleHandleW(L"browseui.dll"), MAKEINTRESOURCEW(IDM_TASKBAR_TOOLBARS));
if (!m_hmenu)
return HRESULT_FROM_WIN32(GetLastError());
/* Get the handle of the submenu where the available items will be shown */
hmenuToolbars = GetSubMenu(m_hmenu, 0);
/* Create the category enumerator */
hr = SHEnumClassesOfCategories(1, &category, 0, NULL, &pEnumGUID);
if (FAILED_UNEXPECTEDLY(hr))
return hr;
m_ComCatGuids.RemoveAll();
/* Enumerate the classes in the CATID_DeskBand category */
cBands = 0;
do
{
GUID iter;
pEnumGUID->Next(1, &iter, &dwRead);
if (!dwRead)
continue;
if (!StringFromGUID2(iter, wszBandGUID, MAX_PATH))
continue;
/* Get the band name */
StringCchPrintfW(wRegKey, MAX_PATH, L"CLSID\\%s", wszBandGUID);
dwDataSize = MAX_PATH;
SHGetValue(HKEY_CLASSES_ROOT, wRegKey, NULL, NULL, wszBandName, &dwDataSize);
/* Insert it */
InsertMenu(hmenuToolbars, cBands, MF_BYPOSITION, m_ComCatGuids.GetSize() + FIRST_COMCAT_MENU_ID, wszBandName);
m_ComCatGuids.Add(iter);
cBands++;
}
while (dwRead > 0);
return S_OK;
}
示例15: DumpServiceClassInfo
void DumpServiceClassInfo(LPWSASERVICECLASSINFO lpSci)
{
WCHAR szGuid[MAX_PATH] = {'\0'};
GUID TempGuid = {0};
DWORD i = 0;
HRESULT hRet;
if (NULL == lpSci)
return;
CopyMemory(&TempGuid,lpSci->lpServiceClassId,sizeof(GUID));
if (FAILED(hRet = StringCchPrintfW(szGuid,
sizeof(szGuid)/sizeof(szGuid[0]),
L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
TempGuid.Data1,
TempGuid.Data2,
TempGuid.Data3,
TempGuid.Data4[0],
TempGuid.Data4[1],
TempGuid.Data4[2],
TempGuid.Data4[3],
TempGuid.Data4[4],
TempGuid.Data4[5],
TempGuid.Data4[6],
TempGuid.Data4[7]
)))
{
printf("StringCchPrintfW failed: 0x%x\n",hRet);
return;
}
printf("\nWSASERVICECLASSINFO %p:\n",lpSci);
wprintf(L"lpServiceClassId:\t%s\n",szGuid);
printf("lpszServiceClassName:\t%s\n",lpSci->lpszServiceClassName);
printf("dwCount:\t\t%d\n",lpSci->dwCount);
for (i = 0; i < lpSci->dwCount; i++)
{
printf("lpClassInfos (WSANSCLASSINFOW %p):\n",&lpSci->lpClassInfos[i]);
printf("\t\tdwNameSpace:\t%d\n",lpSci->lpClassInfos[i].dwNameSpace);
printf("\t\tdwValueSize:\t%d\n",lpSci->lpClassInfos[i].dwValueSize);
printf("\t\tdwValueType:\t%d\n",lpSci->lpClassInfos[i].dwValueType);
printf("\t\tlpszName:\t%s\n",lpSci->lpClassInfos[i].lpszName);
printf("\t\tlpValue:\t%p\n",lpSci->lpClassInfos[i].lpValue);
}
printf("\n");
return;
}