{
INTErrorCode = ERROR_SUCCESS;
SIZE_T UnicodeSize, AnsiSize;
LPWSAQUERYSETW UnicodeCopy = NULL;
LPWSAQUERYSETA AnsiCopy;
LPSTR ServiceCopy = NULL, CommentCopy = NULL;
LPSTR ContextCopy = NULL, QueryCopy = NULL;
/* Calculate the size of the Ansi version and allocate space for a copy */
UnicodeSize = WSAComputeQuerySetSizeW(UnicodeSet);
UnicodeCopy = HeapAlloc(WsSockHeap, 0, UnicodeSize);
if (!UnicodeCopy)
{
/* Fail, couldn't allocate memory */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
gotoerror;
}
/* Build the relative buffer version */
ErrorCode = WSABuildQuerySetBufferW(UnicodeSet, UnicodeSize, UnicodeCopy);
if (ErrorCode != ERROR_SUCCESS) gotoerror;
/* Re-use the Unicode version since the fields match */
AnsiCopy = (LPWSAQUERYSETA)UnicodeCopy;
/* Check if we have a service instance name */if (UnicodeCopy->lpszServiceInstanceName)
{
/* Duplicate it into unicode form */
ServiceCopy = AnsiDupFromUnicode(UnicodeCopy->lpszServiceInstanceName);
if (!ServiceCopy)
{
/* Fail */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
gotoerror;
}
/* Set the new string pointer */
AnsiCopy->lpszServiceInstanceName = ServiceCopy;
}
/* Check if we have a service instance name */if (UnicodeCopy->lpszContext)
{
/* Duplicate it into unicode form */
ContextCopy = AnsiDupFromUnicode(UnicodeCopy->lpszContext);
if (!ContextCopy)
{
/* Fail */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
gotoerror;
}
/* Set the new string pointer */
AnsiCopy->lpszContext = ContextCopy;
}
/* Check if we have a service instance name */if (UnicodeCopy->lpszComment)
{
/* Duplicate it into unicode form */
CommentCopy = AnsiDupFromUnicode(UnicodeCopy->lpszComment);
if (!CommentCopy)
{
/* Fail */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
gotoerror;
}
/* Set the new string pointer */
AnsiCopy->lpszComment = CommentCopy;
}
/* Check if we have a query name */if (UnicodeCopy->lpszQueryString)
{
/* Duplicate it into unicode form */
QueryCopy = AnsiDupFromUnicode(UnicodeCopy->lpszQueryString);
if (!QueryCopy)
{
/* Fail */
ErrorCode = WSA_NOT_ENOUGH_MEMORY;
gotoerror;
}
/* Set the new string pointer */
AnsiCopy->lpszQueryString = QueryCopy;
}
/* Now that we have the absolute unicode buffer, calculate its size */
AnsiSize = WSAComputeQuerySetSizeA(AnsiCopy);
if (AnsiSize > *SetSize)
{
/* The buffer wasn't large enough; return how much we need */
*SetSize = AnsiSize;
ErrorCode = WSAEFAULT;
gotoerror;
}
/* Build the relative unicode buffer */
ErrorCode = WSABuildQuerySetBufferA(AnsiCopy, *SetSize, AnsiSet);
error:
/* Free the Ansi copy if we had one */if (UnicodeCopy) HeapFree(WsSockHeap, 0, UnicodeCopy);
/* Free all the strings */if (ServiceCopy) HeapFree(WsSockHeap, 0, ServiceCopy);
if (CommentCopy) HeapFree(WsSockHeap, 0, CommentCopy);
if (ContextCopy) HeapFree(WsSockHeap, 0, ContextCopy);
if (QueryCopy) HeapFree(WsSockHeap, 0, QueryCopy);
/* Return error code */returnErrorCode;
}
Generated on Sat May 26 2012 05:20:14 for ReactOS by
1.7.6.1
ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.