BOOL ConvertOEMDevmode(PCOEMDEV pOEMDevIn, POEMDEV pOEMDevOut) { HRESULT hCopy = S_OK; if( (NULL == pOEMDevIn) || (NULL == pOEMDevOut) ) { ERR(DLLTEXT("ConvertOEMDevmode() invalid parameters.\r\n")); return FALSE; } // Check OEM Signature, if it doesn't match ours, // then just assume DMIn is bad and use defaults. if(pOEMDevIn->dmOEMExtra.dwSignature == pOEMDevOut->dmOEMExtra.dwSignature) { VERBOSE(DLLTEXT("Converting private OEM Devmode.\r\n")); // Set the devmode defaults so that anything the isn't copied over will // be set to the default value. pOEMDevOut->bEnabled = WATER_MARK_DEFAULT_ENABLED; pOEMDevOut->dfRotate = WATER_MARK_DEFAULT_ROTATION; pOEMDevOut->dwFontSize = WATER_MARK_DEFAULT_FONTSIZE; pOEMDevOut->crTextColor = WATER_MARK_DEFAULT_COLOR; hCopy = StringCbCopyW(pOEMDevOut->szWaterMark, sizeof(pOEMDevOut->szWaterMark), WATER_MARK_DEFAULT_TEXT); // Copy the old structure in to the new using which ever size is the smaller. // Devmode maybe from newer Devmode (not likely since there is only one), or // Devmode maybe a newer Devmode, in which case it maybe larger, // but the first part of the structure should be the same. // DESIGN ASSUMPTION: the private DEVMODE structure only gets added to; // the fields that are in the DEVMODE never change only new fields get added to the end. memcpy(pOEMDevOut, pOEMDevIn, __min(pOEMDevOut->dmOEMExtra.dwSize, pOEMDevIn->dmOEMExtra.dwSize)); // Re-fill in the size and version fields to indicated // that the DEVMODE is the current private DEVMODE version. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; } else { WARNING(DLLTEXT("Unknown DEVMODE signature, pOEMDMIn ignored.\r\n")); // Don't know what the input DEVMODE is, so just use defaults. pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE; pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; pOEMDevOut->bEnabled = WATER_MARK_DEFAULT_ENABLED; pOEMDevOut->dfRotate = WATER_MARK_DEFAULT_ROTATION; pOEMDevOut->dwFontSize = WATER_MARK_DEFAULT_FONTSIZE; pOEMDevOut->crTextColor = WATER_MARK_DEFAULT_COLOR; hCopy = StringCbCopyW(pOEMDevOut->szWaterMark, sizeof(pOEMDevOut->szWaterMark), WATER_MARK_DEFAULT_TEXT); } return SUCCEEDED(hCopy); }
BOOL ProcessArguments(int iArgCnt, WCHAR ** argv) { if(iArgCnt < 2) return FALSE; wPath[0] = 0; wFullUserName[0] = 0; memset(wServerName, NULL, sizeof(wServerName)); memset(wNameSpace, NULL, sizeof(wNameSpace)); for(int iCnt = 1; iCnt <= iArgCnt-1 ; iCnt++) { WCHAR * pArg = argv[iCnt]; if(pArg[0] != '-') return FALSE; switch (pArg[1]) { case L's': case L'S': StringCbCopyW(wServerName, sizeof(wServerName), pArg+3); break; case L'n': case L'N': StringCbCopyW(wNameSpace, sizeof(wNameSpace), pArg+3); break; default: return FALSE; } } return TRUE; }
BOOL FormatFs (int driveNo, int clusterSize, int fsType) { wchar_t dllPath[MAX_PATH] = {0}; WCHAR dir[8] = { (WCHAR) driveNo + L'A', 0 }; PFORMATEX FormatEx; HMODULE hModule; int i; WCHAR szFsFormat[16]; WCHAR szLabel[2] = {0}; switch (fsType) { case FILESYS_NTFS: StringCbCopyW (szFsFormat, sizeof (szFsFormat),L"NTFS"); break; case FILESYS_EXFAT: StringCbCopyW (szFsFormat, sizeof (szFsFormat),L"EXFAT"); break; default: return FALSE; } if (GetSystemDirectory (dllPath, MAX_PATH)) { StringCbCatW(dllPath, sizeof(dllPath), L"\\fmifs.dll"); } else StringCbCopyW(dllPath, sizeof(dllPath), L"C:\\Windows\\System32\\fmifs.dll"); hModule = LoadLibrary (dllPath); if (hModule == NULL) return FALSE; if (!(FormatEx = (PFORMATEX) GetProcAddress (GetModuleHandle (L"fmifs.dll"), "FormatEx"))) { FreeLibrary (hModule); return FALSE; } StringCbCatW (dir, sizeof(dir), L":\\"); FormatExError = TRUE; // Windows sometimes fails to format a volume (hosted on a removable medium) as NTFS. // It often helps to retry several times. for (i = 0; i < 50 && FormatExError; i++) { FormatExError = FALSE; FormatEx (dir, FMIFS_HARDDISK, szFsFormat, szLabel, TRUE, clusterSize * FormatSectorSize, FormatExCallback); } // The device may be referenced for some time after FormatEx() returns Sleep (4000); FreeLibrary (hModule); return FormatExError? FALSE : TRUE; }
wchar_t* BLBS_GetIniFullPath(wchar_t* iniFullPath, const size_t bufSize) { GetModuleFileNameW(NULL, iniFullPath, bufSize); wchar_t* dirPath = StrRChrW(iniFullPath, NULL, L'\\')+1; StringCbCopyW(dirPath, bufSize, BL_SettingFile); return iniFullPath; }
/* create full directory tree. returns 0 for success, -1 if failure */ int mkfulldir (wchar_t *oriPath, BOOL bCheckonly) { struct _stat st; wchar_t *uniq_file; wchar_t path [TC_MAX_PATH]; StringCbCopyW (path, TC_MAX_PATH, oriPath); if (wcslen (path) == 3 && path[1] == L':') goto is_root; /* keep final slash in root if present */ /* strip final forward or backslash if we have one! */ uniq_file = wcsrchr (path, L'\\'); if (uniq_file && uniq_file[1] == L'\0') uniq_file[0] = L'\0'; else { uniq_file = wcsrchr (path, L'/'); if (uniq_file && uniq_file[1] == L'\0') uniq_file[0] = L'\0'; } is_root: if (bCheckonly) return _wstat (path, &st); if (_wstat (path, &st)) return mkfulldir_internal (path); else return 0; }
// Allocates and copies source string. PWSTR MakeStringCopy(HANDLE hHeap, PCWSTR pszSource) { PWSTR pszCopy = NULL; DWORD dwSize; // Validate parameters if( (NULL == hHeap) || (NULL == pszSource) ) { return NULL; } // Allocate memory for string duplication, and duplicate the string. dwSize = (DWORD)(wcslen(pszSource) + 1) * sizeof(WCHAR); pszCopy = (PWSTR) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, dwSize); if(NULL != pszCopy) { HRESULT hResult; hResult = StringCbCopyW(pszCopy, dwSize, pszSource); if(FAILED(hResult)) { HeapFree(hHeap, 0, pszCopy); pszCopy = NULL; SetLastError(hResult); } } return pszCopy; }
//***************************************************************************** // Function: WbemErrorString // Purpose: Turns sc into a text string // Note: The BSTR returned by this method needs to be freed by the caller. // If allocation fails, the method will return NULL //***************************************************************************** BSTR WbemErrorString(SCODE sc) { IWbemStatusCodeTextPtr pStatus; BSTR bstr = NULL; SCODE mysc = CoCreateInstance(CLSID_WbemStatusCodeText, 0, CLSCTX_INPROC_SERVER, IID_IWbemStatusCodeText, (LPVOID *) &pStatus); if (mysc == S_OK) { mysc = pStatus->GetErrorCodeText(sc, 0, 0, &bstr); if (mysc == S_OK) { } else { WCHAR szBuffer2[MAXITOA]; WCHAR szBuffer[sizeof(szBuffer2) + 4]; _ltow_s(sc, szBuffer2, 16); StringCbCopyW(szBuffer, sizeof(szBuffer), L"0x"); StringCbCatW(szBuffer, sizeof(szBuffer), szBuffer2); bstr = SysAllocString(szBuffer); } } return bstr; }
wchar_t *osi_LogSaveStringW(osi_log_t *logp, wchar_t *s) { wchar_t *saveplace; if (!logp) return s; if (!logp->enabled) return s; if (s == NULL) return NULL; thrd_EnterCrit(&logp->cs); saveplace = (wchar_t *) (logp->stringsp[logp->stringindex]); if (wcslen(s)*sizeof(wchar_t) >= OSI_LOG_STRINGSIZE) StringCbPrintfW(saveplace, OSI_LOG_STRINGSIZE, L"...%s", (s + wcslen(s) - (OSI_LOG_STRINGSIZE/sizeof(wchar_t) - 4))); else StringCbCopyW(saveplace, OSI_LOG_STRINGSIZE, s); logp->stringindex++; if (logp->stringindex >= logp->maxstringindex) logp->stringindex = 0; thrd_LeaveCrit(&logp->cs); return saveplace; }
//////////////////////////////////////////////////////////////////////////////// // // OptItems call back for OEM device or document property UI. // LONG APIENTRY OEMUICallBack(PCPSUICBPARAM pCallbackParam, POEMCUIPPARAM pOEMUIParam) { LONG lReturn = CPSUICB_ACTION_NONE; POEMDEV pOEMDev = (POEMDEV) pOEMUIParam->pOEMDM; VERBOSE(DLLTEXT("OEMUICallBack() entry.\r\n")); switch(pCallbackParam->Reason) { case CPSUICB_REASON_APPLYNOW: // Store OptItems state in DEVMODE. pOEMDev->bEnabled = !pOEMUIParam->pOEMOptItems[0].Sel; if(FAILED(StringCbCopyW(pOEMDev->szWaterMark, sizeof(pOEMDev->szWaterMark), (LPWSTR)pOEMUIParam->pOEMOptItems[1].pSel))) { ERR(DLLTEXT("OEMUICallBack() failed to copy water mark text\r\n")); } pOEMDev->dwFontSize = FontIndexToSize(pOEMUIParam->pOEMOptItems[2].Sel); pOEMDev->dfRotate = (DOUBLE) pOEMUIParam->pOEMOptItems[3].Sel; pOEMDev->crTextColor = IndexToTextColor(pOEMUIParam->pOEMOptItems[4].Sel); break; default: break; } return lReturn; }
BOOL FakeVersion(LPOSVERSIONINFOEXA pResult, VersionLieInfo* pFake) { if (pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOW)) { pResult->dwMajorVersion = pFake->dwMajorVersion; pResult->dwMinorVersion = pFake->dwMinorVersion; pResult->dwBuildNumber = pFake->dwBuildNumber; pResult->dwPlatformId = pFake->dwPlatformId; if (pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA)) { if (FAILED(StringCbCopyA(pResult->szCSDVersion, sizeof(pResult->szCSDVersion), pFake->szCSDVersionA))) return FALSE; if (pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) && pFake->dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) { pResult->wServicePackMajor = pFake->wServicePackMajor; pResult->wServicePackMinor = pFake->wServicePackMinor; } } else { LPOSVERSIONINFOEXW pResultW = (LPOSVERSIONINFOEXW)pResult; if (FAILED(StringCbCopyW(pResultW->szCSDVersion, sizeof(pResultW->szCSDVersion), pFake->szCSDVersionW))) return FALSE; if (pResultW->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW) && pFake->dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) { pResultW->wServicePackMajor = pFake->wServicePackMajor; pResultW->wServicePackMinor = pFake->wServicePackMinor; } } return TRUE; } return FALSE; }
static PWSTR pCDevSettings_AllocAndCopyString(const TCHAR *pszSrc) { INT c; PWSTR str; c = _tcslen(pszSrc) + 1; str = (PWSTR)LocalAlloc(LMEM_FIXED, c * sizeof(WCHAR)); if (str != NULL) { #ifdef UNICODE StringCbCopyW(str, c * sizeof(WCHAR), pszSrc); #else MultiByteToWideChar(CP_ACP, 0, pszSrc, -1, str, c); #endif } return str; }
HRESULT CDocUIHandler::GetOptionKeyPath( /* [out] */ BSTR *pchKey, /* [in] */ DWORD dw) { return E_NOTIMPL; HRESULT hr; WCHAR* szKey = L"ljwnb"; // cbLength is the length of szKey in bytes. size_t cbLength; hr = StringCbLengthW(szKey, 1280, &cbLength); // TODO: Add error handling code here. if (pchKey) { *pchKey = (LPOLESTR)CoTaskMemAlloc(cbLength + sizeof(WCHAR)); if (*pchKey) hr = StringCbCopyW(*pchKey, cbLength + sizeof(WCHAR), szKey); } else hr = E_INVALIDARG; return hr; }
HRESULT CALLBACK GetOrderStatusImpl( __in const WS_OPERATION_CONTEXT* context, __inout unsigned int* orderID, __out_opt __deref __nullterminated WCHAR** status, __in_opt const WS_ASYNC_CONTEXT* asyncContext, __in_opt WS_ERROR* error) { UNREFERENCED_PARAMETER(asyncContext); WS_HEAP* heap = NULL; HRESULT hr = S_OK; *orderID = *orderID; hr = WsGetOperationContextProperty(context, WS_OPERATION_CONTEXT_PROPERTY_HEAP, &heap, sizeof(heap), error); if (FAILED(hr)) { return hr; } hr = WsAlloc(heap, sizeof(OrderStatusString), (void**)status, error); if (FAILED(hr)) { return hr; } hr = StringCbCopyW(*status, sizeof(OrderStatusString), OrderStatusString); if (FAILED(hr)) { return hr; } return S_OK; }
int CWnd::ShowErrorMessage(UINT nIDMsgStr,UINT nIDTitleStr,UINT uType) const { if (IsUnicodeSystem()) { WCHAR title[100]; WCHAR msg[1000]; LoadStringW(GetLanguageSpecificResourceHandle(),nIDMsgStr,msg,1000); if (nIDTitleStr) LoadStringW(GetLanguageSpecificResourceHandle(),nIDTitleStr,title,100); else StringCbCopyW(title,100*2,szwError); return ::MessageBoxW(m_hWnd,msg,title,uType); } else { char title[100]; char msg[1000]; LoadString(nIDMsgStr,msg,1000); if (nIDTitleStr) LoadString(nIDTitleStr,title,100); else StringCbCopy(title,100,szError); return ::MessageBox(m_hWnd,msg,title,uType); } }
DXContext::DXContext(LPDIRECT3DDEVICE9 device, wchar_t* szIniFile) { m_szWindowCaption[0] = 0; m_hwnd = NULL; // m_lpD3D = NULL; m_lpDevice = device; m_hmod_d3d9 = NULL; m_hmod_d3dx9 = NULL; m_zFormat = D3DFMT_UNKNOWN; for (int i=0; i<MAX_DXC_ADAPTERS; i++) m_orig_windowed_mode_format[i] = D3DFMT_UNKNOWN; m_ordinal_adapter = D3DADAPTER_DEFAULT; m_winamp_minimized = 0; m_truly_exiting = 0; m_bpp = 0; m_frame_delay = 0; StringCbCopyW(m_szIniFile, sizeof(m_szIniFile), szIniFile); m_szDriver[0] = 0; m_szDesc[0] = 0; // clear the error register m_lastErr = S_OK; // clear the active flag m_ready=FALSE; }
DWORD GetDisplayNameID(IN LPCWSTR lpLogName) { HKEY hKey; WCHAR *KeyPath; DWORD dwMessageID = 0; DWORD cbData; SIZE_T cbKeyPath; cbKeyPath = (wcslen(EVENTLOG_BASE_KEY) + wcslen(lpLogName) + 1) * sizeof(WCHAR); KeyPath = HeapAlloc(GetProcessHeap(), 0, cbKeyPath); if (!KeyPath) { return 0; } StringCbCopyW(KeyPath, cbKeyPath, EVENTLOG_BASE_KEY); StringCbCatW(KeyPath, cbKeyPath, lpLogName); if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, KeyPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS) { HeapFree(GetProcessHeap(), 0, KeyPath); return 0; } cbData = sizeof(dwMessageID); RegQueryValueExW(hKey, L"DisplayNameID", NULL, NULL, (LPBYTE)&dwMessageID, &cbData); RegCloseKey(hKey); HeapFree(GetProcessHeap(), 0, KeyPath); return dwMessageID; }
VOID GetDisplayNameFile(IN LPCWSTR lpLogName, OUT PWCHAR lpModuleName) { HKEY hKey; WCHAR *KeyPath; WCHAR szModuleName[MAX_PATH]; DWORD cbData; SIZE_T cbKeyPath; cbKeyPath = (wcslen(EVENTLOG_BASE_KEY) + wcslen(lpLogName) + 1) * sizeof(WCHAR); KeyPath = HeapAlloc(GetProcessHeap(), 0, cbKeyPath); if (!KeyPath) { return; } StringCbCopyW(KeyPath, cbKeyPath, EVENTLOG_BASE_KEY); StringCbCatW(KeyPath, cbKeyPath, lpLogName); if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, KeyPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS) { HeapFree(GetProcessHeap(), 0, KeyPath); return; } cbData = sizeof(szModuleName); if (RegQueryValueExW(hKey, L"DisplayNameFile", NULL, NULL, (LPBYTE)szModuleName, &cbData) == ERROR_SUCCESS) { ExpandEnvironmentStringsW(szModuleName, lpModuleName, MAX_PATH); } RegCloseKey(hKey); HeapFree(GetProcessHeap(), 0, KeyPath); }
//------------------------------------------------------------------------- // Description: // // Implementation of IAudioSystemEffectsCustomFormats::GetFormatRepresentation // // Parameters: // // nFormat - [in] which format is being requested // ppwstrFormatRep - [in] address of a variable that will receive a ptr // to a new string description of the requested format // // Return values: // // S_OK Success // E_INVALIDARG nFormat is out of range // E_POINTER Null pointer passed // // Remarks: // STDMETHODIMP CSwapAPOGFX::GetFormatRepresentation ( UINT nFormat, _Outptr_ LPWSTR* ppwstrFormatRep ) { HRESULT hr; size_t cbRep; LPWSTR pwstrLocal; IF_TRUE_ACTION_JUMP((nFormat >= _cCustomFormats), hr = E_INVALIDARG, Exit); IF_TRUE_ACTION_JUMP((ppwstrFormatRep == NULL), hr = E_POINTER, Exit); cbRep = (wcslen(_rgCustomFormats[nFormat].pwszRep) + 1) * sizeof(WCHAR); pwstrLocal = (LPWSTR)CoTaskMemAlloc(cbRep); IF_TRUE_ACTION_JUMP((pwstrLocal == NULL), hr = E_OUTOFMEMORY, Exit); hr = StringCbCopyW(pwstrLocal, cbRep, _rgCustomFormats[nFormat].pwszRep); if (FAILED(hr)) { CoTaskMemFree(pwstrLocal); } else { *ppwstrFormatRep = pwstrLocal; } Exit: return hr; }
HRESULT hrOEMDevMode(DWORD dwMode, POEMDMPARAM pOemDMParam) { HRESULT hResult = S_OK; POEMDEV pOEMDevIn = NULL; POEMDEV pOEMDevOut = NULL; // Verify parameters. if( (NULL == pOemDMParam) || ( (OEMDM_SIZE != dwMode) && (OEMDM_DEFAULT != dwMode) && (OEMDM_CONVERT != dwMode) && (OEMDM_MERGE != dwMode) ) ) { ERR(DLLTEXT("DevMode() ERROR_INVALID_PARAMETER.\r\n")); SetLastError(ERROR_INVALID_PARAMETER); return E_FAIL; } // Cast generic (i.e. PVOID) to OEM private devomode pointer type. pOEMDevIn = (POEMDEV) pOemDMParam->pOEMDMIn; pOEMDevOut = (POEMDEV) pOemDMParam->pOEMDMOut; switch(dwMode) { case OEMDM_SIZE: pOemDMParam->cbBufSize = sizeof(OEMDEV); break; case OEMDM_DEFAULT: pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV); pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE; pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION; pOEMDevOut->bEnabled = WATER_MARK_DEFAULT_ENABLED; pOEMDevOut->dfRotate = WATER_MARK_DEFAULT_ROTATION; pOEMDevOut->dwFontSize = WATER_MARK_DEFAULT_FONTSIZE; pOEMDevOut->crTextColor = WATER_MARK_DEFAULT_COLOR; hResult = StringCbCopyW(pOEMDevOut->szWaterMark, sizeof(pOEMDevOut->szWaterMark), WATER_MARK_DEFAULT_TEXT); break; case OEMDM_CONVERT: ConvertOEMDevmode(pOEMDevIn, pOEMDevOut); break; case OEMDM_MERGE: ConvertOEMDevmode(pOEMDevIn, pOEMDevOut); MakeOEMDevmodeValid(pOEMDevOut); break; } return hResult; }
BOOL GetEventMessageFileDLL(IN LPCWSTR lpLogName, IN LPCWSTR SourceName, IN LPCWSTR EntryName, OUT PWCHAR ExpandedName) { DWORD dwSize; BYTE szModuleName[MAX_PATH]; WCHAR szKeyName[MAX_PATH]; HKEY hAppKey = NULL; HKEY hSourceKey = NULL; BOOL bReturn = FALSE; StringCbCopyW(szKeyName, sizeof(szKeyName), L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\"); StringCbCatW(szKeyName, sizeof(szKeyName), lpLogName); if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_READ, &hAppKey) == ERROR_SUCCESS) { if (RegOpenKeyExW(hAppKey, SourceName, 0, KEY_READ, &hSourceKey) == ERROR_SUCCESS) { dwSize = MAX_PATH; if (RegQueryValueExW(hSourceKey, EntryName, NULL, NULL, (LPBYTE)szModuleName, &dwSize) == ERROR_SUCCESS) { /* Returns a string containing the requested substituted environment variable. */ ExpandEnvironmentStringsW((LPCWSTR)szModuleName, ExpandedName, MAX_PATH); /* Successful */ bReturn = TRUE; } } } else { ShowLastWin32Error(); } if (hSourceKey != NULL) RegCloseKey(hSourceKey); if (hAppKey != NULL) RegCloseKey(hAppKey); return bReturn; }
// In this sample, wsutil is used with the /string:WS_STRING command line option // to compile the schema files. When /string:WS_STRING is used, wsutil generates stubs // using WS_STRING (instead of WCHAR*) type for strings. HRESULT CALLBACK PurchaseOrderImpl( _In_ const WS_OPERATION_CONTEXT* context, _In_ int quantity, _In_ WS_STRING productName, _Out_ unsigned int* orderID, _In_ WS_STRING* expectedShipDate, _In_ const WS_ASYNC_CONTEXT* asyncContext, _In_ WS_ERROR* error) { UNREFERENCED_PARAMETER(asyncContext); WS_HEAP* heap = NULL; HRESULT hr = S_OK; wprintf(L"%ld, %.*s\n", quantity, productName.length, productName.chars); fflush(stdout); hr = WsGetOperationContextProperty( context, WS_OPERATION_CONTEXT_PROPERTY_HEAP, &heap, sizeof(heap), error); if (FAILED(hr)) { goto Exit; } hr = WsAlloc( heap, sizeof(ExpectedShipDate), (void**)&expectedShipDate->chars, error); if (FAILED(hr)) { goto Exit; } hr = StringCbCopyW( expectedShipDate->chars, sizeof(ExpectedShipDate), ExpectedShipDate); if (FAILED(hr)) { goto Exit; } *orderID = 123; expectedShipDate->length = (ULONG)wcslen(ExpectedShipDate); Exit: return hr; }
wchar_t *ReadRegistryString (wchar_t *subKey, wchar_t *name, wchar_t *defaultValue, wchar_t *str, int maxLen) { HKEY hkey = 0; wchar_t value[MAX_PATH*4]; DWORD size = sizeof (value); str[maxLen/2-1] = 0; StringCbCopyW (str, maxLen, defaultValue); ZeroMemory (value, sizeof value); if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, 0, KEY_READ, &hkey) == ERROR_SUCCESS) if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS) StringCbCopyW (str, maxLen,value); if (hkey) RegCloseKey (hkey); return str; }
void CToolTipCtrl::UpdateTipText(LPCWSTR lpszText,HWND hWnd,UINT nIDTool) { TOOLINFOW ti; WCHAR szText[256]; ti.cbSize=TTTOOLINFOW_V1_SIZE; ti.uFlags=TTF_SUBCLASS; ti.hwnd=hWnd; ti.uId=nIDTool; ti.lpszText=szText; StringCbCopyW(szText,256*2,lpszText); ::SendMessage(m_hWnd,TTM_UPDATETIPTEXTW,0,(LPARAM)&ti); }
IFACEMETHODIMP OCContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { HRESULT hr; if (!(CMF_DEFAULTONLY & uFlags)) { InsertMenu(hMenu, indexMenu, MF_STRING | MF_BYPOSITION, idCmdFirst + IDM_SHARE, L"&Share with ownCloud"); } hr = StringCbCopyW(m_pwszVerb, sizeof(m_pwszVerb), L"ownCloudShare"); return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(IDM_SHARE + 1)); }
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo) { pSettingsInfo->bSaveWndPos = TRUE; pSettingsInfo->bUpdateAtStart = FALSE; pSettingsInfo->bLogEnabled = TRUE; StringCbCopyW(pSettingsInfo->szDownloadDir, sizeof(pSettingsInfo->szDownloadDir), L"C:\\Downloads"); pSettingsInfo->bDelInstaller = FALSE; pSettingsInfo->Maximized = FALSE; pSettingsInfo->Left = CW_USEDEFAULT; pSettingsInfo->Top = CW_USEDEFAULT; pSettingsInfo->Width = 680; pSettingsInfo->Height = 450; pSettingsInfo->Proxy = 0; StringCbCopyW(pSettingsInfo->szProxyServer, sizeof(pSettingsInfo->szProxyServer), L""); StringCbCopyW(pSettingsInfo->szNoProxyFor, sizeof(pSettingsInfo->szNoProxyFor), L""); }
HRESULT CALLBACK PurchaseOrderImpl( __in const WS_OPERATION_CONTEXT* context, __in int quantity, __in_opt __nullterminated WCHAR* productName, __out unsigned int* orderID, __out_opt __deref __nullterminated WCHAR** expectedShipDate, __in_opt const WS_ASYNC_CONTEXT* asyncContext, __in_opt WS_ERROR* error) { UNREFERENCED_PARAMETER(asyncContext); WS_HEAP* heap = NULL; HRESULT hr = S_OK; wprintf(L"%ld, %s\n", quantity, productName); fflush(stdout); hr = WsGetOperationContextProperty( context, WS_OPERATION_CONTEXT_PROPERTY_HEAP, &heap, sizeof(heap), error); if (FAILED(hr)) { goto Exit; } hr = WsAlloc( heap, sizeof(ExpectedShipDate), (void**)expectedShipDate, error); if (FAILED(hr)) { goto Exit; } hr = StringCbCopyW( *expectedShipDate, sizeof(ExpectedShipDate), ExpectedShipDate); if (FAILED(hr)) { goto Exit; } *orderID = 123; Exit: return hr; }
int mkfulldir_internal (wchar_t *path) { wchar_t *token; struct _stat st; static wchar_t tokpath[_MAX_PATH]; static wchar_t trail[_MAX_PATH]; StringCbCopyW (tokpath, _MAX_PATH, path); trail[0] = L'\0'; token = wcstok (tokpath, L"\\/"); if (tokpath[0] == L'\\' && tokpath[1] == L'\\') { /* unc */ trail[0] = tokpath[0]; trail[1] = tokpath[1]; trail[2] = L'\0'; if (token) { StringCbCatW (trail, _MAX_PATH, token); StringCbCatW (trail, _MAX_PATH, L"\\"); token = wcstok (NULL, L"\\/"); if (token) { /* get share name */ StringCbCatW (trail, _MAX_PATH, token); StringCbCatW (trail, _MAX_PATH, L"\\"); } token = wcstok (NULL, L"\\/"); } } if (tokpath[1] == L':') { /* drive letter */ StringCbCatW (trail, _MAX_PATH, tokpath); StringCbCatW (trail, _MAX_PATH, L"\\"); token = wcstok (NULL, L"\\/"); } while (token != NULL) { int x; StringCbCatW (trail, _MAX_PATH, token); x = _wmkdir (trail); StringCbCatW (trail, _MAX_PATH, L"\\"); token = wcstok (NULL, L"\\/"); } return _wstat (path, &st); }
DWORD CopyWideString( IN _In_ LPWSTR pSrcWString, OUT _Out_ LPWSTR *pDestWString) { DWORD retCode = NO_ERROR; HRESULT hr = S_OK; size_t dwStringLength = 0; LPWSTR pTempString = NULL; *pDestWString = NULL; // Nothing to copy if(!pSrcWString) goto Cleanup; hr = StringCbLengthW(pSrcWString, (size_t)(STRSAFE_MAX_CCH * sizeof(wchar_t)), &dwStringLength); if (FAILED(hr)) { retCode = HRESULT_CODE(hr); goto Cleanup; } // StringCbLengthW - returns the length of string in bytes (excluding the null character). // StringCbCopyW expects the length of string in bytes (including the null character). dwStringLength += sizeof(wchar_t); retCode = AllocateMemory((DWORD)dwStringLength, (PVOID *)&pTempString); if(retCode != NO_ERROR) { goto Cleanup; } hr = StringCbCopyW((LPTSTR)pTempString, dwStringLength, pSrcWString); if (FAILED(hr)) { retCode = HRESULT_CODE(hr); goto Cleanup; } // // Set the OUT parameter // *pDestWString = pTempString; Cleanup: if((retCode != NO_ERROR) && (pTempString != NULL)) FreeMemory((PVOID *)&pTempString); pTempString = NULL; return retCode; }
BOOL GetFilePathName( PCWSTR BasePath, PCWSTR RelativePath, PWCHAR Buffer, ULONG BufferSize ) { if (FAILED(StringCbCopyW(Buffer, BufferSize, BasePath))) return FALSE; if (FAILED(StringCbCatW(Buffer, BufferSize, RelativePath))) return FALSE; return TRUE; }
VOID DownloadApplicationsDB(LPCWSTR lpUrl) { APPLICATION_INFO IntInfo; ZeroMemory(&IntInfo, sizeof(APPLICATION_INFO)); if (FAILED(StringCbCopyW(IntInfo.szUrlDownload, sizeof(IntInfo.szUrlDownload), lpUrl))) { return; } AppInfo = &IntInfo; DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG), hMainWnd, DownloadDlgProc); }