// // This function copies the length of pwz and the pointer pwz into the UNICODE_STRING structure // This function is intended for serializing a credential in GetSerialization only. // Note that this function just makes a copy of the string pointer. It DOES NOT ALLOCATE storage! // Be very, very sure that this is what you want, because it probably isn't outside of the // exact GetSerialization call where the sample uses it. // HRESULT UnicodeStringInitWithString( PWSTR pwz, UNICODE_STRING* pus ) { HRESULT hr; if (pwz) { size_t lenString; hr = StringCchLengthW(pwz, USHORT_MAX, &(lenString)); if (SUCCEEDED(hr)) { USHORT usCharCount; hr = SizeTToUShort(lenString, &usCharCount); if (SUCCEEDED(hr)) { USHORT usSize; hr = SizeTToUShort(sizeof(WCHAR), &usSize); if (SUCCEEDED(hr)) { hr = UShortMult(usCharCount, usSize, &(pus->Length)); // Explicitly NOT including NULL terminator if (SUCCEEDED(hr)) { pus->MaximumLength = pus->Length; pus->Buffer = pwz; hr = S_OK; } else { hr = HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); } } } } } else { hr = E_INVALIDARG; } return hr; }
HRESULT CTsTeleportShellExt::AnnounceTransfer(__in_z LPTSTR szPartial, BOOL bDir) { HRESULT hr; PTELEP_PACKET_HEADER pPacket = NULL; // // Send start packet for file or dir // size_t Len = _tcslen(szPartial); USHORT DataLen; hr = SizeTToUShort(Len, &DataLen); LEAVE_IF_FAILED("SizeTToUShort (0x%Ix) failed", Len); hr = UShortAdd(DataLen, 1, &DataLen); LEAVE_IF_FAILED("UShortAdd (0x%4x, 1) failed", DataLen); hr = UShortMult(DataLen, sizeof(TCHAR), &DataLen); LEAVE_IF_FAILED("UShortMult (0x%4x, %d) failed", DataLen, sizeof(TCHAR)); hr = UShortAdd(DataLen, sizeof(TELEP_PACKET_HEADER), &DataLen); LEAVE_IF_FAILED("UShortMult (0x%4x, %d) failed", DataLen, sizeof(TELEP_PACKET_HEADER)); USHORT Flags = 0; if (bDir) { Flags |= TELET_FLAG_DIRECTORY; } pPacket = NewPacket(PacketTypeFileStart, DataLen, Flags); // throwing! LPWSTR pData = (LPWSTR) (pPacket+1); CopyMemory(pData, szPartial, pPacket->PacketSize); hr = SendPacket(pPacket); LEAVE_IF_FAILED("SendPacket (Start, %s) failed", szPartial); _Function_Exit: if (pPacket) { delete [] pPacket; } return hr; }
// // This function packs the string pszSourceString in pszDestinationString // for use with LSA functions including LsaLookupAuthenticationPackage. // HRESULT LsaInitString(PSTRING pszDestinationString, PCSTR pszSourceString) { size_t cchLength; HRESULT hr = StringCchLength(pszSourceString, USHORT_MAX, &cchLength); if (SUCCEEDED(hr)) { USHORT usLength; hr = SizeTToUShort(cchLength, &usLength); if (SUCCEEDED(hr)) { pszDestinationString->Buffer = (PCHAR)pszSourceString; pszDestinationString->Length = usLength; pszDestinationString->MaximumLength = pszDestinationString->Length+1; hr = S_OK; } } return hr; }